Skip to content

Instantly share code, notes, and snippets.

@calebdwilliams
Created October 8, 2015 20:56
Show Gist options
  • Save calebdwilliams/f3658d27022070d4444f to your computer and use it in GitHub Desktop.
Save calebdwilliams/f3658d27022070d4444f to your computer and use it in GitHub Desktop.
(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