Created
August 28, 2012 07:22
-
-
Save pmanijak/3495819 to your computer and use it in GitHub Desktop.
Validation on blur with AngularJS
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
// Make a custom "invalid" class that goes away | |
// when an element is focused. | |
var setupValidation = function(selector) { | |
$(selector).blur(function() { | |
var elm = $(this); | |
if (isInvalid(elm)) { | |
elm.addClass("invalid"); | |
} | |
}); | |
$(selector).focus(function() { | |
$(this).removeClass("invalid"); | |
}); | |
}; | |
var isInvalid = function(elm) { | |
return (elm.hasClass("ng-invalid") && !elm.hasClass("ng-pristine")); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment