diff --git a/dist/angular-validation.js b/dist/angular-validation.js index df60d6c..1589f36 100644 --- a/dist/angular-validation.js +++ b/dist/angular-validation.js @@ -355,8 +355,8 @@ var validators = validation.slice(0), validator = validators[0].trim(), leftValidation = validators.slice(1), - successMessage = validation + 'SuccessMessage', - errorMessage = validation + 'ErrorMessage', + successMessage = validator + 'SuccessMessage', + errorMessage = validator + 'ErrorMessage', expression = $validationProvider.getExpression(validator), valid = { success: function() { diff --git a/dist/angular-validation.min.js b/dist/angular-validation.min.js index 8924dbe..a95cd83 100644 --- a/dist/angular-validation.min.js +++ b/dist/angular-validation.min.js @@ -1 +1 @@ -(function(){angular.module("validation",["validation.provider","validation.directive"])}).call(this),function(){angular.module("validation.provider",[]).provider("$validation",function(){var a,b,c,d,e,f=this,g=function(f){a=f,b=a.get("$rootScope"),c=a.get("$http"),d=a.get("$q"),e=a.get("$timeout")},h={},i={};this.setExpression=function(a){return angular.extend(h,a),f},this.getExpression=function(a){return h[a]},this.setDefaultMsg=function(a){return angular.extend(i,a),f},this.getDefaultMsg=function(a){return i[a]},this.setErrorHTML=function(a){return a.constructor===Function?(f.getErrorHTML=a,f):void 0},this.getErrorHTML=function(a){return'
'+a+"
"},this.setSuccessHTML=function(a){return a.constructor===Function?(f.getSuccessHTML=a,f):void 0},this.getSuccessHTML=function(a){return''+a+"
"},this.showSuccessMessage=!0,this.showErrorMessage=!0,this.checkValid=function(a){return void 0===a.$valid?!1:a&&a.$valid===!0},this.validate=function(a){var c=d.defer(),g=0;if(void 0===a)return console.error("This is not a regular Form name scope"),c.reject("This is not a regular Form name scope"),c.promise;if(a.validationId)b.$broadcast(a.$name+"submit-"+a.validationId,g++);else if(a.constructor===Array)for(var h in a)b.$broadcast(a[h].$name+"submit-"+a[h].validationId,g++);else for(var i in a)a[i]&&a[i].hasOwnProperty("$dirty")&&b.$broadcast(i+"submit-"+a[i].validationId,g++);return c.promise.success=function(a){return c.promise.then(function(b){a(b)}),c.promise},c.promise.error=function(a){return c.promise.then(null,function(b){a(b)}),c.promise},e(function(){f.checkValid(a)?c.resolve("success"):c.reject("error")}),c.promise},this.reset=function(a){if(void 0===a)return void console.error("This is not a regular Form name scope");if(a.validationId)b.$broadcast(a.$name+"reset-"+a.validationId);else if(a.constructor===Array)for(var c in a)b.$broadcast(a[c].$name+"reset-"+a[c].validationId);else for(var d in a)a[d].hasOwnProperty("$dirty")&&b.$broadcast(d+"reset-"+a[d].validationId)},this.$get=["$injector",function(a){return g(a),{setErrorHTML:this.setErrorHTML,getErrorHTML:this.getErrorHTML,setSuccessHTML:this.setSuccessHTML,getSuccessHTML:this.getSuccessHTML,setExpression:this.setExpression,getExpression:this.getExpression,setDefaultMsg:this.setDefaultMsg,getDefaultMsg:this.getDefaultMsg,showSuccessMessage:this.showSuccessMessage,showErrorMessage:this.showErrorMessage,checkValid:this.checkValid,validate:this.validate,reset:this.reset}}]})}.call(this),function(){angular.module("validation.directive",["validation.provider"]).directive("validator",["$injector",function(a){var b=a.get("$validation"),c=a.get("$q"),d=a.get("$timeout"),e=function(a,c,d,e,f){return a.next().html(b.showSuccessMessage?b.getSuccessHTML(c||b.getDefaultMsg(d).success):""),f.$setValidity(f.$name,!0),e&&e(),!0},f=function(a,c,d,e,f){return a.next().html(b.showErrorMessage?b.getErrorHTML(c||b.getDefaultMsg(d).error):""),f.$setValidity(f.$name,!1),e&&e(),!1},g=!1,h=function(a,d,g,i,j,k){var l=j.slice(0),m=l[0].trim(),n=l.slice(1),o=j+"SuccessMessage",p=j+"ErrorMessage",q=b.getExpression(m),r={success:function(){return e(d,g[o],m,a.validCallback,i),n.length?void h(a,d,g,i,n,k):!0},error:function(){return f(d,g[p],m,a.invalidCallback,i)}};if(void 0===q){if(console.error('You are using undefined validator "%s"',m),!n.length)return;h(a,d,g,i,n,k)}return q.constructor===Function?c.all([b.getExpression(m)(k,a,d,g)]).then(function(a){return a&&a.length>0&&a[0]?r.success():r.error()},function(){return r.error()}):q.constructor===RegExp&&b.getExpression(m).test(k)?r.success():r.error()},i=function(){return(65536*(1+Math.random())|0).toString(16).substring(1)},j=function(){return i()+i()+i()+i()};return{restrict:"A",require:"ngModel",scope:{model:"=ngModel",initialValidity:"=initialValidity",validCallback:"&",invalidCallback:"&"},link:function(a,b,c,e){var f=function(){},i=c.validator.split(","),k=e.validationId=j();b.after("");var l=!1;"boolean"==typeof a.initialValidity&&(l=a.initialValidity),e.$setValidity(e.$name,l),a.$on(e.$name+"reset-"+k,function(){f(),g=!1,e.$setViewValue(""),e.$setPristine(),e.$setValidity(e.$name,!1),e.$render(),b.next().html("")}),function(){return a.$on(e.$name+"submit-"+k,function(d,j){var k=b[0].value,l=!1;0===j&&(g=!1),l=h(a,b,c,e,i,k),"submit"===c.validMethod&&(f(),f=a.$watch("model",function(d,f){d!==f&&((void 0===d||null===d)&&(d=""),l=h(a,b,c,e,i,d))})),g||l||(g=!0,b[0].focus())}),"blur"===c.validMethod?void b.bind("blur",function(){var d=b[0].value;a.$apply(function(){h(a,b,c,e,i,d)})}):void("submit"!==c.validMethod&&"submit-only"!==c.validMethod&&a.$watch("model",function(d){if(e.$pristine&&e.$viewValue)e.$setViewValue(e.$viewValue);else if(e.$pristine)return void b.next().html("");h(a,b,c,e,i,d)}))}(),d(function(){c.$observe("noValidationMessage",function(a){var c=b.next();"true"==a||a===!0?c.css("display","none"):("false"==a||a===!1)&&c.css("display","block")})})}}}]).directive("validationSubmit",["$injector",function(a){var b=a.get("$validation"),c=a.get("$timeout"),d=a.get("$parse");return{priority:1,require:"?ngClick",link:function(a,e,f){var g=d(f.validationSubmit)(a);c(function(){e.off("click"),e.on("click",function(c){c.preventDefault(),b.validate(g).success(function(){d(f.ngClick)(a)})})})}}}]).directive("validationReset",["$injector",function(a){var b=a.get("$validation"),c=a.get("$timeout"),d=a.get("$parse");return{link:function(a,e,f){var g=d(f.validationReset)(a);c(function(){e.on("click",function(a){a.preventDefault(),b.reset(g)})})}}}])}.call(this); \ No newline at end of file +(function(){angular.module("validation",["validation.provider","validation.directive"])}).call(this),function(){angular.module("validation.provider",[]).provider("$validation",function(){var a,b,c,d,e,f=this,g=function(f){a=f,b=a.get("$rootScope"),c=a.get("$http"),d=a.get("$q"),e=a.get("$timeout")},h={},i={};this.setExpression=function(a){return angular.extend(h,a),f},this.getExpression=function(a){return h[a]},this.setDefaultMsg=function(a){return angular.extend(i,a),f},this.getDefaultMsg=function(a){return i[a]},this.setErrorHTML=function(a){return a.constructor===Function?(f.getErrorHTML=a,f):void 0},this.getErrorHTML=function(a){return''+a+"
"},this.setSuccessHTML=function(a){return a.constructor===Function?(f.getSuccessHTML=a,f):void 0},this.getSuccessHTML=function(a){return''+a+"
"},this.showSuccessMessage=!0,this.showErrorMessage=!0,this.checkValid=function(a){return void 0===a.$valid?!1:a&&a.$valid===!0},this.validate=function(a){var c=d.defer(),g=0;if(void 0===a)return console.error("This is not a regular Form name scope"),c.reject("This is not a regular Form name scope"),c.promise;if(a.validationId)b.$broadcast(a.$name+"submit-"+a.validationId,g++);else if(a.constructor===Array)for(var h in a)b.$broadcast(a[h].$name+"submit-"+a[h].validationId,g++);else for(var i in a)a[i]&&a[i].hasOwnProperty("$dirty")&&b.$broadcast(i+"submit-"+a[i].validationId,g++);return c.promise.success=function(a){return c.promise.then(function(b){a(b)}),c.promise},c.promise.error=function(a){return c.promise.then(null,function(b){a(b)}),c.promise},e(function(){f.checkValid(a)?c.resolve("success"):c.reject("error")}),c.promise},this.reset=function(a){if(void 0===a)return void console.error("This is not a regular Form name scope");if(a.validationId)b.$broadcast(a.$name+"reset-"+a.validationId);else if(a.constructor===Array)for(var c in a)b.$broadcast(a[c].$name+"reset-"+a[c].validationId);else for(var d in a)a[d].hasOwnProperty("$dirty")&&b.$broadcast(d+"reset-"+a[d].validationId)},this.$get=["$injector",function(a){return g(a),{setErrorHTML:this.setErrorHTML,getErrorHTML:this.getErrorHTML,setSuccessHTML:this.setSuccessHTML,getSuccessHTML:this.getSuccessHTML,setExpression:this.setExpression,getExpression:this.getExpression,setDefaultMsg:this.setDefaultMsg,getDefaultMsg:this.getDefaultMsg,showSuccessMessage:this.showSuccessMessage,showErrorMessage:this.showErrorMessage,checkValid:this.checkValid,validate:this.validate,reset:this.reset}}]})}.call(this),function(){angular.module("validation.directive",["validation.provider"]).directive("validator",["$injector",function(a){var b=a.get("$validation"),c=a.get("$q"),d=a.get("$timeout"),e=function(a,c,d,e,f){return a.next().html(b.showSuccessMessage?b.getSuccessHTML(c||b.getDefaultMsg(d).success):""),f.$setValidity(f.$name,!0),e&&e(),!0},f=function(a,c,d,e,f){return a.next().html(b.showErrorMessage?b.getErrorHTML(c||b.getDefaultMsg(d).error):""),f.$setValidity(f.$name,!1),e&&e(),!1},g=!1,h=function(a,d,g,i,j,k){var l=j.slice(0),m=l[0].trim(),n=l.slice(1),o=m+"SuccessMessage",p=m+"ErrorMessage",q=b.getExpression(m),r={success:function(){return e(d,g[o],m,a.validCallback,i),n.length?void h(a,d,g,i,n,k):!0},error:function(){return f(d,g[p],m,a.invalidCallback,i)}};if(void 0===q){if(console.error('You are using undefined validator "%s"',m),!n.length)return;h(a,d,g,i,n,k)}return q.constructor===Function?c.all([b.getExpression(m)(k,a,d,g)]).then(function(a){return a&&a.length>0&&a[0]?r.success():r.error()},function(){return r.error()}):q.constructor===RegExp&&b.getExpression(m).test(k)?r.success():r.error()},i=function(){return(65536*(1+Math.random())|0).toString(16).substring(1)},j=function(){return i()+i()+i()+i()};return{restrict:"A",require:"ngModel",scope:{model:"=ngModel",initialValidity:"=initialValidity",validCallback:"&",invalidCallback:"&"},link:function(a,b,c,e){var f=function(){},i=c.validator.split(","),k=e.validationId=j();b.after("");var l=!1;"boolean"==typeof a.initialValidity&&(l=a.initialValidity),e.$setValidity(e.$name,l),a.$on(e.$name+"reset-"+k,function(){f(),g=!1,e.$setViewValue(""),e.$setPristine(),e.$setValidity(e.$name,!1),e.$render(),b.next().html("")}),function(){return a.$on(e.$name+"submit-"+k,function(d,j){var k=b[0].value,l=!1;0===j&&(g=!1),l=h(a,b,c,e,i,k),"submit"===c.validMethod&&(f(),f=a.$watch("model",function(d,f){d!==f&&((void 0===d||null===d)&&(d=""),l=h(a,b,c,e,i,d))})),g||l||(g=!0,b[0].focus())}),"blur"===c.validMethod?void b.bind("blur",function(){var d=b[0].value;a.$apply(function(){h(a,b,c,e,i,d)})}):void("submit"!==c.validMethod&&"submit-only"!==c.validMethod&&a.$watch("model",function(d){if(e.$pristine&&e.$viewValue)e.$setViewValue(e.$viewValue);else if(e.$pristine)return void b.next().html("");h(a,b,c,e,i,d)}))}(),d(function(){c.$observe("noValidationMessage",function(a){var c=b.next();"true"==a||a===!0?c.css("display","none"):("false"==a||a===!1)&&c.css("display","block")})})}}}]).directive("validationSubmit",["$injector",function(a){var b=a.get("$validation"),c=a.get("$timeout"),d=a.get("$parse");return{priority:1,require:"?ngClick",link:function(a,e,f){var g=d(f.validationSubmit)(a);c(function(){e.off("click"),e.on("click",function(c){c.preventDefault(),b.validate(g).success(function(){d(f.ngClick)(a)})})})}}}]).directive("validationReset",["$injector",function(a){var b=a.get("$validation"),c=a.get("$timeout"),d=a.get("$parse");return{link:function(a,e,f){var g=d(f.validationReset)(a);c(function(){e.on("click",function(a){a.preventDefault(),b.reset(g)})})}}}])}.call(this); \ No newline at end of file diff --git a/index.html b/index.html index 1f65d6d..d8df9db 100644 --- a/index.html +++ b/index.html @@ -217,4 +217,4 @@