diff --git a/dist/angular-validation.js b/dist/angular-validation.js index 06aa4b3..b8ff0ac 100644 --- a/dist/angular-validation.js +++ b/dist/angular-validation.js @@ -223,10 +223,6 @@ this.reset = function (form) { for (var k in form) { if (form[k].hasOwnProperty('$dirty')) { - form[k].$setViewValue(null); - form[k].$setPristine(); - form[k].$setValidity(form[k].$name, false); - form[k].$render(); $scope.$broadcast(k + 'reset'); } } @@ -384,6 +380,10 @@ * Reset the validation for specific form */ scope.$on(ctrl.$name + 'reset', function () { + ctrl.$setViewValue(null); + ctrl.$setPristine(); + ctrl.$setValidity(ctrl.$name, false); + ctrl.$render(); element.next().html(''); }); diff --git a/dist/angular-validation.min.js b/dist/angular-validation.min.js index 0fb9f79..c6b8528 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=this,f=function(e){a=e,b=a.get("$rootScope"),c=a.get("$http"),d=a.get("$q")},g={required:/^.+$/,url:/((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/,email:/^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/,number:/^\d+$/},h={required:{error:"This should be Required!!",success:"It's Required"},url:{error:"This should be Url",success:"It's Url"},email:{error:"This should be Email",success:"It's Email"},number:{error:"This should be Number",success:"It's Number"}};this.setExpression=function(a){angular.extend(g,a)},this.getExpression=function(a){return g[a]},this.setDefaultMsg=function(a){angular.extend(h,a)},this.getDefaultMsg=function(a){return h[a]},this.setErrorHTML=function(a){a.constructor===Function&&(e.getErrorHTML=a)},this.getErrorHTML=function(a){return'
'+a+"
"},this.setSuccessHTML=function(a){a.constructor===Function&&(e.getSuccessHTML=a)},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){for(var c in a)a[c].hasOwnProperty("$dirty")&&b.$broadcast(c+"submit");var f=d.defer();return f.promise.success=function(a){return f.promise.then(function(b){a(b)}),f.promise},f.promise.error=function(a){return f.promise.then(null,function(b){a(b)}),f.promise},e.checkValid(a)?f.resolve("success"):f.reject("error"),f.promise},this.reset=function(a){for(var c in a)a[c].hasOwnProperty("$dirty")&&(a[c].$setViewValue(null),a[c].$setPristine(),a[c].$setValidity(a[c].$name,!1),a[c].$render(),b.$broadcast(c+"reset"))},this.$get=["$injector",function(a){return f(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){a.next().html(b.showSuccessMessage?b.getSuccessHTML(c||b.getDefaultMsg(d).success):""),f.$setValidity(f.$name,!0),e&&e()},f=function(a,c,d,e,f){a.next().html(b.showErrorMessage?b.getErrorHTML(c||b.getDefaultMsg(d).error):""),f.$setValidity(f.$name,!1),e&&e()},g=function(a,d,g,h,i,j){var k=i+"SuccessMessage",l=i+"ErrorMessage",m=b.getExpression(i).constructor,n={success:function(){e(d,g[k],i,a.validCallback(),h)},error:function(){f(d,g[l],i,a.invalidCallback(),h)}};return m===Function?c.all([b.getExpression(i)(j)]).then(function(a){return a&&a.length>0&&a[0]?n.success():n.error()},function(){return n.error()}):m===RegExp&&b.getExpression(i).test(j)?n.success():n.error()};return{restrict:"A",require:"ngModel",scope:{model:"=ngModel",validCallback:"&",invalidCallback:"&"},link:function(a,b,c,e){var f=c.validator.split(",");b.after(""),e.$setValidity(e.$name,!1),a.$on(e.$name+"reset",function(){b.next().html("")}),f.forEach(function(d){return a.$on(e.$name+"submit",function(){var f=b[0].value;g(a,b,c,e,d,f)}),"blur"===c.validMethod?void b.bind("blur",function(){var f=b[0].value;a.$apply(function(){g(a,b,c,e,d,f)})}):void("submit"!==c.validMethod&&a.$watch("model",function(f){if(e.$pristine&&e.$viewValue)e.$setViewValue(e.$viewValue);else if(e.$pristine)return void b.next().html("");g(a,b,c,e,d,f)}))}),d(function(){c.$observe("noValidationMessage",function(a){var c=b.next();"true"==a||1==a?c.css("display","none"):("false"==a||0==a)&&c.css("display","block")})})}}}])}.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=this,f=function(e){a=e,b=a.get("$rootScope"),c=a.get("$http"),d=a.get("$q")},g={required:/^.+$/,url:/((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/,email:/^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/,number:/^\d+$/},h={required:{error:"This should be Required!!",success:"It's Required"},url:{error:"This should be Url",success:"It's Url"},email:{error:"This should be Email",success:"It's Email"},number:{error:"This should be Number",success:"It's Number"}};this.setExpression=function(a){angular.extend(g,a)},this.getExpression=function(a){return g[a]},this.setDefaultMsg=function(a){angular.extend(h,a)},this.getDefaultMsg=function(a){return h[a]},this.setErrorHTML=function(a){a.constructor===Function&&(e.getErrorHTML=a)},this.getErrorHTML=function(a){return''+a+"
"},this.setSuccessHTML=function(a){a.constructor===Function&&(e.getSuccessHTML=a)},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){for(var c in a)a[c].hasOwnProperty("$dirty")&&b.$broadcast(c+"submit");var f=d.defer();return f.promise.success=function(a){return f.promise.then(function(b){a(b)}),f.promise},f.promise.error=function(a){return f.promise.then(null,function(b){a(b)}),f.promise},e.checkValid(a)?f.resolve("success"):f.reject("error"),f.promise},this.reset=function(a){for(var c in a)a[c].hasOwnProperty("$dirty")&&b.$broadcast(c+"reset")},this.$get=["$injector",function(a){return f(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){a.next().html(b.showSuccessMessage?b.getSuccessHTML(c||b.getDefaultMsg(d).success):""),f.$setValidity(f.$name,!0),e&&e()},f=function(a,c,d,e,f){a.next().html(b.showErrorMessage?b.getErrorHTML(c||b.getDefaultMsg(d).error):""),f.$setValidity(f.$name,!1),e&&e()},g=function(a,d,g,h,i,j){var k=i+"SuccessMessage",l=i+"ErrorMessage",m=b.getExpression(i).constructor,n={success:function(){e(d,g[k],i,a.validCallback(),h)},error:function(){f(d,g[l],i,a.invalidCallback(),h)}};return m===Function?c.all([b.getExpression(i)(j)]).then(function(a){return a&&a.length>0&&a[0]?n.success():n.error()},function(){return n.error()}):m===RegExp&&b.getExpression(i).test(j)?n.success():n.error()};return{restrict:"A",require:"ngModel",scope:{model:"=ngModel",validCallback:"&",invalidCallback:"&"},link:function(a,b,c,e){var f=c.validator.split(",");b.after(""),e.$setValidity(e.$name,!1),a.$on(e.$name+"reset",function(){e.$setViewValue(null),e.$setPristine(),e.$setValidity(e.$name,!1),e.$render(),b.next().html("")}),f.forEach(function(d){return a.$on(e.$name+"submit",function(){var f=b[0].value;g(a,b,c,e,d,f)}),"blur"===c.validMethod?void b.bind("blur",function(){var f=b[0].value;a.$apply(function(){g(a,b,c,e,d,f)})}):void("submit"!==c.validMethod&&a.$watch("model",function(f){if(e.$pristine&&e.$viewValue)e.$setViewValue(e.$viewValue);else if(e.$pristine)return void b.next().html("");g(a,b,c,e,d,f)}))}),d(function(){c.$observe("noValidationMessage",function(a){var c=b.next();"true"==a||1==a?c.css("display","none"):("false"==a||0==a)&&c.css("display","block")})})}}}])}.call(this); \ No newline at end of file diff --git a/src/directive.js b/src/directive.js index 9dd46d5..f23825d 100644 --- a/src/directive.js +++ b/src/directive.js @@ -123,6 +123,10 @@ * Reset the validation for specific form */ scope.$on(ctrl.$name + 'reset', function () { + ctrl.$setViewValue(null); + ctrl.$setPristine(); + ctrl.$setValidity(ctrl.$name, false); + ctrl.$render(); element.next().html(''); }); diff --git a/src/provider.js b/src/provider.js index b37e6b1..817794c 100644 --- a/src/provider.js +++ b/src/provider.js @@ -220,10 +220,6 @@ this.reset = function (form) { for (var k in form) { if (form[k].hasOwnProperty('$dirty')) { - form[k].$setViewValue(null); - form[k].$setPristine(); - form[k].$setValidity(form[k].$name, false); - form[k].$render(); $scope.$broadcast(k + 'reset'); } }