From 92b7ef461a4e95d42d4afa84da2861fc0c37dab7 Mon Sep 17 00:00:00 2001 From: Ghislain B Date: Thu, 9 Apr 2015 08:51:05 -0400 Subject: [PATCH] Bumped to v1.3.16 Bumped to version 1.3.16 after Merge #3 --- app.js | 2 ++ bower.json | 2 +- changelog.txt | 3 ++- dist/angular-validation.min.js | 6 +++--- package.json | 2 +- readme.md | 5 +++-- src/validation-common.js | 2 +- 7 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app.js b/app.js index 7ac0187..9ef20f6 100644 --- a/app.js +++ b/app.js @@ -58,6 +58,8 @@ myApp.controller('CtrlValidationDirective', ['$scope', 'validationService', func } }]); +// -- Controller to use Angular-Validation Directive with 2 forms +// --------------------------------------------------------------- myApp.controller('Ctrl2forms', ['$scope', 'validationService', function ($scope, validationService) { $scope.submitForm = function() { if(new validationService().checkFormValidity($scope.form01)) { diff --git a/bower.json b/bower.json index 9874cd9..31d0464 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "ghiscoding.angular-validation", - "version": "1.3.15", + "version": "1.3.16", "authors": [ "Ghislain B." ], diff --git a/changelog.txt b/changelog.txt index 32050b4..a56cbe9 100644 --- a/changelog.txt +++ b/changelog.txt @@ -16,4 +16,5 @@ Angular-Validation change logs 1.3.12 (2015-04-04): Fix issue #16 and added Validators Alternate Text option on all type of validators. Also fixed removeValidator and clean a lot of code. 1.3.13 (2015-04-06) Fixed $translate delay issue when using external JSON files 1.3.14 (2015-04-07) Merge pull request #19 Added norwegian translation and changes to allow user to remove invalid validators. -1.3.15 (2015-04-08) Fixed #23 If multiple forms exist in the app the errors in 1 form affect validation in the other \ No newline at end of file +1.3.15 (2015-04-08) Fixed #23 If multiple forms exist in the app the errors in 1 form affect validation in the other +1.3.16 (2015-04-09) Accept Merge #3 Fixed removeFromValidationSummary to also remove from 'local' array \ No newline at end of file diff --git a/dist/angular-validation.min.js b/dist/angular-validation.min.js index acb5e0a..c42c642 100644 --- a/dist/angular-validation.min.js +++ b/dist/angular-validation.min.js @@ -2,11 +2,11 @@ * Angular-Validation Directive and Service (ghiscoding) * http://github.com/ghiscoding/angular-validation * @author: Ghislain B. - * @version: 1.3.15 + * @version: 1.3.16 * @license: MIT - * @build: Thu Apr 09 2015 00:07:40 GMT-0400 (Eastern Daylight Time) + * @build: Thu Apr 09 2015 08:50:15 GMT-0400 (Eastern Daylight Time) */ angular.module("ghiscoding.validation",["pascalprecht.translate"]).directive("validation",["$timeout","validationCommon","validationRules",function(i,t){return{restrict:"A",require:"ngModel",link:function(a,e,n,l){function d(){i.cancel(r),u.updateErrorMsg(""),l.$setValidity("validation",!0),e.unbind("blur")}function o(t){return u.validate(t,!1),u.isFieldRequired()||""!==t&&null!==t&&"undefined"!=typeof t?((u.isFieldRequired()||t)&&l.$setValidity("validation",!1),e.bind("blur",function(){return a.$evalAsync(l.$setValidity("validation",u.validate(t,!0))),t}),"SELECT"===e.prop("tagName").toUpperCase()?(l.$setValidity("validation",u.validate(t,!0)),t):("undefined"!=typeof t&&(u.updateErrorMsg(""),i.cancel(r),r=i(function(){a.$evalAsync(l.$setValidity("validation",u.validate(t,!0)))},u.typingLimit)),t)):(d(),t)}var r,u=new t(a,e,n,l);l.$parsers.unshift(o),l.$formatters.unshift(o),n.$observe("disabled",function(i){i?l.$setValidity("validation",!0):l.$setValidity("validation",u.validate(l.$viewValue,!0))})}}}]); -angular.module("ghiscoding.validation").factory("validationCommon",["$filter","$timeout","$translate","validationRules",function(t,a,e,r){function i(){var t=this,a={};t.validators=[],t.typingLimit=R,t.validatorAttrs.hasOwnProperty("debounce")?t.typingLimit=parseInt(t.validatorAttrs.debounce,10):t.validatorAttrs.hasOwnProperty("typingLimit")&&(t.typingLimit=parseInt(t.validatorAttrs.typingLimit,10));var e=t.validatorAttrs.hasOwnProperty("rules")?t.validatorAttrs.rules:t.validatorAttrs.validation;if(e.indexOf("regex:")>=0){var i=e.match("regex:(.*?):regex");if(i.length<2)throw'Regex validator within the validation needs to be define with an opening "regex:" and a closing ":regex", please review your validator.';var l=i[1].split(":=");a={message:l[0],pattern:l[1]},e=e.replace(i[0],"regex:")}var n=e.split("|");if(n){t.bFieldRequired=e.indexOf("required")>=0?!0:!1;for(var s=0,o=n.length;o>s;s++){var d=n[s].split(":"),u=n[s].indexOf("alt=")>=0?!0:!1;t.validators[s]=r.getElementValidators({altText:u===!0?2===d.length?d[1]:d[2]:"",customRegEx:a,rule:d[0],ruleParams:u&&2===d.length?null:d[1]})}}return t}function l(t){return g(x,"fieldName",t)}function n(){return x}function s(t,a,e,r){this.scope=t,this.elm=a,this.ctrl=r,this.validatorAttrs=e,v(a,e,r),this.defineValidation()}function o(){var t=this;return t.bFieldRequired}function d(t,a){var e=h(t,"field",a);e>=0&&t.splice(e,1)}function u(t,a){var r=this;a&&a.obj&&(r=a.obj,r.validatorAttrs=a.obj.attrs);var i=a&&a.elm?a.elm:r.elm,l=i&&i.attr("name")?i.attr("name"):null;if("undefined"==typeof l||null===l)throw'Angular-Validation Service requires you to have a (name="") attribute on the element to validate... Your element is: ng-model="'+i.attr("ng-model")+'"';var n=a&&a.translate?e(t):t,s=l.replace(/[|&;$%@"<>()+,\[\]\{\}]/g,""),o=null;if(r.validatorAttrs&&r.validatorAttrs.hasOwnProperty("validationErrorTo")){var d=r.validatorAttrs.validationErrorTo.charAt(0),u="."===d||"#"===d?r.validatorAttrs.validationErrorTo:"#"+r.validatorAttrs.validationErrorTo;o=angular.element(document.querySelector(u))}o&&0!==o.length||(o=angular.element(document.querySelector(".validation-"+s)));var p=a&&a.isSubmitted?a.isSubmitted:!1;a&&!a.isValid&&(p||r.ctrl.$dirty||r.ctrl.$touched)?o.length>0?o.text(n):i.after(''+n+""):o.text("")}function p(t,a){for(var r,i=this,n=!0,s=!0,o="",d=0,u=i.validators.length;u>d;d++){if("conditionalDate"===i.validators[d].type){if(r=new RegExp(i.validators[d].pattern,"i"),s="\\S+"!==i.validators[d].pattern||"undefined"!=typeof t&&null!==t?r.test(t):!1){var p=i.validators[d].dateType,v=y(t,p).getTime();if(2==i.validators[d].params.length){var m=y(i.validators[d].params[0],p).getTime(),g=y(i.validators[d].params[1],p).getTime(),f=O(i.validators[d].condition[0],v,m),h=O(i.validators[d].condition[1],v,g);s=f&&h?!0:!1}else{var b=y(i.validators[d].params[0],p).getTime();s=O(i.validators[d].condition,v,b)}}}else if("conditionalNumber"===i.validators[d].type)if(2==i.validators[d].params.length){var f=O(i.validators[d].condition[0],parseFloat(t),parseFloat(i.validators[d].params[0])),h=O(i.validators[d].condition[1],parseFloat(t),parseFloat(i.validators[d].params[1]));s=f&&h?!0:!1}else s=O(i.validators[d].condition,parseFloat(t),parseFloat(i.validators[d].params[0]));else if("match"===i.validators[d].type){var E=i.validators[d].params[0],R=i.scope.$eval(E);s=R===t}else i.elm.prop("disabled")||1==parseInt(i.elm.attr("ng-disabled"))||"true"===i.elm.attr("ng-disabled")?s=!0:"string"==typeof t&&""===t&&"NUMBER"===i.elm.prop("type").toUpperCase()?(o=e("INVALID_KEY_CHAR"),s=!1):(r=new RegExp(i.validators[d].pattern,"i"),s="\\S+"!==i.validators[d].pattern||"undefined"!=typeof t&&null!==t?r.test(t):!1);if((!i.bFieldRequired&&!t||i.elm.prop("disabled")||1==parseInt(i.elm.attr("ng-disabled"))||"true"===i.elm.attr("ng-disabled"))&&(s=!0),!s&&(n=!1,o+=" ",o+=i.validators[d].altText&&i.validators[d].altText.length>0?i.validators[d].altText.replace("alt=",""):e(i.validators[d].message),"undefined"!=typeof i.validators[d].params))for(var x=0,S=i.validators[d].params.length;S>x;x++)"match"===i.validators[d].type&&S>1&&0===x||(o=o.replace(":param",i.validators[d].params[x]))}o=o.trim(),c(i,e(o));var A=l(i.elm.attr("name"));return A&&(A.isValid=s,A.message=e(o)),a&&i.updateErrorMsg(o,{isValid:n}),n}function v(t,a,e){var r={fieldName:t.attr("name"),elm:t,attrs:a,ctrl:e,isValid:!1,message:""},i=h(x,"fieldName",t.attr("name"));return i>=0?x[i]=r:x.push(r),x}function m(t){var a=h(x,"fieldName",t);a>=0&&x.splice(a,1)}function c(t,a){var e=t.elm.attr("name"),r=b(t),i=h(S,"field",e);if(i>=0&&""===a)S.splice(i,1);else if(""!==a){var l={field:e,message:a,formName:r?r.$name:null};i>=0?S[i]=l:S.push(l)}t.scope.$validationSummary=S,r&&(r.$validationSummary=f(S,"formName",r.$name))}function g(t,a,e){for(var r=0;r8?t.substring(9).split(":"):null;break;case"UK":case"EURO":case"EURO_SHORT":case"EURO-SHORT":case"EUROPE":e=t.substring(0,8),r=t.substring(2,3),i=E(e,r),o=i[0],s=i[1],n=parseInt(i[2])<50?"20"+i[2]:"19"+i[2],l=t.length>8?t.substring(9).split(":"):null;break;case"US_LONG":case"US-LONG":e=t.substring(0,10),r=t.substring(2,3),i=E(e,r),s=i[0],o=i[1],n=i[2],l=t.length>8?t.substring(9).split(":"):null;break;case"US":case"US_SHORT":case"US-SHORT":e=t.substring(0,8),r=t.substring(2,3),i=E(e,r),s=i[0],o=i[1],n=parseInt(i[2])<50?"20"+i[2]:"19"+i[2],l=t.length>8?t.substring(9).split(":"):null;break;case"ISO":default:e=t.substring(0,10),r=t.substring(4,5),i=E(e,r),n=i[0],s=i[1],o=i[2],l=t.length>10?t.substring(11).split(":"):null}var d=l&&3===l.length?l[0]:0,u=l&&3===l.length?l[1]:0,p=l&&3===l.length?l[2]:0;return new Date(n,s-1,o,d,u,p)}function E(t,a){var e=[];switch(a){case"/":e=t.split("/");break;case".":e=t.split(".");break;case"-":default:e=t.split("-")}return e}function O(t,a,e){var r=!1;switch(t){case"<":r=e>a?!0:!1;break;case"<=":r=e>=a?!0:!1;break;case">":r=a>e?!0:!1;break;case">=":r=a>=e?!0:!1;break;case"!=":case"<>":r=a!=e?!0:!1;break;case"=":case"==":r=a==e?!0:!1;break;default:r=!1}return r}var R=1e3,x=[],S=[],e=t("translate"),A=function(t,a,e,r){this.timer=null,this.bFieldRequired=!1,this.validators=[],this.typingLimit=R,this.scope=t,this.elm=a,this.ctrl=r,this.validatorAttrs=e,t&&a&&e&&r&&(v(a,e,r),this.defineValidation())};return A.prototype.defineValidation=i,A.prototype.getFormElementByName=l,A.prototype.getFormElements=n,A.prototype.isFieldRequired=o,A.prototype.initialize=s,A.prototype.removeFromValidationSummary=d,A.prototype.updateErrorMsg=u,A.prototype.validate=p,A.prototype.removeFromFormElementObjectList=m,A}]); +angular.module("ghiscoding.validation").factory("validationCommon",["$filter","$timeout","$translate","validationRules",function(t,a,e,r){function i(){var t=this,a={};t.validators=[],t.typingLimit=R,t.validatorAttrs.hasOwnProperty("debounce")?t.typingLimit=parseInt(t.validatorAttrs.debounce,10):t.validatorAttrs.hasOwnProperty("typingLimit")&&(t.typingLimit=parseInt(t.validatorAttrs.typingLimit,10));var e=t.validatorAttrs.hasOwnProperty("rules")?t.validatorAttrs.rules:t.validatorAttrs.validation;if(e.indexOf("regex:")>=0){var i=e.match("regex:(.*?):regex");if(i.length<2)throw'Regex validator within the validation needs to be define with an opening "regex:" and a closing ":regex", please review your validator.';var l=i[1].split(":=");a={message:l[0],pattern:l[1]},e=e.replace(i[0],"regex:")}var n=e.split("|");if(n){t.bFieldRequired=e.indexOf("required")>=0?!0:!1;for(var s=0,o=n.length;o>s;s++){var d=n[s].split(":"),u=n[s].indexOf("alt=")>=0?!0:!1;t.validators[s]=r.getElementValidators({altText:u===!0?2===d.length?d[1]:d[2]:"",customRegEx:a,rule:d[0],ruleParams:u&&2===d.length?null:d[1]})}}return t}function l(t){return g(x,"fieldName",t)}function n(){return x}function s(t,a,e,r){this.scope=t,this.elm=a,this.ctrl=r,this.validatorAttrs=e,v(a,e,r),this.defineValidation()}function o(){var t=this;return t.bFieldRequired}function d(t,a){var e=h(t,"field",a);e>=0&&t.splice(e,1),e=h(S,"field",a),e>=0&&S.splice(e,1)}function u(t,a){var r=this;a&&a.obj&&(r=a.obj,r.validatorAttrs=a.obj.attrs);var i=a&&a.elm?a.elm:r.elm,l=i&&i.attr("name")?i.attr("name"):null;if("undefined"==typeof l||null===l)throw'Angular-Validation Service requires you to have a (name="") attribute on the element to validate... Your element is: ng-model="'+i.attr("ng-model")+'"';var n=a&&a.translate?e(t):t,s=l.replace(/[|&;$%@"<>()+,\[\]\{\}]/g,""),o=null;if(r.validatorAttrs&&r.validatorAttrs.hasOwnProperty("validationErrorTo")){var d=r.validatorAttrs.validationErrorTo.charAt(0),u="."===d||"#"===d?r.validatorAttrs.validationErrorTo:"#"+r.validatorAttrs.validationErrorTo;o=angular.element(document.querySelector(u))}o&&0!==o.length||(o=angular.element(document.querySelector(".validation-"+s)));var p=a&&a.isSubmitted?a.isSubmitted:!1;a&&!a.isValid&&(p||r.ctrl.$dirty||r.ctrl.$touched)?o.length>0?o.text(n):i.after(''+n+""):o.text("")}function p(t,a){for(var r,i=this,n=!0,s=!0,o="",d=0,u=i.validators.length;u>d;d++){if("conditionalDate"===i.validators[d].type){if(r=new RegExp(i.validators[d].pattern,"i"),s="\\S+"!==i.validators[d].pattern||"undefined"!=typeof t&&null!==t?r.test(t):!1){var p=i.validators[d].dateType,v=y(t,p).getTime();if(2==i.validators[d].params.length){var m=y(i.validators[d].params[0],p).getTime(),g=y(i.validators[d].params[1],p).getTime(),f=O(i.validators[d].condition[0],v,m),h=O(i.validators[d].condition[1],v,g);s=f&&h?!0:!1}else{var b=y(i.validators[d].params[0],p).getTime();s=O(i.validators[d].condition,v,b)}}}else if("conditionalNumber"===i.validators[d].type)if(2==i.validators[d].params.length){var f=O(i.validators[d].condition[0],parseFloat(t),parseFloat(i.validators[d].params[0])),h=O(i.validators[d].condition[1],parseFloat(t),parseFloat(i.validators[d].params[1]));s=f&&h?!0:!1}else s=O(i.validators[d].condition,parseFloat(t),parseFloat(i.validators[d].params[0]));else if("match"===i.validators[d].type){var E=i.validators[d].params[0],R=i.scope.$eval(E);s=R===t}else i.elm.prop("disabled")||1==parseInt(i.elm.attr("ng-disabled"))||"true"===i.elm.attr("ng-disabled")?s=!0:"string"==typeof t&&""===t&&"NUMBER"===i.elm.prop("type").toUpperCase()?(o=e("INVALID_KEY_CHAR"),s=!1):(r=new RegExp(i.validators[d].pattern,"i"),s="\\S+"!==i.validators[d].pattern||"undefined"!=typeof t&&null!==t?r.test(t):!1);if((!i.bFieldRequired&&!t||i.elm.prop("disabled")||1==parseInt(i.elm.attr("ng-disabled"))||"true"===i.elm.attr("ng-disabled"))&&(s=!0),!s&&(n=!1,o+=" ",o+=i.validators[d].altText&&i.validators[d].altText.length>0?i.validators[d].altText.replace("alt=",""):e(i.validators[d].message),"undefined"!=typeof i.validators[d].params))for(var x=0,S=i.validators[d].params.length;S>x;x++)"match"===i.validators[d].type&&S>1&&0===x||(o=o.replace(":param",i.validators[d].params[x]))}o=o.trim(),c(i,e(o));var A=l(i.elm.attr("name"));return A&&(A.isValid=s,A.message=e(o)),a&&i.updateErrorMsg(o,{isValid:n}),n}function v(t,a,e){var r={fieldName:t.attr("name"),elm:t,attrs:a,ctrl:e,isValid:!1,message:""},i=h(x,"fieldName",t.attr("name"));return i>=0?x[i]=r:x.push(r),x}function m(t){var a=h(x,"fieldName",t);a>=0&&x.splice(a,1)}function c(t,a){var e=t.elm.attr("name"),r=b(t),i=h(S,"field",e);if(i>=0&&""===a)S.splice(i,1);else if(""!==a){var l={field:e,message:a,formName:r?r.$name:null};i>=0?S[i]=l:S.push(l)}t.scope.$validationSummary=S,r&&(r.$validationSummary=f(S,"formName",r.$name))}function g(t,a,e){for(var r=0;r8?t.substring(9).split(":"):null;break;case"UK":case"EURO":case"EURO_SHORT":case"EURO-SHORT":case"EUROPE":e=t.substring(0,8),r=t.substring(2,3),i=E(e,r),o=i[0],s=i[1],n=parseInt(i[2])<50?"20"+i[2]:"19"+i[2],l=t.length>8?t.substring(9).split(":"):null;break;case"US_LONG":case"US-LONG":e=t.substring(0,10),r=t.substring(2,3),i=E(e,r),s=i[0],o=i[1],n=i[2],l=t.length>8?t.substring(9).split(":"):null;break;case"US":case"US_SHORT":case"US-SHORT":e=t.substring(0,8),r=t.substring(2,3),i=E(e,r),s=i[0],o=i[1],n=parseInt(i[2])<50?"20"+i[2]:"19"+i[2],l=t.length>8?t.substring(9).split(":"):null;break;case"ISO":default:e=t.substring(0,10),r=t.substring(4,5),i=E(e,r),n=i[0],s=i[1],o=i[2],l=t.length>10?t.substring(11).split(":"):null}var d=l&&3===l.length?l[0]:0,u=l&&3===l.length?l[1]:0,p=l&&3===l.length?l[2]:0;return new Date(n,s-1,o,d,u,p)}function E(t,a){var e=[];switch(a){case"/":e=t.split("/");break;case".":e=t.split(".");break;case"-":default:e=t.split("-")}return e}function O(t,a,e){var r=!1;switch(t){case"<":r=e>a?!0:!1;break;case"<=":r=e>=a?!0:!1;break;case">":r=a>e?!0:!1;break;case">=":r=a>=e?!0:!1;break;case"!=":case"<>":r=a!=e?!0:!1;break;case"=":case"==":r=a==e?!0:!1;break;default:r=!1}return r}var R=1e3,x=[],S=[],e=t("translate"),A=function(t,a,e,r){this.timer=null,this.bFieldRequired=!1,this.validators=[],this.typingLimit=R,this.scope=t,this.elm=a,this.ctrl=r,this.validatorAttrs=e,t&&a&&e&&r&&(v(a,e,r),this.defineValidation())};return A.prototype.defineValidation=i,A.prototype.getFormElementByName=l,A.prototype.getFormElements=n,A.prototype.isFieldRequired=o,A.prototype.initialize=s,A.prototype.removeFromValidationSummary=d,A.prototype.updateErrorMsg=u,A.prototype.validate=p,A.prototype.removeFromFormElementObjectList=m,A}]); angular.module("ghiscoding.validation").factory("validationRules",[function(){function e(e){var a="undefined"!=typeof e.altText?e.altText.replace("alt=",""):null,t=e.hasOwnProperty("customRegEx")?e.customRegEx:null,s=e.hasOwnProperty("rule")?e.rule:null,r=e.hasOwnProperty("ruleParams")?e.ruleParams:null,n={};switch(s){case"alpha":n={pattern:"^([a-zÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ])+$",message:"INVALID_ALPHA",type:"regex"};break;case"alphaSpaces":case"alpha_spaces":n={pattern:"^([a-zÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ\\s])+$",message:"INVALID_ALPHA_SPACE",type:"regex"};break;case"alphaNum":case"alpha_num":n={pattern:"^([a-z0-9ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ])+$",message:"INVALID_ALPHA_NUM",type:"regex"};break;case"alphaNumSpaces":case"alpha_num_spaces":n={pattern:"^([a-z0-9ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ\\s])+$",message:"INVALID_ALPHA_NUM_SPACE",type:"regex"};break;case"alphaDash":case"alpha_dash":n={pattern:"^([a-z0-9ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ_-])+$",message:"INVALID_ALPHA_DASH",type:"regex"};break;case"alphaDashSpaces":case"alpha_dash_spaces":n={pattern:"^([a-z0-9ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ\\s_-])+$",message:"INVALID_ALPHA_DASH_SPACE",type:"regex"};break;case"betweenLen":case"between_len":var _=r.split(",");if(2!==_.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_len:1,5";n={pattern:"^.{"+_[0]+","+_[1]+"}$",message:"INVALID_BETWEEN_CHAR",params:[_[0],_[1]],type:"regex"};break;case"betweenNum":case"between_num":var _=r.split(",");if(2!==_.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_num:1,5";n={condition:[">=","<="],message:"INVALID_BETWEEN_NUM",params:[_[0],_[1]],type:"conditionalNumber"};break;case"creditCard":case"credit_card":n={pattern:"^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|6(?:011|5[0-9]{2})[0-9]{12}|(?:2131|1800|35\\d{3})\\d{11})$",message:"INVALID_CREDIT_CARD",type:"regex"};break;case"dateEuroLong":case"date_euro_long":n={pattern:"^(0[1-9]|[12][0-9]|3[01])[-/](0[1-9]|1[012])[-/](19|20)\\d\\d$",message:"INVALID_DATE_EURO_LONG",type:"regex"};break;case"dateEuroLongBetween":case"date_euro_long_between":case"betweenDateEuroLong":case"between_date_euro_long":var _=r.split(",");if(2!==_.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_euro_long:01-01-1990,31-12-2015";n={condition:[">=","<="],dateType:"EURO_LONG",params:[_[0],_[1]],pattern:"^(0[1-9]|[12][0-9]|3[01])[-/](0[1-9]|1[012])[-/](19|20)\\d\\d$",message:"INVALID_DATE_EURO_LONG_BETWEEN",type:"conditionalDate"};break;case"dateEuroLongMax":case"date_euro_long_max":case"maxDateEuroLong":case"max_date_euro_long":n={condition:"<=",dateType:"EURO_LONG",params:[r],pattern:"^(0[1-9]|[12][0-9]|3[01])[-/](0[1-9]|1[012])[-/](19|20)\\d\\d$",message:"INVALID_DATE_EURO_LONG_MAX",type:"conditionalDate"};break;case"dateEuroLongMin":case"date_euro_long_min":case"minDateEuroLong":case"min_date_euro_long":n={condition:">=",dateType:"EURO_LONG",params:[r],pattern:"^(0[1-9]|[12][0-9]|3[01])[-/](0[1-9]|1[012])[-/](19|20)\\d\\d$",message:"INVALID_DATE_EURO_LONG_MIN",type:"conditionalDate"};break;case"dateEuroShort":case"date_euro_short":n={pattern:"^(0[1-9]|[12][0-9]|3[01])[-/](0[1-9]|1[012])[-/]\\d\\d$",message:"INVALID_DATE_EURO_SHORT",type:"regex"};break;case"dateEuroShortBetween":case"date_euro_short_between":case"betweenDateEuroShort":case"between_date_euro_short":var _=r.split(",");if(2!==_.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_euro_short:01-01-90,31-12-15";n={condition:[">=","<="],dateType:"EURO_SHORT",params:[_[0],_[1]],pattern:"^(0[1-9]|[12][0-9]|3[01])[-/](0[1-9]|1[012])[-/]\\d\\d$",message:"INVALID_DATE_EURO_SHORT_BETWEEN",type:"conditionalDate"};break;case"dateEuroShortMax":case"date_euro_short_max":case"maxDateEuroShort":case"max_date_euro_short":n={condition:"<=",dateType:"EURO_SHORT",params:[r],pattern:"^(0[1-9]|[12][0-9]|3[01])[-/](0[1-9]|1[012])[-/]\\d\\d$",message:"INVALID_DATE_EURO_SHORT_MAX",type:"conditionalDate"};break;case"dateEuroShortMin":case"date_euro_short_min":case"minDateEuroShort":case"min_date_euro_short":n={condition:">=",dateType:"EURO_SHORT",params:[r],pattern:"^(0[1-9]|[12][0-9]|3[01])[-/](0[1-9]|1[012])[-/]\\d\\d$",message:"INVALID_DATE_EURO_SHORT_MIN",type:"conditionalDate"};break;case"dateIso":case"date_iso":n={pattern:"^(19|20)\\d\\d([-])(0[1-9]|1[012])\\2(0[1-9]|[12][0-9]|3[01])$",message:"INVALID_DATE_ISO",type:"regex"};break;case"dateIsoBetween":case"date_iso_between":case"betweenDateIso":case"between_date_iso":var _=r.split(",");if(2!==_.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_iso:1990-01-01,2000-12-31";n={condition:[">=","<="],dateType:"ISO",params:[_[0],_[1]],pattern:"^(19|20)\\d\\d([-])(0[1-9]|1[012])\\2(0[1-9]|[12][0-9]|3[01])$",message:"INVALID_DATE_ISO_BETWEEN",type:"conditionalDate"};break;case"dateIsoMax":case"date_iso_max":case"maxDateIso":case"max_date_iso":n={condition:"<=",dateType:"ISO",params:[r],pattern:"^(19|20)\\d\\d([-])(0[1-9]|1[012])\\2(0[1-9]|[12][0-9]|3[01])$",message:"INVALID_DATE_ISO_MAX",type:"conditionalDate"};break;case"dateIsoMin":case"date_iso_min":case"minDateIso":case"min_date_iso":n={condition:">=",dateType:"ISO",params:[r],pattern:"^(19|20)\\d\\d([-])(0[1-9]|1[012])\\2(0[1-9]|[12][0-9]|3[01])$",message:"INVALID_DATE_ISO_MIN",type:"conditionalDate"};break;case"dateUsLong":case"date_us_long":n={pattern:"^(0[1-9]|1[012])[-/](0[1-9]|[12][0-9]|3[01])[-/](19|20)\\d\\d$",message:"INVALID_DATE_US_LONG",type:"regex"};break;case"dateUsLongBetween":case"date_us_long_between":case"betweenDateUsLong":case"between_date_us_long":var _=r.split(",");if(2!==_.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_us_long:01/01/1990,12/31/2015";n={condition:[">=","<="],dateType:"US_LONG",params:[_[0],_[1]],pattern:"^(0[1-9]|1[012])[-/](0[1-9]|[12][0-9]|3[01])[-/](19|20)\\d\\d$",message:"INVALID_DATE_US_LONG_BETWEEN",type:"conditionalDate"};break;case"dateUsLongMax":case"date_us_long_max":case"maxDateUsLong":case"max_date_us_long":n={condition:"<=",dateType:"US_LONG",params:[r],pattern:"^(0[1-9]|1[012])[-/](0[1-9]|[12][0-9]|3[01])[-/](19|20)\\d\\d$",message:"INVALID_DATE_US_LONG_MAX",type:"conditionalDate"};break;case"dateUsLongMin":case"date_us_long_min":case"minDateUsLong":case"min_date_us_long":n={condition:">=",dateType:"US_LONG",params:[r],pattern:"^(0[1-9]|1[012])[-/](0[1-9]|[12][0-9]|3[01])[-/](19|20)\\d\\d$",message:"INVALID_DATE_US_LONG_MIN",type:"conditionalDate"};break;case"dateUsShort":case"date_us_short":n={pattern:"^(0[1-9]|1[012])[-/](0[1-9]|[12][0-9]|3[01])[-/]\\d\\d$",message:"INVALID_DATE_US_SHORT",type:"regex"};break;case"dateUsShortBetween":case"date_us_short_between":case"betweenDateUsShort":case"between_date_us_short":var _=r.split(",");if(2!==_.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_us_short:01/01/90,12/31/15";n={condition:[">=","<="],dateType:"US_SHORT",params:[_[0],_[1]],pattern:"^(0[1-9]|1[012])[-/](0[1-9]|[12][0-9]|3[01])[-/]\\d\\d$",message:"INVALID_DATE_US_SHORT_BETWEEN",type:"conditionalDate"};break;case"dateUsShortMax":case"date_us_short_max":case"maxDateUsShort":case"max_date_us_short":n={condition:"<=",dateType:"US_SHORT",params:[r],pattern:"^(0[1-9]|1[012])[-/](0[1-9]|[12][0-9]|3[01])[-/]\\d\\d$",message:"INVALID_DATE_US_SHORT_MAX",type:"conditionalDate"};break;case"dateUsShortMin":case"date_us_short_min":case"minDateUsShort":case"min_date_us_short":n={condition:">=",dateType:"US_SHORT",params:[r],pattern:"^(0[1-9]|1[012])[-/](0[1-9]|[12][0-9]|3[01])[-/]\\d\\d$",message:"INVALID_DATE_US_SHORT_MIN",type:"conditionalDate"};break;case"email":n={pattern:"^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$",message:"INVALID_EMAIL",type:"regex"};break;case"exactLen":case"exact_len":n={pattern:"^.{"+r+"}$",message:"INVALID_EXACT_LEN",params:[r],type:"regex"};break;case"float":n={pattern:"^\\d*\\.{1}\\d+$",message:"INVALID_FLOAT",type:"regex"};break;case"floatSigned":case"float_signed":n={pattern:"^[-+]?\\d*\\.{1}\\d+$",message:"INVALID_FLOAT_SIGNED",type:"regex"};break;case"iban":n={pattern:"[a-zA-Z]{2}[0-9]{2}[a-zA-Z0-9]{4}[0-9]{7}([a-zA-Z0-9]?){0,16}",message:"INVALID_IBAN",type:"regex"};break;case"int":case"integer":n={pattern:"^\\d+$",message:"INVALID_INTEGER",type:"regex"};break;case"intSigned":case"integerSigned":case"int_signed":case"integer_signed":n={pattern:"^[+-]?\\d+$",message:"INVALID_INTEGER_SIGNED",type:"regex"};break;case"ipv4":n={pattern:"^(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3}$",message:"INVALID_IPV4",type:"regex"};break;case"ipv6":n={pattern:"^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$",message:"INVALID_IPV6",type:"regex"};break;case"ipv6_hex":n={pattern:"^((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)::((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)$",message:"INVALID_IPV6_HEX",type:"regex"};break;case"match":var e=r.split(",");n={message:"INVALID_INPUT_MATCH",params:e,type:"match"};break;case"maxLen":case"max_len":n={pattern:"^.{0,"+r+"}$",message:"INVALID_MAX_CHAR",params:[r],type:"regex"};break;case"maxNum":case"max_num":n={condition:"<=",message:"INVALID_MAX_NUM",params:[r],type:"conditionalNumber"};break;case"minLen":case"min_len":n={pattern:"^.{"+r+",}$",message:"INVALID_MIN_CHAR",params:[r],type:"regex"};break;case"minNum":case"min_num":n={condition:">=",message:"INVALID_MIN_NUM",params:[r],type:"conditionalNumber"};break;case"numeric":n={pattern:"^\\d*\\.?\\d+$",message:"INVALID_NUMERIC",type:"regex"};break;case"numericSigned":case"numeric_signed":n={pattern:"^[-+]?\\d*\\.?\\d+$",message:"INVALID_NUMERIC_SIGNED",type:"regex"};break;case"regex":n={pattern:t.pattern,message:"INVALID_PATTERN",params:[t.message],type:"regex"};break;case"required":n={pattern:"\\S+",message:"INVALID_REQUIRED",type:"regex"};break;case"url":n={pattern:"(http|ftp|https):\\/\\/[\\w\\-_]+(\\.[\\w\\-_]+)+([\\w\\-\\.,@?^=%&:/~\\+#]*[\\w\\-\\@?^=%&/~\\+#])?",message:"INVALID_URL",type:"regex"};break;case"time":n={pattern:"^([01]?[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?$",message:"INVALID_TIME",type:"regex"};break;case"checked":n={pattern:"^true$",message:"INVALID_CHECKBOX_SELECTED",type:"regex"}}return n.altText=a,n}var a={getElementValidators:e};return a}]); angular.module("ghiscoding.validation").service("validationService",["$timeout","validationCommon",function(e,o){function t(e,o){var t=this,i={};if("string"==typeof e&&"string"==typeof o?(i.elmName=e,i.rules=o):i=e,"object"!=typeof i||!i.hasOwnProperty("elmName")||!i.hasOwnProperty("rules")||!i.hasOwnProperty("scope")&&"undefined"==typeof t.validationAttrs.scope)throw"Angular-Validation-Service requires at least the following 3 attributes: {elmName, rules, scope}";return i.elm=angular.element(document.querySelector('[name="'+i.elmName+'"]:not([disabled]):not([ng-disabled]')),"object"!=typeof i.elm||0===i.elm.length?t:(i.elm.bind("blur",function(e){t.commonObj.initialize(i.scope,i.elm,i,i.ctrl),t.commonObj.typingLimit=0,m(t,e.target.value)}),i=c(t.validationAttrs,i),i.scope.$watch(i.elmName,function(e,o){return void 0===e&&void 0!==o?void t.commonObj.updateErrorMsg("INVALID_KEY_CHAR",{valid:!1,translate:!0}):(i.ctrl=angular.element(i.elm).controller("ngModel"),i.value=e,t.commonObj.initialize(i.scope,i.elm,i,i.ctrl),void m(t,e))},!0),t)}function i(e){var o=this;if("undefined"==typeof e||"undefined"==typeof e.$validationSummary)throw"checkFormValidity() requires a valid Angular Form or $scope object passed as argument to function properly (ex.: $scope.form1 OR $scope).";for(var t=[],i=0,n=e.$validationSummary.length;n>i;i++)t.push(e.$validationSummary[i].field);for(i=0,n=t.length;n>i;i++)t[i]&&(o.commonObj.removeFromFormElementObjectList(t[i]),o.commonObj.removeFromValidationSummary(e.$validationSummary,t[i]))}function n(e){var o=this,t="",i=!0;if("undefined"==typeof e||"undefined"==typeof e.$validationSummary)throw"checkFormValidity() requires a valid Angular Form or $scope object passed as argument to function properly (ex.: $scope.form1 OR $scope).";for(var n=0,a=e.$validationSummary.length;a>n;n++)if(i=!1,t=e.$validationSummary[n].field){var r=o.commonObj.getFormElementByName(t);r.elm&&r.elm.length>0&&(r.ctrl.$setTouched(),o.commonObj.updateErrorMsg(e.$validationSummary[n].message,{isSubmitted:!0,isValid:r.isValid,obj:r}))}return i}function a(e,o){var t=this;if("undefined"==typeof e||"undefined"==typeof e.$validationSummary)throw"checkFormValidity() requires a valid Angular Form or $scope object passed as argument to function properly (ex.: $scope.form1 OR $scope).";var i;if(o instanceof Array)for(var n=0,a=o.length;a>n;n++)i=t.commonObj.getFormElementByName(o[n]),d(t,i,e.$validationSummary);else i=t.commonObj.getFormElementByName(o),d(t,i,e.$validationSummary)}function r(e){var o=this;return o.validationAttrs=e,o}function m(o,t){return o.commonObj.validate(t,!1),o.commonObj.isFieldRequired()||""!==t&&null!==t&&"undefined"!=typeof t?((o.commonObj.isFieldRequired()||t)&&o.commonObj.ctrl.$setValidity("validation",!1),"SELECT"===o.commonObj.elm.prop("tagName").toUpperCase()?(o.commonObj.ctrl.$setValidity("validation",o.commonObj.validate(t,!0)),t):("undefined"!=typeof t&&(o.commonObj.updateErrorMsg(""),e.cancel(o.timer),o.timer=e(function(){o.commonObj.scope.$evalAsync(o.commonObj.ctrl.$setValidity("validation",o.commonObj.validate(t,!0)))},o.commonObj.typingLimit)),t)):(l(o),t)}function l(o){e.cancel(self.timer),o.commonObj.updateErrorMsg(""),o.commonObj.ctrl.$setValidity("validation",!0),o.commonObj.elm.unbind("blur")}function c(e,o){var t={};for(var i in e)t[i]=e[i];for(var i in o)t[i]=o[i];return t}function d(e,o,t){if("undefined"!=typeof e.commonObj.scope){var i=e.commonObj.scope.$watch(o.fieldName,function(){});i(),o.elm.unbind(),o.ctrl.$setUntouched(),o.ctrl.$setPristine(),o.ctrl.$setValidity("validation",!0),e.commonObj.removeFromValidationSummary(t,o.fieldName),e.commonObj.updateErrorMsg("",{isValid:!0,obj:o})}}var s=function(){this.validationAttrs={},this.commonObj=new o};return s.prototype.addValidator=t,s.prototype.checkFormValidity=n,s.prototype.removeValidator=a,s.prototype.setGlobalOptions=r,s.prototype.clearInvalidValidatorsInSummary=i,s}]); \ No newline at end of file diff --git a/package.json b/package.json index 475ae1e..2cfe047 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ghiscoding.angular-validation", - "version": "1.3.15", + "version": "1.3.16", "author": "Ghislain B.", "description": "Angular-Validation Directive and Service (ghiscoding)", "main": "app.js", diff --git a/readme.md b/readme.md index 2f70b66..7f5f6a7 100644 --- a/readme.md +++ b/readme.md @@ -1,5 +1,5 @@ #Angular Validation (Directive / Service) -`Version: 1.3.15` +`Version: 1.3.16` ### Form validation after user inactivity of default 1sec. (customizable timeout) Forms Validation with Angular made easy! Angular-Validation is an angular directive/service with locales (languages) with a very simple approach of defining your `validation=""` directly within your element to validate (input, textarea, etc) and...that's it!!! The directive/service will take care of the rest! @@ -460,4 +460,5 @@ License * [1.3.12](https://github.com/ghiscoding/angular-validation/commit/0af82337a6961923e3b022a19660237d3e6f7184) `2015-04-04` Fix issue #16 and added Validators Alternate Text option on all type of validators. Also fixed removeValidator and clean a lot of code. * [1.3.13](https://github.com/ghiscoding/angular-validation/commit/d0440bdd7fc2816e03d28ad3a9c3bd7bee8ac519) `2015-04-06` Fixed $translate delay issue when using external JSON files * [1.3.14](https://github.com/ghiscoding/angular-validation/pull/19) `2015-04-07` Merge pull request #19 Added norwegian translation and changes to allow user to remove invalid validators -* [1.3.15](https://github.com/ghiscoding/angular-validation/commit/24037e4b2e22658e7e2011c022ba4cca26f391d9) `2015-04-08` Fixed #23 If multiple forms exist in the app the errors in 1 form affect validation in the other \ No newline at end of file +* [1.3.15](https://github.com/ghiscoding/angular-validation/commit/24037e4b2e22658e7e2011c022ba4cca26f391d9) `2015-04-08` Fixed #23 If multiple forms exist in the app the errors in 1 form affect validation in the other +* [1.3.16]() `2015-04-09` Accept Merge #3 Fixed removeFromValidationSummary to also remove from 'local' array \ No newline at end of file diff --git a/src/validation-common.js b/src/validation-common.js index ee34c5a..22d87d1 100644 --- a/src/validation-common.js +++ b/src/validation-common.js @@ -167,7 +167,7 @@ angular * @param object validationSummary * @param string elmName: element name */ - function removeFromValidationSummary(validationSummaryObj, elmName) { + function removeFromValidationSummary(validationSummaryObj, elmName) { var index = arrayFindObjectIndex(validationSummaryObj, 'field', elmName); // find index of object in our array // if message is empty, remove it from the validation summary object if(index >= 0) {