-
-
Save corradomatt/aa919d70bf222e909332 to your computer and use it in GitHub Desktop.
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