/** * angular-validator * @version v0.0.0 - 2015-12-02 * @link https://github.com/marshal003/angular-validator * @author Vinit Kumar Rai * @license MIT License, http://www.opensource.org/licenses/MIT */ "use strict";var validator=angular.module("hiComponents.validator",[]);validator.service("hiValidatorService",["$templateCache",function(a){var b={},c="hiValidatorErrorTemplate",d=function(a,c,d,e,f){if(c in b&&!f)throw"A validator with same name already exists. Either provide a unique name or specify override true";b[c]={fn:a,context:d,async:e||!1}},e=function(a){return a in b?b[a]:null},f=function(){a.get(c)||a.put("hiValidatorErrorTemplate",'
')};return f(),{register:d,getValidator:e}}]),validator.directive("hiValidate",["hiValidatorService","$log",function(a,b){return{require:"ngModel",scope:{},link:function(c,d,e,f){var g=null,h=angular.forEach,i=function(){g=k(),h(g,function(c){var d=a.getValidator(c);d?j(c,d):b.error("No validator with name "+c+" has been registered")})},j=function(a,b){var c=b.fn,d=b.context,e=function(b,e){var g=c.call(d,b||e);return f.$error.messages[a]=f.$dirty?g:{},g.isValid},g=function(b,e){var g=c.call(d,b||e);return g.then(function(b){f.$error.messages[a]=f.$dirty?b:{}},function(b){f.$error.messages[a]=f.$dirty?b:{}}),g},h=b.async?"$asyncValidators":"$validators",i=b.async?g:e;f[h][a]=i,f.$error.messages={}},k=function(){return e.hiValidate.split(",").map(function(a){return a.trim()})};i()}}}]),validator.directive("hiValidatorMessage",function(){return{replace:!0,restrict:"E",require:"^form",scope:{model:"@model"},templateUrl:function(a,b){return b.tpl||"hiValidatorErrorTemplate"},link:function(a,b,c,d){a.errors=d[a.model].$error.messages}}});