Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to add cursor focus on first Gravity Forms field validation error
<?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;
}
<script type="text/javascript">
jQuery(document).bind('gform_post_render', function() {
jQuery('li.gfield.gfield_error:first input').focus();
});
</script>
<?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
You can’t perform that action at this time.