Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Gravity Wiz // Gravity Forms // Give First Validation Error Focus
<?php
/**
* Gravity Wiz // Gravity Forms // Give First Validation Error Focus
* http://gravitywiz.com/
*/
add_filter( 'gform_pre_render', 'gw_first_error_focus' );
function gw_first_error_focus( $form ) {
add_filter( 'gform_confirmation_anchor_' . $form['id'], '__return_false' );
?>
<script type="text/javascript">
if( window['jQuery'] ) {
( function( $ ) {
$( document ).bind( 'gform_post_render', function() {
var $firstError = $( 'li.gfield.gfield_error:first' );
if( $firstError.length > 0 ) {
$firstError.find( 'input, select, textarea' ).eq( 0 ).focus();
document.body.scrollTop = $firstError.offset().top;
}
} );
} )( jQuery );
}
</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.