Created
September 9, 2013 15:45
-
-
Save guyroutledge/6497479 to your computer and use it in GitHub Desktop.
Inline form validation with Gravity Forms
This file contains 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
// if an invalid form field has been made valid, | |
// remove the shouty error highlighting - if a valid | |
// required field has been made invalid, start shouting | |
$('input, textarea, select').on('change', function(){ | |
var $input = $(this); | |
var isRequired = $input.parents('.gfield').is('.gfield_contains_required'); | |
var isValid = $input.is(':valid'); | |
if ( isRequired && isValid ) { | |
$input.parents('.gfield').removeClass('gfield_error'); | |
$input.parent().next('.validation_message').slideUp(); | |
} | |
}).blur(function(){ | |
var $input = $(this); | |
var isRequired = $input.parents('.gfield').is('.gfield_contains_required'); | |
var isInValid = $input.is(':invalid'); | |
var isEmpty = $input.val() === ''; | |
if ( isRequired && ( isInValid || isEmpty ) ) { | |
$input.parents('.gfield').addClass('gfield_error'); | |
$input.parent().next('.validation_message').slideDown(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey mate, just looking a way to do an inline validation of Gravity Forms and I have found your Javascript... could you share please how (where), I need to include this code?
I'm using gravity form with wordpress.
Thanks for your help!!