Jquery fix for preventing wordpress empty search issue. I found a decent/easy jquery workaround on preventing submit if the field is empty:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | /** * Stop empty searches * * @author Thomas Scholz http://toscho.de * @param $ jQuery object * @return bool|object */ ( function ( $ ) { $.fn.preventEmptySubmit = function ( options ) { var settings = { inputselector: "#s" , msg : "Don’t waste your time with an empty search!" }; if ( options ) { $.extend( settings, options ); }; this .submit( function () { var s = $( this ).find( settings.inputselector ); if ( ! s.val() ) { alert( settings.msg ); s.focus(); return false ; } return true ; }); return this ; }; })( jQuery ); |
And onload:
1 | jQuery( "#searchform" ).preventEmptySubmit(); |
0 Comments.