Last active
August 29, 2015 14:08
-
-
Save luistinygod/03913dcbd4263d9bac77 to your computer and use it in GitHub Desktop.
GravityView Make (some) Search Fields Required
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* If you need to make some of the GravityView search fields required before search is submited | |
* - add as many lines as you need to define which fields are required | |
* e.g. -> jQuery('#gv_search_XYZZ').prop('required', true ); | |
* | |
* Add this gist to your theme functions.php | |
* | |
*/ | |
add_action('gravityview_after', 'my_theme_make_search_fields_required' ); | |
function my_theme_make_search_fields_required() { | |
?> | |
<script> | |
//define here the search fields that are required | |
jQuery('#gv_search_2247').prop('required', true ); | |
// validation magic | |
jQuery('form.gv-widget-search').submit( function(e) { | |
e.stopPropagation(); | |
var isValid = true; | |
jQuery('.gv-widget-search input:required').each( function(){ | |
if( jQuery(this).val() === '' ) { | |
isValid = false; | |
} | |
}); | |
return isValid; | |
}); | |
</script> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment