Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hirejordansmith/0a4a9aa1bc6e4c3f3380ef2367cd7c7d to your computer and use it in GitHub Desktop.
Save hirejordansmith/0a4a9aa1bc6e4c3f3380ef2367cd7c7d to your computer and use it in GitHub Desktop.
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