Skip to content

Instantly share code, notes, and snippets.

@pmanijak
Created August 28, 2012 07:22
Show Gist options
  • Save pmanijak/3495819 to your computer and use it in GitHub Desktop.
Save pmanijak/3495819 to your computer and use it in GitHub Desktop.
Validation on blur with AngularJS
// 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