Skip to content

Instantly share code, notes, and snippets.

@andresmoschini
Created February 23, 2016 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andresmoschini/7f7915726ff7c258c422 to your computer and use it in GitHub Desktop.
Save andresmoschini/7f7915726ff7c258c422 to your computer and use it in GitHub Desktop.
(function () {
'use strict';
angular
.module('dopplerRelay')
.directive('validationErrors', validationErrors);
validationErrors.$inject = [
"$compile"
];
function validationErrors($compile) {
var directive = {
restrict: 'A',
link: function (scope, element, attrs) {
var fieldName = attrs.name;
var content = angular.element(
'<div class="validation-error" '
+ 'ng-show="form.$submitted || (form.' + fieldName + '.$touched && form.' + fieldName + '.$dirty)">'
+ ' <span ng-repeat="(errorKey, error) in form.' + fieldName + '.$error">'
+ ' {{"validation_error_" + errorKey | translate}}'
+ ' </span>'
+ ' </div>');
element.after(content);
$compile(content)(scope);
}
};
return directive;
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment