Skip to content

Instantly share code, notes, and snippets.

@guyroutledge
Created September 9, 2013 15:45
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save guyroutledge/6497479 to your computer and use it in GitHub Desktop.
Save guyroutledge/6497479 to your computer and use it in GitHub Desktop.
Inline form validation with Gravity Forms
// 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();
}
});
@imoyano
Copy link

imoyano commented Feb 9, 2016

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!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment