From d2ad88e41416a0a9f4c43c19967ffebe43a8ded7 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Tue, 3 May 2016 00:48:56 +0900 Subject: [PATCH] release(patch): v2.1.1 --- CHANGELOG.md | 8 ++++++++ dist/vue-validator.common.js | 15 +++++++-------- dist/vue-validator.js | 15 +++++++-------- dist/vue-validator.min.js | 6 +++--- docs/en/installation.md | 2 +- package.json | 2 +- src/index.js | 2 +- 7 files changed, 28 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab2d1a4..1b66903 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ + +## [2.1.1](https://github.com/vuejs/vue-validator/compare/v2.1.0...v2.1.1) (2016-05-02) + +### :star: Bug Fixes + +* **timing:** fix the initiali timing when use v-model integration ([0579685](https://github.com/vuejs/vue-validator/commit/0579685)), closes [#214](https://github.com/vuejs/vue-validator/issues/214) + + # [2.1.0](https://github.com/vuejs/vue-validator/compare/v2.0.2...v2.1.0) (2016-04-30) diff --git a/dist/vue-validator.common.js b/dist/vue-validator.common.js index 20ecc22..fdbf214 100644 --- a/dist/vue-validator.common.js +++ b/dist/vue-validator.common.js @@ -1,5 +1,5 @@ /*! - * vue-validator v2.1.0 + * vue-validator v2.1.1 * (c) 2016 kazuya kawaguchi * Released under the MIT License. */ @@ -429,6 +429,7 @@ var PRIORITY_VALIDATE = 16; var PRIORITY_VALIDATE_CLASS = 32; var REGEX_FILTER = /[^|]\|[^|]/; var REGEX_VALIDATE_DIRECTIVE = /^v-validate(?:$|:(.*)$)/; +var REGEX_EVENT = /^v-on:|^@/; var classId = 0; // ID for validation class @@ -833,7 +834,7 @@ var BaseValidation = function () { return; } - _this.handleValidate(el, _this._initial); + _this.handleValidate(el, { noopable: _this._initial }); if (_this._initial) { _this._initial = null; } @@ -1742,7 +1743,7 @@ var SelectValidation = function (_BaseValidation) { return; } - _this2.handleValidate(el, _this2._initial); + _this2.handleValidate(el, { noopable: _this2._initial }); if (_this2._initial) { _this2._initial = null; } @@ -1797,8 +1798,6 @@ var SelectValidation = function (_BaseValidation) { return SelectValidation; }(BaseValidation); -var eventRE = /^v-on:|^@/; - /** * Validator class */ @@ -1857,8 +1856,8 @@ var Validator$1 = function () { var attrs = this._dir.el.attributes; for (var i = 0, l = attrs.length; i < l; i++) { var event = attrs[i].name; - if (eventRE.test(event)) { - event = event.replace(eventRE, ''); + if (REGEX_EVENT.test(event)) { + event = event.replace(REGEX_EVENT, ''); this._events[this._getEventName(event)] = this._dir.vm.$eval(attrs[i].value, true); } } @@ -2588,7 +2587,7 @@ function plugin(Vue) { Validate(Vue); } -plugin.version = '2.1.0'; +plugin.version = '2.1.1'; if (typeof window !== 'undefined' && window.Vue) { window.Vue.use(plugin); diff --git a/dist/vue-validator.js b/dist/vue-validator.js index 434d42f..e4e85a0 100644 --- a/dist/vue-validator.js +++ b/dist/vue-validator.js @@ -1,5 +1,5 @@ /*! - * vue-validator v2.1.0 + * vue-validator v2.1.1 * (c) 2016 kazuya kawaguchi * Released under the MIT License. */ @@ -433,6 +433,7 @@ var validators = Object.freeze({ var PRIORITY_VALIDATE_CLASS = 32; var REGEX_FILTER = /[^|]\|[^|]/; var REGEX_VALIDATE_DIRECTIVE = /^v-validate(?:$|:(.*)$)/; + var REGEX_EVENT = /^v-on:|^@/; var classId = 0; // ID for validation class @@ -837,7 +838,7 @@ var validators = Object.freeze({ return; } - _this.handleValidate(el, _this._initial); + _this.handleValidate(el, { noopable: _this._initial }); if (_this._initial) { _this._initial = null; } @@ -1746,7 +1747,7 @@ var validators = Object.freeze({ return; } - _this2.handleValidate(el, _this2._initial); + _this2.handleValidate(el, { noopable: _this2._initial }); if (_this2._initial) { _this2._initial = null; } @@ -1801,8 +1802,6 @@ var validators = Object.freeze({ return SelectValidation; }(BaseValidation); - var eventRE = /^v-on:|^@/; - /** * Validator class */ @@ -1861,8 +1860,8 @@ var validators = Object.freeze({ var attrs = this._dir.el.attributes; for (var i = 0, l = attrs.length; i < l; i++) { var event = attrs[i].name; - if (eventRE.test(event)) { - event = event.replace(eventRE, ''); + if (REGEX_EVENT.test(event)) { + event = event.replace(REGEX_EVENT, ''); this._events[this._getEventName(event)] = this._dir.vm.$eval(attrs[i].value, true); } } @@ -2592,7 +2591,7 @@ var validators = Object.freeze({ Validate(Vue); } - plugin.version = '2.1.0'; + plugin.version = '2.1.1'; if (typeof window !== 'undefined' && window.Vue) { window.Vue.use(plugin); diff --git a/dist/vue-validator.min.js b/dist/vue-validator.min.js index 62188a4..38ee962 100644 --- a/dist/vue-validator.min.js +++ b/dist/vue-validator.min.js @@ -1,7 +1,7 @@ /*! - * vue-validator v2.1.0 + * vue-validator v2.1.1 * (c) 2016 kazuya kawaguchi * Released under the MIT License. */ -!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define(i):t.VueValidator=i()}(this,function(){"use strict";function t(t,i){window.console&&(console.warn("[vue-validator] "+t),i&&console.warn(i.stack))}function i(t){if(null===t||void 0===t)return!0;if(Array.isArray(t)){if(t.length>0)return!1;if(0===t.length)return!0}else if(w.Vue.util.isPlainObject(t))for(var i in t)if(w.Vue.util.hasOwn(t,i))return!1;return!0}function e(t,i,e){if(Array.isArray(t))for(var n=0;na;a++)e(t,n[a])}function r(t){if(Array.isArray(t)){if(0!==t.length){for(var i=!0,e=0,n=t.length;n>e&&(i=r(t[e]),i);e++);return i}return!1}return"number"==typeof t||"function"==typeof t?!0:"boolean"==typeof t?t:"string"==typeof t?t.length>0:null!==t&&"object"===("undefined"==typeof t?"undefined":C["typeof"](t))?Object.keys(t).length>0:null===t||void 0===t?!1:void 0}function l(t,i){if("string"!=typeof i)return!1;var e=i.match(new RegExp("^/(.*?)/([gimy]*)$"));return e?new RegExp(e[1],e[2]).test(t):!1}function d(t,i){return"string"==typeof t?f(i,10)&&t.length>=parseInt(i,10):Array.isArray(t)?t.length>=parseInt(i,10):!1}function u(t,i){return"string"==typeof t?f(i,10)&&t.length<=parseInt(i,10):Array.isArray(t)?t.length<=parseInt(i,10):!1}function h(t,i){return!isNaN(+t)&&!isNaN(+i)&&+t>=+i}function c(t,i){return!isNaN(+t)&&!isNaN(+i)&&+i>=+t}function f(t){return/^(-?[1-9]\d*|0)$/.test(t)}function p(t){var i=t.util.extend,e=Object.create(null);i(e,k),t.options.validators=e;var n=t.config.optionMergeStrategies;n&&(n.validators=function(t,e){if(!e)return t;if(!t)return e;var n=Object.create(null);i(n,t);for(var a in e)n[a]=e[a];return n}),t.validator=function(i,e){return e?void(t.options.validators[i]=e):t.options.validators[i]}}function v(t){var i=t.prototype._init;t.prototype._init=function(t){this._validatorMaps||(this._validatorMaps=Object.create(null)),i.call(this,t)};var e=t.prototype._destroy;t.prototype._destroy=function(){e.apply(this,arguments),this._validatorMaps=null}}function _(t){var i=t.directive("if"),e=t.FragmentFactory,n=t.util,a=n.toArray,o=n.replace,s=n.createAnchor;t.directive("validate-class",{terminal:!0,priority:i.priority+N,bind:function(){var t=this,i=String(I++);this.setClassIds(this.el,i),this.vm.$on(E,this.cb=function(e,n,a){e.indexOf(i)>-1&&n.updateClasses(a,t.frag.node)}),this.setupFragment()},unbind:function(){this.vm.$off(E,this.cb),this.teardownFragment()},setClassIds:function(t,i){for(var e=a(t.childNodes),n=0,o=e.length;o>n;n++){var s=e[n];if(1===s.nodeType)for(var r=s.hasAttributes(),l=r&&a(s.attributes),d=0,u=l.length;u>d;d++){var h=l[d];if(h.name.match(x)){var c=s.getAttribute(E),f=c?c+","+i:i;s.setAttribute(E,f)}}s.hasChildNodes()&&this.setClassIds(s,i)}},setupFragment:function(){this.anchor=s("v-validate-class"),o(this.el,this.anchor),this.factory=new e(this.vm,this.el),this.frag=this.factory.create(this._host,this._scope,this._frag),this.frag.before(this.anchor)},teardownFragment:function(){this.frag&&(this.frag.remove(),this.frag=null,this.factory=null),o(this.anchor,this.el),this.anchor=null}})}function g(t){function i(){if(r){var t=document.createElement("textarea");return t.placeholder="t","t"===t.cloneNode(!0).value}return!1}var n=t.directive("if"),a=t.FragmentFactory,o=t.parsers.directive.parseDirective,s=t.util,r=s.inBrowser,l=s.bind,d=s.on,u=s.off,h=s.createAnchor,c=s.replace,f=s.camelize,p=s.isPlainObject,v=i();t.directive("validate",{terminal:!0,priority:n.priority+A,params:["group","field","detect-blur","detect-change","initial","classes"],paramWatchers:{detectBlur:function(t,i){this._invalid||(this.validation.detectBlur=this.isDetectBlur(t),this.validator.validate(this.field))},detectChange:function(t,i){this._invalid||(this.validation.detectChange=this.isDetectChange(t),this.validator.validate(this.field))}},bind:function(){var t=this.el,i=this.vm.$options._validator,e=t.getAttribute("v-model"),n=this.parseModelRaw(e),a=n.model,o=n.filters;this.model=a,this.setupFragment(),this.setupValidate(i,a,o),this.listen()},update:function(t,i){if(t&&!this._invalid){p(t)?this.handleObject(t):Array.isArray(t)&&this.handleArray(t);var e={field:this.field,noopable:this._initialNoopValidation};this.frag&&(e.el=this.frag.node),this.validator.validate(e),this._initialNoopValidation&&(this._initialNoopValidation=null)}},unbind:function(){this._invalid||(this.unlisten(),this.teardownValidate(),this.teardownFragment(),this.model=null)},parseModelRaw:function(t){if(S.test(t)){var i=o(t);return{model:i.expression,filters:i.filters}}return{model:t}},setupValidate:function(t,i,e){var n=this.params,a=this.validator=this.vm._validatorMaps[t];this.field=f(this.arg?this.arg:n.field),this.validation=a.manageValidation(this.field,i,this.vm,this.frag.node,this._scope,e,n.initial,this.isDetectBlur(n.detectBlur),this.isDetectChange(n.detectChange)),p(n.classes)&&this.validation.setValidationClasses(n.classes),n.group&&a.addGroupValidation(n.group,this.field),this._initialNoopValidation=this.isInitialNoopValidation(n.initial)},listen:function(){var t=this.model,i=this.validation,e=this.frag.node;this.onBlur=l(i.listener,i),d(e,"blur",this.onBlur),"radio"!==e.type&&"SELECT"!==e.tagName||t?"checkbox"===e.type?t?(this.onClick=l(i.listener,i),d(e,"click",this.onClick)):(this.onChange=l(i.listener,i),d(e,"change",this.onChange)):t||(this.onInput=l(i.listener,i),d(e,"input",this.onInput)):(this.onChange=l(i.listener,i),d(e,"change",this.onChange))},unlisten:function(){var t=this.frag.node;this.onInput&&(u(t,"input",this.onInput),this.onInput=null),this.onClick&&(u(t,"click",this.onClick),this.onClick=null),this.onChange&&(u(t,"change",this.onChange),this.onChange=null),this.onBlur&&(u(t,"blur",this.onBlur),this.onBlur=null)},teardownValidate:function(){if(this.validator&&this.validation){var t=this.frag.node;this.params.group&&this.validator.removeGroupValidation(this.params.group,this.field),this.validator.unmanageValidation(this.field,t),this.validator=null,this.validation=null,this.field=null}},setupFragment:function(){this.anchor=h("v-validate"),c(this.el,this.anchor),this.factory=new a(this.vm,this.shimNode(this.el)),this.frag=this.factory.create(this._host,this._scope,this._frag),this.frag.before(this.anchor)},teardownFragment:function(){this.frag&&(this.frag.remove(),this.frag=null,this.factory=null),c(this.anchor,this.el),this.anchor=null},handleArray:function(t){var i=this;e(t,function(t){i.validation.setValidation(t)})},handleObject:function(t){var i=this;e(t,function(t,e){if(p(t)){if("rule"in t){var n="message"in t?t.message:null,a="initial"in t?t.initial:null;i.validation.setValidation(e,t.rule,n,a)}}else i.validation.setValidation(e,t)})},isDetectBlur:function(t){return void 0===t||"on"===t||t===!0},isDetectChange:function(t){return void 0===t||"on"===t||t===!0},isInitialNoopValidation:function(t){return"off"===t||t===!1},shimNode:function(t){var i=t;if(v&&"TEXTAREA"===t.tagName){i=t.cloneNode(!0),i.value=t.value;for(var e=i.childNodes.length;e--;)i.removeChild(i.childNodes[e])}return i}})}function m(t){var i=t.FragmentFactory,e=t.directive("if"),n=t.util,a=n.isArray,o=n.isPlainObject,s=n.createAnchor,r=n.replace,l=n.extend,d=n.camelize;t.elementDirective("validator",{params:["name","groups","lazy","classes"],bind:function(){var t=this.params;if(this.validatorName="$"+d(t.name),!this.vm._validatorMaps)throw new Error("Invalid validator management error");var i={};o(this.params.classes)&&(i=this.params.classes),this.setupValidator(i),this.setupFragment(t.lazy)},unbind:function(){this.teardownFragment(),this.teardownValidator()},getGroups:function(){var t=this.params,i=[];return t.groups&&(a(t.groups)?i=t.groups:o(t.groups)||"string"!=typeof t.groups||i.push(t.groups)),i},setupValidator:function(t){var i=this.validator=new U(this.validatorName,this,this.getGroups(),t);i.enableReactive(),i.setupScope(),i.registerEvents()},teardownValidator:function(){this.validator.unregisterEvents(),this.validator.disableReactive(),this.validatorName&&(this.validatorName=null,this.validator=null)},setupFragment:function(t){var n=this,a=this.vm;this.validator.waitFor(function(){n.anchor=s("vue-validator"),r(n.el,n.anchor),l(a.$options,{_validator:n.validatorName}),n.factory=new i(a,n.el.innerHTML),e.insert.call(n)}),!t&&a.$activateValidator()},teardownFragment:function(){e.unbind.call(this)}})}function y(t){var i={name:"validator-error",props:{field:{type:String,required:!0},validator:{type:String},message:{type:String,required:!0},partial:{type:String,"default":"validator-error-default"}},template:'
',partials:{}};return i.partials["validator-error-default"]="

{{field}}: {{message}}

",i}function V(t){var i=t.util,e=y(t),n={name:"validator-errors",props:{validation:{type:Object,required:!0},group:{type:String,"default":null},field:{type:String,"default":null},component:{type:String,"default":"validator-error"}},computed:{errors:function(){var t=this;if(null!==this.group)return this.validation[this.group].errors;if(null!==this.field){var e=this.validation[this.field];if(!e.errors)return;return e.errors.map(function(e){var n={field:t.field};return i.isPlainObject(e)?(e.validator&&(n.validator=e.validator),n.message=e.message):"string"==typeof e&&(n.message=e),n})}return this.validation.errors}},template:'',components:{}};return n.props.partial=e.props.partial,n.components[e.name]=e,t.component(n.name,n),n}function b(i){arguments.length<=1||void 0===arguments[1]?{}:arguments[1];return b.installed?void t("already installed."):(w.Vue=i,p(i),V(i),v(i),m(i),_(i),void g(i))}var C={};C["typeof"]="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},C.classCallCheck=function(t,i){if(!(t instanceof i))throw new TypeError("Cannot call a class as a function")},C.createClass=function(){function t(t,i){for(var e=0;eh;h++)if(s=e[h],r=a(this._vm.$options,"filters",s.name),r&&(r=n?r.write:r.read||r,"function"==typeof r)){if(l=n?[t,i]:[t],u=n?2:1,s.args)for(f=0,p=s.args.length;p>f;f++)d=s.args[f],l[f+u]=d.dynamic?o.$get(d.value):d.value;t=r.apply(this._vm,l)}return t},t.prototype._runValidators=function(t,i){var n=this._validators,a=Object.keys(n).length,o=0;e(n,function(e,n){t(e,n,function(){++o,o>=a&&i()})})},t.prototype._invokeValidator=function(t,i,e,n,a){var s=i.call(this,e,n);"function"==typeof s?s.resolved?a(s.resolved):s.requested?s.pendingCallbacks.push(a):!function(){s.requested=!0;var t=s.pendingCallbacks=[a];s(function(){s.resolved=!0;for(var i=0,e=t.length;e>i;i++)t[i](!0)},function(t){a(!1,t)})}():o(s)?s.then(function(){a(!0)},function(t){a(!1,t)})["catch"](function(t){a(!1,t.message)}):a(s)},t.prototype._resolveValidator=function(t){var i=w.Vue.util.resolveAsset;return i(this._vm.$options,"validators",t)},C.createClass(t,[{key:"vm",get:function(){return this._vm}},{key:"el",get:function(){return this._el}},{key:"detectChange",get:function(){return this._detectChange},set:function(t){this._detectChange=t}},{key:"detectBlur",get:function(){return this._detectBlur},set:function(t){this._detectBlur=t}}]),t}(),O=function(t){function i(e,n,a,o,s,r,l,d,u){C.classCallCheck(this,i);var h=C.possibleConstructorReturn(this,t.call(this,e,n,a,o,s,r,l,d,u));return h._inits=[],h}return C.inherits(i,t),i.prototype.manageElement=function(t,i){var e=this,n=this._getScope(),a=this._addItem(t,i),o=a.model=this._model;if(o){var s=this._evalModel(o,this._filters);Array.isArray(s)?(this._setChecked(s,a.el),a.unwatch=n.$watch(o,function(t,i){if(t!==i){if(e.guardValidate(a.el,"change"))return;e.handleValidate(a.el,{noopable:a.initial}),a.initial&&(a.initial=null)}})):(t.checked=s||!1,this._init=t.checked,a.init=t.checked,a.value=t.value,a.unwatch=n.$watch(o,function(i,n){if(i!==n){if(e.guardValidate(t,"change"))return;e.handleValidate(t,{noopable:a.initial}),a.initial&&(a.initial=null)}}))}else{var r={field:this.field,noopable:i};this._checkClassIds(t)&&(r.el=t),this._validator.validate(r)}},i.prototype.unmanageElement=function(t){var i=-1;e(this._inits,function(e,n){e.el===t&&(i=n,e.unwatch&&e.model&&(e.unwatch(),e.unwatch=null,e.model=null))}),-1!==i&&(this._inits.splice(i,1),this._validator.validate({field:this.field}))},i.prototype.willUpdateFlags=function(){var t=this,i=arguments.length<=0||void 0===arguments[0]?!1:arguments[0];e(this._inits,function(e,n){i&&t.willUpdateTouched(e.el,"blur"),t.willUpdateDirty(e.el),t.willUpdateModified(e.el)})},i.prototype.reset=function(){this.resetFlags(),e(this._inits,function(t,i){t.init=t.el.checked,t.value=t.el.value})},i.prototype.updateClasses=function(t){var i=this,n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];n?this._updateClasses(n,t):e(this._inits,function(e,n){i._updateClasses(e.el,t)})},i.prototype._addItem=function(t,i){var e={el:t,init:t.checked,value:t.value,initial:i},n=t.getAttribute(E);return n&&(t.removeAttribute(E),e.classIds=n.split(",")),this._inits.push(e),e},i.prototype._setChecked=function(t,i){for(var e=0,n=t.length;n>e;e++){var a=t[e];i.disabled||i.value!==a||i.checked||(i.checked=!0)}},i.prototype._getValue=function(t){var i=this;if(!this._inits||0===this._inits.length)return t.checked;var n=function(){var t=[];return e(i._inits,function(i,e){i.el.checked&&t.push(i.el.value)}),{v:t}}();return"object"===("undefined"==typeof n?"undefined":C["typeof"](n))?n.v:void 0},i.prototype._getClassIds=function(t){var i=void 0;return e(this._inits,function(e,n){e.el===t&&(i=e.classIds)}),i},i.prototype._checkModified=function(t){var i=this;if(0===this._inits.length)return this._init!==t.checked;var n=function(){var t=!1;return e(i._inits,function(i,e){t||(t=i.init!==i.el.checked)}),{v:t}}();return"object"===("undefined"==typeof n?"undefined":C["typeof"](n))?n.v:void 0},i}(F),M=function(t){function i(e,n,a,o,s,r,l,d,u){C.classCallCheck(this,i);var h=C.possibleConstructorReturn(this,t.call(this,e,n,a,o,s,r,l,d,u));return h._inits=[],h}return C.inherits(i,t),i.prototype.manageElement=function(t,i){var e=this,n=this._getScope(),a=this._addItem(t,i),o=a.model=this._model;if(o){var s=this._evalModel(o,this._filters);this._setChecked(s,t,a),a.unwatch=n.$watch(o,function(i,n){if(i!==n){if(e.guardValidate(a.el,"change"))return;e.handleValidate(t,{noopable:a.initial}),a.initial&&(a.initial=null)}})}else{var r={field:this.field,noopable:i};this._checkClassIds(t)&&(r.el=t),this._validator.validate(r)}},i.prototype.unmanageElement=function(t){var i=-1;e(this._inits,function(e,n){e.el===t&&(i=n)}),-1!==i&&(this._inits.splice(i,1),this._validator.validate({field:this.field}))},i.prototype.willUpdateFlags=function(){var t=this,i=arguments.length<=0||void 0===arguments[0]?!1:arguments[0];e(this._inits,function(e,n){i&&t.willUpdateTouched(e.el,"blur"),t.willUpdateDirty(e.el),t.willUpdateModified(e.el)})},i.prototype.reset=function(){this.resetFlags(),e(this._inits,function(t,i){t.init=t.el.checked,t.value=t.el.value})},i.prototype.updateClasses=function(t){var i=this,n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];n?this._updateClasses(n,t):e(this._inits,function(e,n){i._updateClasses(e.el,t)})},i.prototype._addItem=function(t,i){var e={el:t,init:t.checked,value:t.value,initial:i},n=t.getAttribute(E);return n&&(t.removeAttribute(E),e.classIds=n.split(",")),this._inits.push(e),e},i.prototype._setChecked=function(t,i,e){i.value===t&&(i.checked=!0,this._init=i.checked,e.init=i.checked,e.value=t)},i.prototype._getValue=function(t){var i=this;if(!this._inits||0===this._inits.length)return t.checked;var n=function(){var t=[];return e(i._inits,function(i,e){i.el.checked&&t.push(i.el.value)}),{v:t}}();return"object"===("undefined"==typeof n?"undefined":C["typeof"](n))?n.v:void 0},i.prototype._getClassIds=function(t){var i=void 0;return e(this._inits,function(e,n){e.el===t&&(i=e.classIds)}),i},i.prototype._checkModified=function(t){var i=this;if(0===this._inits.length)return this._init!==t.checked;var n=function(){var t=!1;return e(i._inits,function(i,e){t||(t=i.init!==i.el.checked)}),{v:t}}();return"object"===("undefined"==typeof n?"undefined":C["typeof"](n))?n.v:void 0},i}(F),$=function(t){function i(e,n,a,o,s,r,l,d,u){C.classCallCheck(this,i);var h=C.possibleConstructorReturn(this,t.call(this,e,n,a,o,s,r,l,d,u));return h._multiple=h._el.hasAttribute("multiple"),h}return C.inherits(i,t),i.prototype.manageElement=function(t,i){var e=this,n=this._getScope(),a=this._model;this._initial=i;var o=t.getAttribute(E);if(o&&(t.removeAttribute(E),this._classIds=o.split(",")),a){var s=this._evalModel(a,this._filters),r=Array.isArray(s)?s:[s];this._setOption(r,t),this._unwatch=n.$watch(a,function(i,n){var a=Array.isArray(i)?i:[i],o=Array.isArray(n)?n:[n];if(a.slice().sort().toString()!==o.slice().sort().toString()){if(e.guardValidate(t,"change"))return;e.handleValidate(t,e._initial),e._initial&&(e._initial=null)}})}},i.prototype.unmanageElement=function(t){this._unwatch&&this._unwatch()},i.prototype.reset=function(){this.resetFlags()},i.prototype._getValue=function(t){for(var i=[],e=0,n=t.options.length;n>e;e++){var a=t.options[e];!a.disabled&&a.selected&&i.push(a.value)}return i},i.prototype._setOption=function(t,i){for(var e=0,n=t.length;n>e;e++)for(var a=t[e],o=0,s=i.options.length;s>o;o++){var r=i.options[o];r.disabled||r.value!==a||r.hasAttribute("selected")&&r.selected||(r.selected=!0)}},i.prototype._checkModified=function(t){var i=this._getValue(t).slice().sort();if(this._init.length!==i.length)return!0;var e=this._init.slice().sort();return e.toString()!==i.toString()},i}(F),j=/^v-on:|^@/,U=function(){function t(i,n,a,o){var s=this;C.classCallCheck(this,t),this.name=i,this._scope={},this._dir=n,this._validations={},this._checkboxValidations={},this._radioValidations={},this._groups=a,this._groupValidations={},this._events={},this._modified=!1,this._classes=o,e(a,function(t){s._groupValidations[t]=[]})}return t.prototype.enableReactive=function(){var t=this._dir.vm;w.Vue.util.defineReactive(t,this.name,this._scope),t._validatorMaps[this.name]=this,this._defineResetValidation(),this._defineValidate(),this._defineSetValidationErrors()},t.prototype.disableReactive=function(){var t=this._dir.vm;t.$setValidationErrors=void 0,t.$validate=void 0,t.$validatorReset=void 0,t._validatorMaps[this.name]=null,t[this.name]=null},t.prototype.registerEvents=function(){for(var t=this._dir.el.attributes,i=0,e=t.length;e>i;i++){var n=t[i].name;j.test(n)&&(n=n.replace(j,""),this._events[this._getEventName(n)]=this._dir.vm.$eval(t[i].value,!0))}},t.prototype.unregisterEvents=function(){var t=this;e(this._events,function(i,e){t._events[e]=null,delete t._events[e]})},t.prototype.manageValidation=function(t,i,e,n,a,o,s,r,l){var d=null;return d="SELECT"===n.tagName?this._manageSelectValidation(t,i,e,n,a,o,s,r,l):"checkbox"===n.type?this._manageCheckboxValidation(t,i,e,n,a,o,s,r,l):"radio"===n.type?this._manageRadioValidation(t,i,e,n,a,o,s,r,l):this._manageBaseValidation(t,i,e,n,a,o,s,r,l),d.setValidationClasses(this._classes),d},t.prototype.unmanageValidation=function(t,i){"checkbox"===i.type?this._unmanageCheckboxValidation(t,i):"radio"===i.type?this._unmanageRadioValidation(t,i):"SELECT"===i.tagName?this._unmanageSelectValidation(t,i):this._unmanageBaseValidation(t,i)},t.prototype.addGroupValidation=function(t,i){var e=w.Vue.util.indexOf,n=this._validations[i]||this._checkboxValidations[i].validation||this._radioValidations[i].validation,a=this._groupValidations[t];a&&!~e(a,n)&&a.push(n)},t.prototype.removeGroupValidation=function(t,i){var e=this._validations[i]||this._checkboxValidations[i].validation||this._radioValidations[i].validation,a=this._groupValidations[t];a&&n(a,e)},t.prototype.validate=function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],i=t.el,n=void 0===i?null:i,a=t.field,o=void 0===a?null:a,s=t.touched,r=void 0===s?!1:s,l=t.noopable,d=void 0===l?!1:l,u=t.cb,h=void 0===u?null:u;o?this._validate(o,r,d,n,h):(e(this.validations,function(t,i){t.willUpdateFlags(r)}),this._validates(h))},t.prototype.setupScope=function(){var t=this;this._defineProperties(function(){return t.validations},function(){return t._scope}),e(this._groups,function(i){var e=t._groupValidations[i],n={};w.Vue.set(t._scope,i,n),t._defineProperties(function(){return e},function(){return n})})},t.prototype.waitFor=function(t){var i="$activateValidator",e=this._dir.vm;e[i]=function(){t(),e[i]=null}},t.prototype._defineResetValidation=function(){var t=this;this._dir.vm.$resetValidation=function(i){t._resetValidation(i)}},t.prototype._defineValidate=function(){var t=this;this._dir.vm.$validate=function(){for(var i=arguments.length,n=Array(i),a=0;i>a;a++)n[a]=arguments[a];var o=null,s=!1,r=null;e(n,function(t,i){"string"==typeof t?o=t:"boolean"==typeof t?s=t:"function"==typeof t&&(r=t)}),t.validate({field:o,touched:s,cb:r})}},t.prototype._defineSetValidationErrors=function(){var t=this;this._dir.vm.$setValidationErrors=function(i){t._setValidationErrors(i)}},t.prototype._validate=function(t){var i=arguments.length<=1||void 0===arguments[1]?!1:arguments[1],e=arguments.length<=2||void 0===arguments[2]?!1:arguments[2],n=this,a=arguments.length<=3||void 0===arguments[3]?null:arguments[3],o=arguments.length<=4||void 0===arguments[4]?null:arguments[4],s=this._scope,r=this._getValidationFrom(t);r&&(r.willUpdateFlags(i),r.validate(function(i){w.Vue.set(s,t,i),n._fireEvents(),o&&o()},e,a))},t.prototype._validates=function(t){var i=this,e=this._scope;this._runValidates(function(t,i,n){t.validate(function(t){w.Vue.set(e,i,t),n()})},function(){i._fireEvents(),t&&t()})},t.prototype._getValidationFrom=function(t){var i=this._validations[t];return!i&&this._checkboxValidations[t]?i=this._checkboxValidations[t].validation:!i&&this._radioValidations[t]&&(i=this._radioValidations[t].validation),i},t.prototype._resetValidation=function(t){e(this.validations,function(t,i){t.reset()}),this._validates(t)},t.prototype._setValidationErrors=function(t){var i=this,n=w.Vue.util.extend,a={};e(t,function(t,i){a[t.field]||(a[t.field]=[]),a[t.field].push(t)}),e(a,function(t,a){var o=i._scope[a],s={};e(t,function(t){t.validator&&(o[t.validator]=t.message)}),o.valid=!1,o.invalid=!0,o.errors=t,n(s,o),w.Vue.set(i._scope,a,s)})},t.prototype._manageBaseValidation=function(t,i,e,n,a,o,s,r,l){var d=this._validations[t]=new F(t,i,e,n,a,this,o,r,l);return d.manageElement(n,s),d},t.prototype._unmanageBaseValidation=function(t,i){var e=this._validations[t];e&&(e.unmanageElement(i),w.Vue["delete"](this._scope,t),this._validations[t]=null,delete this._validations[t])},t.prototype._manageCheckboxValidation=function(t,i,e,n,a,o,s,r,l){var d=this._checkboxValidations[t];if(!d){var u=new O(t,i,e,n,a,this,o,r,l);d={validation:u,elements:0},this._checkboxValidations[t]=d}return d.elements++,d.validation.manageElement(n,s),d.validation},t.prototype._unmanageCheckboxValidation=function(t,i){var e=this._checkboxValidations[t];e&&(e.elements--,e.validation.unmanageElement(i),0===e.elements&&(w.Vue["delete"](this._scope,t),this._checkboxValidations[t]=null,delete this._checkboxValidations[t]))},t.prototype._manageRadioValidation=function(t,i,e,n,a,o,s,r,l){var d=this._radioValidations[t];if(!d){var u=new M(t,i,e,n,a,this,o,r,l);d={validation:u,elements:0},this._radioValidations[t]=d}return d.elements++,d.validation.manageElement(n,s),d.validation},t.prototype._unmanageRadioValidation=function(t,i){var e=this._radioValidations[t];e&&(e.elements--,e.validation.unmanageElement(i),0===e.elements&&(w.Vue["delete"](this._scope,t),this._radioValidations[t]=null,delete this._radioValidations[t]))},t.prototype._manageSelectValidation=function(t,i,e,n,a,o,s,r,l){var d=this._validations[t]=new $(t,i,e,n,a,this,o,r,l);return d.manageElement(n,s),d},t.prototype._unmanageSelectValidation=function(t,i){var e=this._validations[t];e&&(e.unmanageElement(i),w.Vue["delete"](this._scope,t),this._validations[t]=null,delete this._validations[t])},t.prototype._fireEvent=function(t){for(var i=this._events[this._getEventName(t)],e=arguments.length,n=Array(e>1?e-1:0),a=1;e>a;a++)n[a-1]=arguments[a];i&&i.apply(null,n)},t.prototype._fireEvents=function(){var t=this._scope;t.touched&&this._fireEvent("touched"),t.dirty&&this._fireEvent("dirty"),this._modified!==t.modified&&(this._fireEvent("modified",t.modified),this._modified=t.modified);var i=t.valid;this._fireEvent(i?"valid":"invalid")},t.prototype._getEventName=function(t){return this.name+":"+t},t.prototype._defineProperties=function(t,i){var n=this,a=w.Vue.util.bind;e({valid:{fn:this._defineValid,arg:t},invalid:{fn:this._defineInvalid,arg:i},touched:{fn:this._defineTouched,arg:t},untouched:{fn:this._defineUntouched, -arg:i},modified:{fn:this._defineModified,arg:t},dirty:{fn:this._defineDirty,arg:t},pristine:{fn:this._definePristine,arg:i},errors:{fn:this._defineErrors,arg:t}},function(t,e){Object.defineProperty(i(),e,{enumerable:!0,configurable:!0,get:function(){return a(t.fn,n)(t.arg)}})})},t.prototype._runValidates=function(t,i){var n=Object.keys(this.validations).length,a=0;e(this.validations,function(e,o){t(e,o,function(){++a,a>=n&&i()})})},t.prototype._walkValidations=function(t,i,n){var a=this,o=w.Vue.util.hasOwn,s=n;return e(t,function(t,e){if(s!==!n&&o(a._scope,t.field)){var r=a._scope[t.field];r&&r[i]===!n&&(s=!n)}}),s},t.prototype._defineValid=function(t){return this._walkValidations(t(),"valid",!0)},t.prototype._defineInvalid=function(t){return!t().valid},t.prototype._defineTouched=function(t){return this._walkValidations(t(),"touched",!1)},t.prototype._defineUntouched=function(t){return!t().touched},t.prototype._defineModified=function(t){return this._walkValidations(t(),"modified",!1)},t.prototype._defineDirty=function(t){return this._walkValidations(t(),"dirty",!1)},t.prototype._definePristine=function(t){return!t().dirty},t.prototype._defineErrors=function(t){var n=this,a=w.Vue.util.hasOwn,o=w.Vue.util.isPlainObject,s=[];return e(t(),function(t,r){if(a(n._scope,t.field)){var l=n._scope[t.field];l&&!i(l.errors)&&e(l.errors,function(i,e){var n={field:t.field};o(i)?(i.validator&&(n.validator=i.validator),n.message=i.message):"string"==typeof i&&(n.message=i),s.push(n)})}}),i(s)?void 0:s},C.createClass(t,[{key:"validations",get:function(){var t=w.Vue.util.extend,i={};return t(i,this._validations),e(this._checkboxValidations,function(t,e){i[e]=t.validation}),e(this._radioValidations,function(t,e){i[e]=t.validation}),i}}]),t}();return b.version="2.1.0","undefined"!=typeof window&&window.Vue&&window.Vue.use(b),b}); \ No newline at end of file +!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define(i):t.VueValidator=i()}(this,function(){"use strict";function t(t,i){window.console&&(console.warn("[vue-validator] "+t),i&&console.warn(i.stack))}function i(t){if(null===t||void 0===t)return!0;if(Array.isArray(t)){if(t.length>0)return!1;if(0===t.length)return!0}else if(w.Vue.util.isPlainObject(t))for(var i in t)if(w.Vue.util.hasOwn(t,i))return!1;return!0}function e(t,i,e){if(Array.isArray(t))for(var n=0;na;a++)e(t,n[a])}function r(t){if(Array.isArray(t)){if(0!==t.length){for(var i=!0,e=0,n=t.length;n>e&&(i=r(t[e]),i);e++);return i}return!1}return"number"==typeof t||"function"==typeof t?!0:"boolean"==typeof t?t:"string"==typeof t?t.length>0:null!==t&&"object"===("undefined"==typeof t?"undefined":C["typeof"](t))?Object.keys(t).length>0:null===t||void 0===t?!1:void 0}function l(t,i){if("string"!=typeof i)return!1;var e=i.match(new RegExp("^/(.*?)/([gimy]*)$"));return e?new RegExp(e[1],e[2]).test(t):!1}function d(t,i){return"string"==typeof t?f(i,10)&&t.length>=parseInt(i,10):Array.isArray(t)?t.length>=parseInt(i,10):!1}function u(t,i){return"string"==typeof t?f(i,10)&&t.length<=parseInt(i,10):Array.isArray(t)?t.length<=parseInt(i,10):!1}function h(t,i){return!isNaN(+t)&&!isNaN(+i)&&+t>=+i}function c(t,i){return!isNaN(+t)&&!isNaN(+i)&&+i>=+t}function f(t){return/^(-?[1-9]\d*|0)$/.test(t)}function p(t){var i=t.util.extend,e=Object.create(null);i(e,k),t.options.validators=e;var n=t.config.optionMergeStrategies;n&&(n.validators=function(t,e){if(!e)return t;if(!t)return e;var n=Object.create(null);i(n,t);for(var a in e)n[a]=e[a];return n}),t.validator=function(i,e){return e?void(t.options.validators[i]=e):t.options.validators[i]}}function v(t){var i=t.prototype._init;t.prototype._init=function(t){this._validatorMaps||(this._validatorMaps=Object.create(null)),i.call(this,t)};var e=t.prototype._destroy;t.prototype._destroy=function(){e.apply(this,arguments),this._validatorMaps=null}}function _(t){var i=t.directive("if"),e=t.FragmentFactory,n=t.util,a=n.toArray,o=n.replace,s=n.createAnchor;t.directive("validate-class",{terminal:!0,priority:i.priority+N,bind:function(){var t=this,i=String(F++);this.setClassIds(this.el,i),this.vm.$on(E,this.cb=function(e,n,a){e.indexOf(i)>-1&&n.updateClasses(a,t.frag.node)}),this.setupFragment()},unbind:function(){this.vm.$off(E,this.cb),this.teardownFragment()},setClassIds:function(t,i){for(var e=a(t.childNodes),n=0,o=e.length;o>n;n++){var s=e[n];if(1===s.nodeType)for(var r=s.hasAttributes(),l=r&&a(s.attributes),d=0,u=l.length;u>d;d++){var h=l[d];if(h.name.match(x)){var c=s.getAttribute(E),f=c?c+","+i:i;s.setAttribute(E,f)}}s.hasChildNodes()&&this.setClassIds(s,i)}},setupFragment:function(){this.anchor=s("v-validate-class"),o(this.el,this.anchor),this.factory=new e(this.vm,this.el),this.frag=this.factory.create(this._host,this._scope,this._frag),this.frag.before(this.anchor)},teardownFragment:function(){this.frag&&(this.frag.remove(),this.frag=null,this.factory=null),o(this.anchor,this.el),this.anchor=null}})}function g(t){function i(){if(r){var t=document.createElement("textarea");return t.placeholder="t","t"===t.cloneNode(!0).value}return!1}var n=t.directive("if"),a=t.FragmentFactory,o=t.parsers.directive.parseDirective,s=t.util,r=s.inBrowser,l=s.bind,d=s.on,u=s.off,h=s.createAnchor,c=s.replace,f=s.camelize,p=s.isPlainObject,v=i();t.directive("validate",{terminal:!0,priority:n.priority+A,params:["group","field","detect-blur","detect-change","initial","classes"],paramWatchers:{detectBlur:function(t,i){this._invalid||(this.validation.detectBlur=this.isDetectBlur(t),this.validator.validate(this.field))},detectChange:function(t,i){this._invalid||(this.validation.detectChange=this.isDetectChange(t),this.validator.validate(this.field))}},bind:function(){var t=this.el,i=this.vm.$options._validator,e=t.getAttribute("v-model"),n=this.parseModelRaw(e),a=n.model,o=n.filters;this.model=a,this.setupFragment(),this.setupValidate(i,a,o),this.listen()},update:function(t,i){if(t&&!this._invalid){p(t)?this.handleObject(t):Array.isArray(t)&&this.handleArray(t);var e={field:this.field,noopable:this._initialNoopValidation};this.frag&&(e.el=this.frag.node),this.validator.validate(e),this._initialNoopValidation&&(this._initialNoopValidation=null)}},unbind:function(){this._invalid||(this.unlisten(),this.teardownValidate(),this.teardownFragment(),this.model=null)},parseModelRaw:function(t){if(S.test(t)){var i=o(t);return{model:i.expression,filters:i.filters}}return{model:t}},setupValidate:function(t,i,e){var n=this.params,a=this.validator=this.vm._validatorMaps[t];this.field=f(this.arg?this.arg:n.field),this.validation=a.manageValidation(this.field,i,this.vm,this.frag.node,this._scope,e,n.initial,this.isDetectBlur(n.detectBlur),this.isDetectChange(n.detectChange)),p(n.classes)&&this.validation.setValidationClasses(n.classes),n.group&&a.addGroupValidation(n.group,this.field),this._initialNoopValidation=this.isInitialNoopValidation(n.initial)},listen:function(){var t=this.model,i=this.validation,e=this.frag.node;this.onBlur=l(i.listener,i),d(e,"blur",this.onBlur),"radio"!==e.type&&"SELECT"!==e.tagName||t?"checkbox"===e.type?t?(this.onClick=l(i.listener,i),d(e,"click",this.onClick)):(this.onChange=l(i.listener,i),d(e,"change",this.onChange)):t||(this.onInput=l(i.listener,i),d(e,"input",this.onInput)):(this.onChange=l(i.listener,i),d(e,"change",this.onChange))},unlisten:function(){var t=this.frag.node;this.onInput&&(u(t,"input",this.onInput),this.onInput=null),this.onClick&&(u(t,"click",this.onClick),this.onClick=null),this.onChange&&(u(t,"change",this.onChange),this.onChange=null),this.onBlur&&(u(t,"blur",this.onBlur),this.onBlur=null)},teardownValidate:function(){if(this.validator&&this.validation){var t=this.frag.node;this.params.group&&this.validator.removeGroupValidation(this.params.group,this.field),this.validator.unmanageValidation(this.field,t),this.validator=null,this.validation=null,this.field=null}},setupFragment:function(){this.anchor=h("v-validate"),c(this.el,this.anchor),this.factory=new a(this.vm,this.shimNode(this.el)),this.frag=this.factory.create(this._host,this._scope,this._frag),this.frag.before(this.anchor)},teardownFragment:function(){this.frag&&(this.frag.remove(),this.frag=null,this.factory=null),c(this.anchor,this.el),this.anchor=null},handleArray:function(t){var i=this;e(t,function(t){i.validation.setValidation(t)})},handleObject:function(t){var i=this;e(t,function(t,e){if(p(t)){if("rule"in t){var n="message"in t?t.message:null,a="initial"in t?t.initial:null;i.validation.setValidation(e,t.rule,n,a)}}else i.validation.setValidation(e,t)})},isDetectBlur:function(t){return void 0===t||"on"===t||t===!0},isDetectChange:function(t){return void 0===t||"on"===t||t===!0},isInitialNoopValidation:function(t){return"off"===t||t===!1},shimNode:function(t){var i=t;if(v&&"TEXTAREA"===t.tagName){i=t.cloneNode(!0),i.value=t.value;for(var e=i.childNodes.length;e--;)i.removeChild(i.childNodes[e])}return i}})}function m(t){var i=t.FragmentFactory,e=t.directive("if"),n=t.util,a=n.isArray,o=n.isPlainObject,s=n.createAnchor,r=n.replace,l=n.extend,d=n.camelize;t.elementDirective("validator",{params:["name","groups","lazy","classes"],bind:function(){var t=this.params;if(this.validatorName="$"+d(t.name),!this.vm._validatorMaps)throw new Error("Invalid validator management error");var i={};o(this.params.classes)&&(i=this.params.classes),this.setupValidator(i),this.setupFragment(t.lazy)},unbind:function(){this.teardownFragment(),this.teardownValidator()},getGroups:function(){var t=this.params,i=[];return t.groups&&(a(t.groups)?i=t.groups:o(t.groups)||"string"!=typeof t.groups||i.push(t.groups)),i},setupValidator:function(t){var i=this.validator=new U(this.validatorName,this,this.getGroups(),t);i.enableReactive(),i.setupScope(),i.registerEvents()},teardownValidator:function(){this.validator.unregisterEvents(),this.validator.disableReactive(),this.validatorName&&(this.validatorName=null,this.validator=null)},setupFragment:function(t){var n=this,a=this.vm;this.validator.waitFor(function(){n.anchor=s("vue-validator"),r(n.el,n.anchor),l(a.$options,{_validator:n.validatorName}),n.factory=new i(a,n.el.innerHTML),e.insert.call(n)}),!t&&a.$activateValidator()},teardownFragment:function(){e.unbind.call(this)}})}function y(t){var i={name:"validator-error",props:{field:{type:String,required:!0},validator:{type:String},message:{type:String,required:!0},partial:{type:String,"default":"validator-error-default"}},template:'
',partials:{}};return i.partials["validator-error-default"]="

{{field}}: {{message}}

",i}function V(t){var i=t.util,e=y(t),n={name:"validator-errors",props:{validation:{type:Object,required:!0},group:{type:String,"default":null},field:{type:String,"default":null},component:{type:String,"default":"validator-error"}},computed:{errors:function(){var t=this;if(null!==this.group)return this.validation[this.group].errors;if(null!==this.field){var e=this.validation[this.field];if(!e.errors)return;return e.errors.map(function(e){var n={field:t.field};return i.isPlainObject(e)?(e.validator&&(n.validator=e.validator),n.message=e.message):"string"==typeof e&&(n.message=e),n})}return this.validation.errors}},template:'',components:{}};return n.props.partial=e.props.partial,n.components[e.name]=e,t.component(n.name,n),n}function b(i){arguments.length<=1||void 0===arguments[1]?{}:arguments[1];return b.installed?void t("already installed."):(w.Vue=i,p(i),V(i),v(i),m(i),_(i),void g(i))}var C={};C["typeof"]="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},C.classCallCheck=function(t,i){if(!(t instanceof i))throw new TypeError("Cannot call a class as a function")},C.createClass=function(){function t(t,i){for(var e=0;eh;h++)if(s=e[h],r=a(this._vm.$options,"filters",s.name),r&&(r=n?r.write:r.read||r,"function"==typeof r)){if(l=n?[t,i]:[t],u=n?2:1,s.args)for(f=0,p=s.args.length;p>f;f++)d=s.args[f],l[f+u]=d.dynamic?o.$get(d.value):d.value;t=r.apply(this._vm,l)}return t},t.prototype._runValidators=function(t,i){var n=this._validators,a=Object.keys(n).length,o=0;e(n,function(e,n){t(e,n,function(){++o,o>=a&&i()})})},t.prototype._invokeValidator=function(t,i,e,n,a){var s=i.call(this,e,n);"function"==typeof s?s.resolved?a(s.resolved):s.requested?s.pendingCallbacks.push(a):!function(){s.requested=!0;var t=s.pendingCallbacks=[a];s(function(){s.resolved=!0;for(var i=0,e=t.length;e>i;i++)t[i](!0)},function(t){a(!1,t)})}():o(s)?s.then(function(){a(!0)},function(t){a(!1,t)})["catch"](function(t){a(!1,t.message)}):a(s)},t.prototype._resolveValidator=function(t){var i=w.Vue.util.resolveAsset;return i(this._vm.$options,"validators",t)},C.createClass(t,[{key:"vm",get:function(){return this._vm}},{key:"el",get:function(){return this._el}},{key:"detectChange",get:function(){return this._detectChange},set:function(t){this._detectChange=t}},{key:"detectBlur",get:function(){return this._detectBlur},set:function(t){this._detectBlur=t}}]),t}(),M=function(t){function i(e,n,a,o,s,r,l,d,u){C.classCallCheck(this,i);var h=C.possibleConstructorReturn(this,t.call(this,e,n,a,o,s,r,l,d,u));return h._inits=[],h}return C.inherits(i,t),i.prototype.manageElement=function(t,i){var e=this,n=this._getScope(),a=this._addItem(t,i),o=a.model=this._model;if(o){var s=this._evalModel(o,this._filters);Array.isArray(s)?(this._setChecked(s,a.el),a.unwatch=n.$watch(o,function(t,i){if(t!==i){if(e.guardValidate(a.el,"change"))return;e.handleValidate(a.el,{noopable:a.initial}),a.initial&&(a.initial=null)}})):(t.checked=s||!1,this._init=t.checked,a.init=t.checked,a.value=t.value,a.unwatch=n.$watch(o,function(i,n){if(i!==n){if(e.guardValidate(t,"change"))return;e.handleValidate(t,{noopable:a.initial}),a.initial&&(a.initial=null)}}))}else{var r={field:this.field,noopable:i};this._checkClassIds(t)&&(r.el=t),this._validator.validate(r)}},i.prototype.unmanageElement=function(t){var i=-1;e(this._inits,function(e,n){e.el===t&&(i=n,e.unwatch&&e.model&&(e.unwatch(),e.unwatch=null,e.model=null))}),-1!==i&&(this._inits.splice(i,1),this._validator.validate({field:this.field}))},i.prototype.willUpdateFlags=function(){var t=this,i=arguments.length<=0||void 0===arguments[0]?!1:arguments[0];e(this._inits,function(e,n){i&&t.willUpdateTouched(e.el,"blur"),t.willUpdateDirty(e.el),t.willUpdateModified(e.el)})},i.prototype.reset=function(){this.resetFlags(),e(this._inits,function(t,i){t.init=t.el.checked,t.value=t.el.value})},i.prototype.updateClasses=function(t){var i=this,n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];n?this._updateClasses(n,t):e(this._inits,function(e,n){i._updateClasses(e.el,t)})},i.prototype._addItem=function(t,i){var e={el:t,init:t.checked,value:t.value,initial:i},n=t.getAttribute(E);return n&&(t.removeAttribute(E),e.classIds=n.split(",")),this._inits.push(e),e},i.prototype._setChecked=function(t,i){for(var e=0,n=t.length;n>e;e++){var a=t[e];i.disabled||i.value!==a||i.checked||(i.checked=!0)}},i.prototype._getValue=function(t){var i=this;if(!this._inits||0===this._inits.length)return t.checked;var n=function(){var t=[];return e(i._inits,function(i,e){i.el.checked&&t.push(i.el.value)}),{v:t}}();return"object"===("undefined"==typeof n?"undefined":C["typeof"](n))?n.v:void 0},i.prototype._getClassIds=function(t){var i=void 0;return e(this._inits,function(e,n){e.el===t&&(i=e.classIds)}),i},i.prototype._checkModified=function(t){var i=this;if(0===this._inits.length)return this._init!==t.checked;var n=function(){var t=!1;return e(i._inits,function(i,e){t||(t=i.init!==i.el.checked)}),{v:t}}();return"object"===("undefined"==typeof n?"undefined":C["typeof"](n))?n.v:void 0},i}(O),$=function(t){function i(e,n,a,o,s,r,l,d,u){C.classCallCheck(this,i);var h=C.possibleConstructorReturn(this,t.call(this,e,n,a,o,s,r,l,d,u));return h._inits=[],h}return C.inherits(i,t),i.prototype.manageElement=function(t,i){var e=this,n=this._getScope(),a=this._addItem(t,i),o=a.model=this._model;if(o){var s=this._evalModel(o,this._filters);this._setChecked(s,t,a),a.unwatch=n.$watch(o,function(i,n){if(i!==n){if(e.guardValidate(a.el,"change"))return;e.handleValidate(t,{noopable:a.initial}),a.initial&&(a.initial=null)}})}else{var r={field:this.field,noopable:i};this._checkClassIds(t)&&(r.el=t),this._validator.validate(r)}},i.prototype.unmanageElement=function(t){var i=-1;e(this._inits,function(e,n){e.el===t&&(i=n)}),-1!==i&&(this._inits.splice(i,1),this._validator.validate({field:this.field}))},i.prototype.willUpdateFlags=function(){var t=this,i=arguments.length<=0||void 0===arguments[0]?!1:arguments[0];e(this._inits,function(e,n){i&&t.willUpdateTouched(e.el,"blur"),t.willUpdateDirty(e.el),t.willUpdateModified(e.el)})},i.prototype.reset=function(){this.resetFlags(),e(this._inits,function(t,i){t.init=t.el.checked,t.value=t.el.value})},i.prototype.updateClasses=function(t){var i=this,n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];n?this._updateClasses(n,t):e(this._inits,function(e,n){i._updateClasses(e.el,t)})},i.prototype._addItem=function(t,i){var e={el:t,init:t.checked,value:t.value,initial:i},n=t.getAttribute(E);return n&&(t.removeAttribute(E),e.classIds=n.split(",")),this._inits.push(e),e},i.prototype._setChecked=function(t,i,e){i.value===t&&(i.checked=!0,this._init=i.checked,e.init=i.checked,e.value=t)},i.prototype._getValue=function(t){var i=this;if(!this._inits||0===this._inits.length)return t.checked;var n=function(){var t=[];return e(i._inits,function(i,e){i.el.checked&&t.push(i.el.value)}),{v:t}}();return"object"===("undefined"==typeof n?"undefined":C["typeof"](n))?n.v:void 0},i.prototype._getClassIds=function(t){var i=void 0;return e(this._inits,function(e,n){e.el===t&&(i=e.classIds)}),i},i.prototype._checkModified=function(t){var i=this;if(0===this._inits.length)return this._init!==t.checked;var n=function(){var t=!1;return e(i._inits,function(i,e){t||(t=i.init!==i.el.checked)}),{v:t}}();return"object"===("undefined"==typeof n?"undefined":C["typeof"](n))?n.v:void 0},i}(O),j=function(t){function i(e,n,a,o,s,r,l,d,u){C.classCallCheck(this,i);var h=C.possibleConstructorReturn(this,t.call(this,e,n,a,o,s,r,l,d,u));return h._multiple=h._el.hasAttribute("multiple"),h}return C.inherits(i,t),i.prototype.manageElement=function(t,i){var e=this,n=this._getScope(),a=this._model;this._initial=i;var o=t.getAttribute(E);if(o&&(t.removeAttribute(E),this._classIds=o.split(",")),a){var s=this._evalModel(a,this._filters),r=Array.isArray(s)?s:[s];this._setOption(r,t),this._unwatch=n.$watch(a,function(i,n){var a=Array.isArray(i)?i:[i],o=Array.isArray(n)?n:[n];if(a.slice().sort().toString()!==o.slice().sort().toString()){if(e.guardValidate(t,"change"))return;e.handleValidate(t,{noopable:e._initial}),e._initial&&(e._initial=null)}})}},i.prototype.unmanageElement=function(t){this._unwatch&&this._unwatch()},i.prototype.reset=function(){this.resetFlags()},i.prototype._getValue=function(t){for(var i=[],e=0,n=t.options.length;n>e;e++){var a=t.options[e];!a.disabled&&a.selected&&i.push(a.value)}return i},i.prototype._setOption=function(t,i){for(var e=0,n=t.length;n>e;e++)for(var a=t[e],o=0,s=i.options.length;s>o;o++){var r=i.options[o];r.disabled||r.value!==a||r.hasAttribute("selected")&&r.selected||(r.selected=!0)}},i.prototype._checkModified=function(t){var i=this._getValue(t).slice().sort();if(this._init.length!==i.length)return!0;var e=this._init.slice().sort();return e.toString()!==i.toString()},i}(O),U=function(){function t(i,n,a,o){var s=this;C.classCallCheck(this,t),this.name=i,this._scope={},this._dir=n,this._validations={},this._checkboxValidations={},this._radioValidations={},this._groups=a,this._groupValidations={},this._events={},this._modified=!1,this._classes=o,e(a,function(t){s._groupValidations[t]=[]})}return t.prototype.enableReactive=function(){var t=this._dir.vm;w.Vue.util.defineReactive(t,this.name,this._scope),t._validatorMaps[this.name]=this,this._defineResetValidation(),this._defineValidate(),this._defineSetValidationErrors()},t.prototype.disableReactive=function(){var t=this._dir.vm;t.$setValidationErrors=void 0,t.$validate=void 0,t.$validatorReset=void 0,t._validatorMaps[this.name]=null,t[this.name]=null},t.prototype.registerEvents=function(){for(var t=this._dir.el.attributes,i=0,e=t.length;e>i;i++){var n=t[i].name;I.test(n)&&(n=n.replace(I,""),this._events[this._getEventName(n)]=this._dir.vm.$eval(t[i].value,!0))}},t.prototype.unregisterEvents=function(){var t=this;e(this._events,function(i,e){t._events[e]=null,delete t._events[e]})},t.prototype.manageValidation=function(t,i,e,n,a,o,s,r,l){var d=null;return d="SELECT"===n.tagName?this._manageSelectValidation(t,i,e,n,a,o,s,r,l):"checkbox"===n.type?this._manageCheckboxValidation(t,i,e,n,a,o,s,r,l):"radio"===n.type?this._manageRadioValidation(t,i,e,n,a,o,s,r,l):this._manageBaseValidation(t,i,e,n,a,o,s,r,l),d.setValidationClasses(this._classes),d},t.prototype.unmanageValidation=function(t,i){"checkbox"===i.type?this._unmanageCheckboxValidation(t,i):"radio"===i.type?this._unmanageRadioValidation(t,i):"SELECT"===i.tagName?this._unmanageSelectValidation(t,i):this._unmanageBaseValidation(t,i)},t.prototype.addGroupValidation=function(t,i){var e=w.Vue.util.indexOf,n=this._validations[i]||this._checkboxValidations[i].validation||this._radioValidations[i].validation,a=this._groupValidations[t];a&&!~e(a,n)&&a.push(n)},t.prototype.removeGroupValidation=function(t,i){var e=this._validations[i]||this._checkboxValidations[i].validation||this._radioValidations[i].validation,a=this._groupValidations[t];a&&n(a,e)},t.prototype.validate=function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],i=t.el,n=void 0===i?null:i,a=t.field,o=void 0===a?null:a,s=t.touched,r=void 0===s?!1:s,l=t.noopable,d=void 0===l?!1:l,u=t.cb,h=void 0===u?null:u;o?this._validate(o,r,d,n,h):(e(this.validations,function(t,i){t.willUpdateFlags(r)}),this._validates(h))},t.prototype.setupScope=function(){var t=this;this._defineProperties(function(){return t.validations},function(){return t._scope}),e(this._groups,function(i){var e=t._groupValidations[i],n={};w.Vue.set(t._scope,i,n),t._defineProperties(function(){return e},function(){return n})})},t.prototype.waitFor=function(t){var i="$activateValidator",e=this._dir.vm;e[i]=function(){t(),e[i]=null}},t.prototype._defineResetValidation=function(){var t=this;this._dir.vm.$resetValidation=function(i){t._resetValidation(i)}},t.prototype._defineValidate=function(){var t=this;this._dir.vm.$validate=function(){for(var i=arguments.length,n=Array(i),a=0;i>a;a++)n[a]=arguments[a];var o=null,s=!1,r=null;e(n,function(t,i){"string"==typeof t?o=t:"boolean"==typeof t?s=t:"function"==typeof t&&(r=t)}),t.validate({field:o,touched:s,cb:r})}},t.prototype._defineSetValidationErrors=function(){var t=this;this._dir.vm.$setValidationErrors=function(i){t._setValidationErrors(i)}},t.prototype._validate=function(t){var i=arguments.length<=1||void 0===arguments[1]?!1:arguments[1],e=arguments.length<=2||void 0===arguments[2]?!1:arguments[2],n=this,a=arguments.length<=3||void 0===arguments[3]?null:arguments[3],o=arguments.length<=4||void 0===arguments[4]?null:arguments[4],s=this._scope,r=this._getValidationFrom(t);r&&(r.willUpdateFlags(i),r.validate(function(i){w.Vue.set(s,t,i),n._fireEvents(),o&&o()},e,a))},t.prototype._validates=function(t){var i=this,e=this._scope;this._runValidates(function(t,i,n){t.validate(function(t){w.Vue.set(e,i,t),n()})},function(){i._fireEvents(),t&&t()})},t.prototype._getValidationFrom=function(t){var i=this._validations[t];return!i&&this._checkboxValidations[t]?i=this._checkboxValidations[t].validation:!i&&this._radioValidations[t]&&(i=this._radioValidations[t].validation),i},t.prototype._resetValidation=function(t){e(this.validations,function(t,i){t.reset()}),this._validates(t)},t.prototype._setValidationErrors=function(t){var i=this,n=w.Vue.util.extend,a={};e(t,function(t,i){a[t.field]||(a[t.field]=[]),a[t.field].push(t)}),e(a,function(t,a){var o=i._scope[a],s={};e(t,function(t){t.validator&&(o[t.validator]=t.message)}),o.valid=!1,o.invalid=!0,o.errors=t,n(s,o),w.Vue.set(i._scope,a,s)})},t.prototype._manageBaseValidation=function(t,i,e,n,a,o,s,r,l){var d=this._validations[t]=new O(t,i,e,n,a,this,o,r,l);return d.manageElement(n,s),d},t.prototype._unmanageBaseValidation=function(t,i){var e=this._validations[t];e&&(e.unmanageElement(i),w.Vue["delete"](this._scope,t),this._validations[t]=null,delete this._validations[t])},t.prototype._manageCheckboxValidation=function(t,i,e,n,a,o,s,r,l){var d=this._checkboxValidations[t];if(!d){var u=new M(t,i,e,n,a,this,o,r,l);d={validation:u,elements:0},this._checkboxValidations[t]=d}return d.elements++,d.validation.manageElement(n,s),d.validation},t.prototype._unmanageCheckboxValidation=function(t,i){var e=this._checkboxValidations[t];e&&(e.elements--,e.validation.unmanageElement(i),0===e.elements&&(w.Vue["delete"](this._scope,t),this._checkboxValidations[t]=null,delete this._checkboxValidations[t]))},t.prototype._manageRadioValidation=function(t,i,e,n,a,o,s,r,l){var d=this._radioValidations[t];if(!d){var u=new $(t,i,e,n,a,this,o,r,l);d={validation:u,elements:0},this._radioValidations[t]=d}return d.elements++,d.validation.manageElement(n,s),d.validation},t.prototype._unmanageRadioValidation=function(t,i){var e=this._radioValidations[t];e&&(e.elements--,e.validation.unmanageElement(i),0===e.elements&&(w.Vue["delete"](this._scope,t),this._radioValidations[t]=null,delete this._radioValidations[t]))},t.prototype._manageSelectValidation=function(t,i,e,n,a,o,s,r,l){var d=this._validations[t]=new j(t,i,e,n,a,this,o,r,l);return d.manageElement(n,s),d},t.prototype._unmanageSelectValidation=function(t,i){var e=this._validations[t];e&&(e.unmanageElement(i),w.Vue["delete"](this._scope,t),this._validations[t]=null,delete this._validations[t])},t.prototype._fireEvent=function(t){for(var i=this._events[this._getEventName(t)],e=arguments.length,n=Array(e>1?e-1:0),a=1;e>a;a++)n[a-1]=arguments[a];i&&i.apply(null,n)},t.prototype._fireEvents=function(){var t=this._scope;t.touched&&this._fireEvent("touched"),t.dirty&&this._fireEvent("dirty"),this._modified!==t.modified&&(this._fireEvent("modified",t.modified),this._modified=t.modified);var i=t.valid;this._fireEvent(i?"valid":"invalid")},t.prototype._getEventName=function(t){return this.name+":"+t},t.prototype._defineProperties=function(t,i){var n=this,a=w.Vue.util.bind;e({valid:{fn:this._defineValid,arg:t},invalid:{fn:this._defineInvalid,arg:i},touched:{fn:this._defineTouched,arg:t},untouched:{ +fn:this._defineUntouched,arg:i},modified:{fn:this._defineModified,arg:t},dirty:{fn:this._defineDirty,arg:t},pristine:{fn:this._definePristine,arg:i},errors:{fn:this._defineErrors,arg:t}},function(t,e){Object.defineProperty(i(),e,{enumerable:!0,configurable:!0,get:function(){return a(t.fn,n)(t.arg)}})})},t.prototype._runValidates=function(t,i){var n=Object.keys(this.validations).length,a=0;e(this.validations,function(e,o){t(e,o,function(){++a,a>=n&&i()})})},t.prototype._walkValidations=function(t,i,n){var a=this,o=w.Vue.util.hasOwn,s=n;return e(t,function(t,e){if(s!==!n&&o(a._scope,t.field)){var r=a._scope[t.field];r&&r[i]===!n&&(s=!n)}}),s},t.prototype._defineValid=function(t){return this._walkValidations(t(),"valid",!0)},t.prototype._defineInvalid=function(t){return!t().valid},t.prototype._defineTouched=function(t){return this._walkValidations(t(),"touched",!1)},t.prototype._defineUntouched=function(t){return!t().touched},t.prototype._defineModified=function(t){return this._walkValidations(t(),"modified",!1)},t.prototype._defineDirty=function(t){return this._walkValidations(t(),"dirty",!1)},t.prototype._definePristine=function(t){return!t().dirty},t.prototype._defineErrors=function(t){var n=this,a=w.Vue.util.hasOwn,o=w.Vue.util.isPlainObject,s=[];return e(t(),function(t,r){if(a(n._scope,t.field)){var l=n._scope[t.field];l&&!i(l.errors)&&e(l.errors,function(i,e){var n={field:t.field};o(i)?(i.validator&&(n.validator=i.validator),n.message=i.message):"string"==typeof i&&(n.message=i),s.push(n)})}}),i(s)?void 0:s},C.createClass(t,[{key:"validations",get:function(){var t=w.Vue.util.extend,i={};return t(i,this._validations),e(this._checkboxValidations,function(t,e){i[e]=t.validation}),e(this._radioValidations,function(t,e){i[e]=t.validation}),i}}]),t}();return b.version="2.1.1","undefined"!=typeof window&&window.Vue&&window.Vue.use(b),b}); \ No newline at end of file diff --git a/docs/en/installation.md b/docs/en/installation.md index 72859b0..6277ac5 100644 --- a/docs/en/installation.md +++ b/docs/en/installation.md @@ -9,7 +9,7 @@ See [dist folder](https://github.com/vuejs/vue-validator/tree/dev/dist). Note th ### jsdelivr ```html - + ``` ## NPM diff --git a/package.json b/package.json index 12b765a..84934de 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "vue-validator", "description": "Validator component for Vue.js", - "version": "2.1.0", + "version": "2.1.1", "author": { "name": "kazuya kawaguchi", "email": "kawakazu80@gmail.com" diff --git a/src/index.js b/src/index.js index b3db277..146b961 100644 --- a/src/index.js +++ b/src/index.js @@ -30,7 +30,7 @@ function plugin (Vue, options = {}) { Validate(Vue) } -plugin.version = '2.1.0' +plugin.version = '2.1.1' export default plugin