From a1a80fcb1a8fd52d0cb77b87b9650c675680148f Mon Sep 17 00:00:00 2001 From: Luca Trazzi Date: Fri, 11 Dec 2015 15:37:22 +0100 Subject: [PATCH] updated dist --- dist/angular-validation.js | 42 ++++++++++++++++++++++++++++------ dist/angular-validation.min.js | 2 +- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/dist/angular-validation.js b/dist/angular-validation.js index f5f18ea..8782835 100644 --- a/dist/angular-validation.js +++ b/dist/angular-validation.js @@ -3,7 +3,7 @@ angular.module('validation.provider', []); angular.module('validation.directive', ['validation.provider']); }).call(this); - + (function() { angular .module('validation.provider') @@ -35,6 +35,12 @@ */ var expression = {}; + /** + * default valid method + * @type {{}} + */ + var validMethod = null; + /** * default error, success message * @type {{}} @@ -79,6 +85,23 @@ return defaultMsg[msg]; }; + /** + * allow user to set the global valid method + * @param v + * @returns {*} + */ + this.setValidMethod = function(v) { + validMethod = v; + }; + + /** + * Get the valid method + * @returns {*} + */ + this.getValidMethod = function() { + return validMethod; + }; + /** * Override the errorHTML function * @param func @@ -247,6 +270,8 @@ this.$get = ['$injector', function($injector) { setup($injector); return { + setValidMethod: this.setValidMethod, + getValidMethod: this.getValidMethod, setErrorHTML: this.setErrorHTML, getErrorHTML: this.getErrorHTML, setSuccessHTML: this.setSuccessHTML, @@ -266,7 +291,7 @@ }]; } }).call(this); - + (function() { angular .module('validation.directive') @@ -290,7 +315,7 @@ } Reset.$inject = ['$injector']; }).call(this); - + (function() { angular .module('validation.directive') @@ -321,7 +346,7 @@ } Submit.$inject = ['$injector']; }).call(this); - + (function() { angular .module('validation.directive') @@ -556,6 +581,9 @@ * Check validator */ + + var validMethod = (angular.isUndefined(attrs.validMethod)) ? $validationProvider.getValidMethod() : attrs.validMethod; + /** * Click submit form, check the validity when submit */ @@ -565,7 +593,7 @@ isValid = checkValidation(scope, element, attrs, ctrl, validation, value); - if (attrs.validMethod === 'submit') { + if (validMethod === 'submit') { // clear previous scope.$watch watch(); watch = scope.$watch(function() { @@ -606,7 +634,7 @@ /** * Validate blur method */ - if (attrs.validMethod === 'blur') { + if (validMethod === 'blur') { element.bind('blur', function() { var value = scope.$eval(attrs.ngModel); scope.$apply(function() { @@ -620,7 +648,7 @@ /** * Validate submit & submit-only method */ - if (attrs.validMethod === 'submit' || attrs.validMethod === 'submit-only') { + if (validMethod === 'submit' || validMethod === 'submit-only') { return; } diff --git a/dist/angular-validation.min.js b/dist/angular-validation.min.js index e8bad40..1472b4a 100644 --- a/dist/angular-validation.min.js +++ b/dist/angular-validation.min.js @@ -1 +1 @@ -(function(){angular.module("validation",["validation.provider","validation.directive"]),angular.module("validation.provider",[]),angular.module("validation.directive",["validation.provider"])}).call(this),function(){function a(){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!(!a||!a.$valid)},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)"$"!==i[0]&&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.validCallback=null,this.invalidCallback=null,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)"$"!==d[0]&&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,validCallback:this.validCallback,invalidCallback:this.invalidCallback,reset:this.reset}}]}angular.module("validation.provider").provider("$validation",a)}.call(this),function(){function a(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)})})}}}angular.module("validation.directive").directive("validationReset",a),a.$inject=["$injector"]}.call(this),function(){function a(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)})})})}}}angular.module("validation.directive").directive("validationSubmit",a),a.$inject=["$injector"]}.call(this),function(){function a(a){var b=a.get("$validation"),c=a.get("$q"),d=a.get("$timeout"),e=a.get("$parse"),f=function(a,c,d,f,g,h){var i,j=c||b.getDefaultMsg(d).success,k=e("success");return i=h.messageId?angular.element(document.querySelector("#"+h.messageId)):a.next(),a.attr("no-validation-message")?i.css("display","none"):b.showSuccessMessage&&j?(i.html(b.getSuccessHTML(j)),i.css("display","")):i.css("display","none"),g.$setValidity(g.$name,!0),k&&k({message:j}),b.validCallback&&b.validCallback(a),!0},g=function(a,c,d,f,g,h){var i,j=c||b.getDefaultMsg(d).error,k=e("error");return i=h.messageId?angular.element(document.querySelector("#"+h.messageId)):a.next(),a.attr("no-validation-message")?i.css("display","none"):b.showErrorMessage&&j?(i.html(b.getErrorHTML(j)),i.css("display","")):i.css("display","none"),g.$setValidity(g.$name,!1),k&&k({message:j}),b.invalidCallback&&b.invalidCallback(a),!1},h={},i=function(a,d,e,h,j,k){var l=j.slice(0),m=l[0].trim(),n=m.indexOf("="),o=-1===n?m:m.substr(0,n),p=-1===n?null:m.substr(n+1),q=l.slice(1),r=o+"SuccessMessage",s=o+"ErrorMessage",t=b.getExpression(o),u={success:function(){return f(d,e[r],o,a,h,e),q.length?i(a,d,e,h,q,k):!0},error:function(){return g(d,e[s],o,a,h,e)}};return void 0===t?(console.error('You are using undefined validator "%s"',o),q.length?i(a,d,e,h,q,k):void 0):t.constructor===Function?c.all([b.getExpression(o)(k,a,d,e,p)]).then(function(a){return a&&a.length>0&&a[0]?u.success():u.error()},function(){return u.error()}):t.constructor===RegExp&&void 0!==k&&null!==k&&b.getExpression(o).test(k)?u.success():u.error()},j=function(){return(65536*(1+Math.random())|0).toString(16).substring(1)},k=function(){return j()+j()+j()+j()};return{restrict:"A",require:"ngModel",link:function(a,b,c,e){var f,g=function(){},j=c.validator.split(","),l=e.validationId=k();return"boolean"==typeof a.initialValidity&&(f=a.initialValidity),c.messageId||b.after(""),e.$setValidity(e.$name,f),a.$on(e.$name+"reset-"+l,function(){g(),d(function(){e.$setViewValue(""),e.$setPristine(),e.$setValidity(e.$name,void 0),e.$render(),c.messageId?angular.element(document.querySelector("#"+c.messageId)).html(""):b.next().html("")})}),a.$on(e.$name+"submit-"+l,function(f,k){var l=e.$viewValue,m=!1;m=i(a,b,c,e,j,l),"submit"===c.validMethod&&(g(),g=a.$watch(function(){return a.$eval(c.ngModel)},function(d,f){d!==f&&((void 0===d||null===d)&&(d=""),m=i(a,b,c,e,j,d))}));var n=function(a){a?delete h[k]:(h[k]=b[0],d(function(){h[Math.min.apply(null,Object.keys(h))].focus()},0))};m.constructor===Object?m.then(n):n(m)}),"blur"===c.validMethod?void b.bind("blur",function(){var d=a.$eval(c.ngModel);a.$apply(function(){i(a,b,c,e,j,d)})}):void("submit"!==c.validMethod&&"submit-only"!==c.validMethod&&(a.$watch(function(){return a.$eval(c.ngModel)},function(d){if(e.$pristine&&e.$viewValue)e.$setViewValue(e.$viewValue);else if(e.$pristine)return void(c.messageId?angular.element(document.querySelector("#"+c.messageId)).html(""):b.next().html(""));i(a,b,c,e,j,d)}),d(function(){c.$observe("noValidationMessage",function(a){var d;d=c.messageId?angular.element(document.querySelector("#"+c.messageId)):b.next(),"true"===a||a===!0?d.css("display","none"):("false"===a||a===!1)&&d.css("display","block")})})))}}}angular.module("validation.directive").directive("validator",a),a.$inject=["$injector"]}.call(this); \ No newline at end of file +(function(){angular.module("validation",["validation.provider","validation.directive"]),angular.module("validation.provider",[]),angular.module("validation.directive",["validation.provider"])}).call(this),function(){function a(){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=null,j={};this.setExpression=function(a){return angular.extend(h,a),f},this.getExpression=function(a){return h[a]},this.setDefaultMsg=function(a){return angular.extend(j,a),f},this.getDefaultMsg=function(a){return j[a]},this.setValidMethod=function(a){i=a},this.getValidMethod=function(){return i},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!(!a||!a.$valid)},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)"$"!==i[0]&&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.validCallback=null,this.invalidCallback=null,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)"$"!==d[0]&&a[d].hasOwnProperty("$dirty")&&b.$broadcast(d+"reset-"+a[d].validationId)},this.$get=["$injector",function(a){return g(a),{setValidMethod:this.setValidMethod,getValidMethod:this.getValidMethod,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,validCallback:this.validCallback,invalidCallback:this.invalidCallback,reset:this.reset}}]}angular.module("validation.provider").provider("$validation",a)}.call(this),function(){function a(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)})})}}}angular.module("validation.directive").directive("validationReset",a),a.$inject=["$injector"]}.call(this),function(){function a(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)})})})}}}angular.module("validation.directive").directive("validationSubmit",a),a.$inject=["$injector"]}.call(this),function(){function a(a){var b=a.get("$validation"),c=a.get("$q"),d=a.get("$timeout"),e=a.get("$parse"),f=function(a,c,d,f,g,h){var i,j=c||b.getDefaultMsg(d).success,k=e("success");return i=h.messageId?angular.element(document.querySelector("#"+h.messageId)):a.next(),a.attr("no-validation-message")?i.css("display","none"):b.showSuccessMessage&&j?(i.html(b.getSuccessHTML(j)),i.css("display","")):i.css("display","none"),g.$setValidity(g.$name,!0),k&&k({message:j}),b.validCallback&&b.validCallback(a),!0},g=function(a,c,d,f,g,h){var i,j=c||b.getDefaultMsg(d).error,k=e("error");return i=h.messageId?angular.element(document.querySelector("#"+h.messageId)):a.next(),a.attr("no-validation-message")?i.css("display","none"):b.showErrorMessage&&j?(i.html(b.getErrorHTML(j)),i.css("display","")):i.css("display","none"),g.$setValidity(g.$name,!1),k&&k({message:j}),b.invalidCallback&&b.invalidCallback(a),!1},h={},i=function(a,d,e,h,j,k){var l=j.slice(0),m=l[0].trim(),n=m.indexOf("="),o=-1===n?m:m.substr(0,n),p=-1===n?null:m.substr(n+1),q=l.slice(1),r=o+"SuccessMessage",s=o+"ErrorMessage",t=b.getExpression(o),u={success:function(){return f(d,e[r],o,a,h,e),q.length?i(a,d,e,h,q,k):!0},error:function(){return g(d,e[s],o,a,h,e)}};return void 0===t?(console.error('You are using undefined validator "%s"',o),q.length?i(a,d,e,h,q,k):void 0):t.constructor===Function?c.all([b.getExpression(o)(k,a,d,e,p)]).then(function(a){return a&&a.length>0&&a[0]?u.success():u.error()},function(){return u.error()}):t.constructor===RegExp&&void 0!==k&&null!==k&&b.getExpression(o).test(k)?u.success():u.error()},j=function(){return(65536*(1+Math.random())|0).toString(16).substring(1)},k=function(){return j()+j()+j()+j()};return{restrict:"A",require:"ngModel",link:function(a,c,e,f){var g,j=function(){},l=e.validator.split(","),m=f.validationId=k();"boolean"==typeof a.initialValidity&&(g=a.initialValidity),e.messageId||c.after(""),f.$setValidity(f.$name,g),a.$on(f.$name+"reset-"+m,function(){j(),d(function(){f.$setViewValue(""),f.$setPristine(),f.$setValidity(f.$name,void 0),f.$render(),e.messageId?angular.element(document.querySelector("#"+e.messageId)).html(""):c.next().html("")})});var n=angular.isUndefined(e.validMethod)?b.getValidMethod():e.validMethod;return a.$on(f.$name+"submit-"+m,function(b,g){var k=f.$viewValue,m=!1;m=i(a,c,e,f,l,k),"submit"===n&&(j(),j=a.$watch(function(){return a.$eval(e.ngModel)},function(b,d){b!==d&&((void 0===b||null===b)&&(b=""),m=i(a,c,e,f,l,b))}));var o=function(a){a?delete h[g]:(h[g]=c[0],d(function(){h[Math.min.apply(null,Object.keys(h))].focus()},0))};m.constructor===Object?m.then(o):o(m)}),"blur"===n?void c.bind("blur",function(){var b=a.$eval(e.ngModel);a.$apply(function(){i(a,c,e,f,l,b)})}):void("submit"!==n&&"submit-only"!==n&&(a.$watch(function(){return a.$eval(e.ngModel)},function(b){if(f.$pristine&&f.$viewValue)f.$setViewValue(f.$viewValue);else if(f.$pristine)return void(e.messageId?angular.element(document.querySelector("#"+e.messageId)).html(""):c.next().html(""));i(a,c,e,f,l,b)}),d(function(){e.$observe("noValidationMessage",function(a){var b;b=e.messageId?angular.element(document.querySelector("#"+e.messageId)):c.next(),"true"===a||a===!0?b.css("display","none"):("false"===a||a===!1)&&b.css("display","block")})})))}}}angular.module("validation.directive").directive("validator",a),a.$inject=["$injector"]}.call(this); \ No newline at end of file