{"id":860,"date":"2012-09-28T03:30:42","date_gmt":"2012-09-27T18:30:42","guid":{"rendered":"http:\/\/www.santoshkori.com\/blog\/?p=860"},"modified":"2012-09-28T03:30:42","modified_gmt":"2012-09-27T18:30:42","slug":"jquery-fix-for-wordpress-empty-search-issue","status":"publish","type":"post","link":"https:\/\/www.santoshkori.com\/blog\/jquery-fix-for-wordpress-empty-search-issue\/","title":{"rendered":"Jquery Fix for WordPress Empty Search issue"},"content":{"rendered":"<p>Jquery fix for preventing wordpress empty search issue. I found a decent\/easy jquery workaround on\u00a0preventing submit if the field is empty:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\/**\r\n * Stop empty searches\r\n *\r\n * @author Thomas Scholz http:\/\/toscho.de\r\n * @param  $ jQuery object\r\n * @return bool|object\r\n *\/\r\n(function( $ ) {\r\n   $.fn.preventEmptySubmit = function( options ) {\r\n       var settings = {\r\n           inputselector: &quot;#s&quot;,\r\n           msg          : &quot;Don\u2019t waste your time with an empty search!&quot;\r\n       };\r\n       if ( options ) {\r\n           $.extend( settings, options );\r\n       };\r\n       this.submit( function() {\r\n           var s = $( this ).find( settings.inputselector );\r\n           if ( ! s.val() ) {\r\n               alert( settings.msg );\r\n               s.focus();\r\n               return false;\r\n           }\r\n           return true;\r\n       });\r\n       return this;\r\n   };\r\n})( jQuery );\r\n\r\n<\/pre>\n<p>And onload: <\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\njQuery( &quot;#searchform&quot; ).preventEmptySubmit();\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Jquery fix for preventing wordpress empty search issue. I found a decent\/easy jquery workaround on\u00a0preventing submit if the field is empty: \/** * Stop empty searches * * @author Thomas Scholz http:\/\/toscho.de * @param $ jQuery object * @return bool|object *\/ (function( $ ) { $.fn.preventEmptySubmit = function( options ) { var settings = { [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[102,5],"tags":[730,404,725],"class_list":["post-860","post","type-post","status-publish","format-standard","hentry","category-jquery","category-wordpress","tag-jquery","tag-jquery-fix-for-empty-wordpress-search","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts\/860","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/comments?post=860"}],"version-history":[{"count":1,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts\/860\/revisions"}],"predecessor-version":[{"id":861,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts\/860\/revisions\/861"}],"wp:attachment":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/media?parent=860"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/categories?post=860"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/tags?post=860"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}