Last active
February 25, 2017 14:29
-
-
Save hirejordansmith/0a4a9aa1bc6e4c3f3380ef2367cd7c7d to your computer and use it in GitHub Desktop.
How to add cursor focus on first Gravity Forms field validation error
This file contains hidden or 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 | |
add_filter( 'gform_pre_render', 'hjs_add_script_block' ); | |
function hjs_add_script_block( $form ) { ?> | |
<script type="text/javascript"> | |
jQuery(document).bind('gform_post_render', function() { | |
jQuery('li.gfield.gfield_error:first input').focus(); | |
}); | |
</script> | |
<?php | |
return $form; | |
} |
This file contains hidden or 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
<script type="text/javascript"> | |
jQuery(document).bind('gform_post_render', function() { | |
jQuery('li.gfield.gfield_error:first input').focus(); | |
}); | |
</script> |
This file contains hidden or 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 | |
// Replace 9 with form ID | |
add_filter( 'gform_pre_render_9', 'hjs_add_script_block' ); | |
function hjs_add_script_block( $form ) { ?> | |
<script type="text/javascript"> | |
jQuery(document).bind('gform_post_render', function() { | |
jQuery('li.gfield.gfield_error:first input').focus(); | |
}); | |
</script> | |
<?php | |
return $form; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment