Created
July 23, 2018 17:00
-
-
Save m1ndspark/ee7be01c1b7c5fbc61078be41ef0ef91 to your computer and use it in GitHub Desktop.
Gravity Forms Validation Errors Mobile-friendly(er) - by Gravity Perks
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 | |
| /** | |
| * 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