Created
October 8, 2015 20:56
-
-
Save calebdwilliams/f3658d27022070d4444f 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
(function() { | |
angular.module('myApp.directives') | |
.directive('validateClass', [function() { | |
return { | |
restrict: 'A', | |
link: function validateClassLink(scope, element, attributes, ngForm) { | |
var fieldObj = ngForm[attributes.validateClass], | |
className = attributes.errorClass || 'has-error'; | |
scope.$watch(function() { | |
return (fieldObj.$invalid && fieldObj.$dirty); | |
}, function(conditionMet) { | |
element.toggleClass(className, conditionMet); | |
}); | |
}, | |
require: '^form' | |
}; | |
}]); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment