diff --git a/CHANGELOG.md b/CHANGELOG.md index 621d037..0eff357 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ + +## [2.1.6](https://github.com/vuejs/vue-validator/compare/v2.1.5...v2.1.6) (2016-08-19) + + +### :bug: Bug Fixes + +* **validate:** fix initial compilation error ([fa99a91](https://github.com/vuejs/vue-validator/commit/fa99a91)), closes [#288](https://github.com/vuejs/vue-validator/issues/288) + + + ## [2.1.5](https://github.com/vuejs/vue-validator/compare/v2.1.4...v2.1.5) (2016-07-25) diff --git a/dist/vue-validator.common.js b/dist/vue-validator.common.js index cc3123d..3f0760c 100644 --- a/dist/vue-validator.common.js +++ b/dist/vue-validator.common.js @@ -1,5 +1,5 @@ /*! - * vue-validator v2.1.5 + * vue-validator v2.1.6 * (c) 2016 kazuya kawaguchi * Released under the MIT License. */ @@ -424,7 +424,7 @@ function Override (Vue) { } var VALIDATE_UPDATE = '__vue-validator-validate-update__'; -var PRIORITY_VALIDATE = 16; +var PRIORITY_VALIDATE = 4096; var PRIORITY_VALIDATE_CLASS = 32; var REGEX_FILTER = /[^|]\|[^|]/; var REGEX_VALIDATE_DIRECTIVE = /^v-validate(?:$|:(.*)$)/; @@ -432,6 +432,7 @@ var REGEX_EVENT = /^v-on:|^@/; var classId = 0; // ID for validation class + function ValidateClass (Vue) { var vIf = Vue.directive('if'); var FragmentFactory = Vue.FragmentFactory; @@ -510,7 +511,6 @@ function ValidateClass (Vue) { } function Validate (Vue) { - var vIf = Vue.directive('if'); var FragmentFactory = Vue.FragmentFactory; var parseDirective = Vue.parsers.directive.parseDirective; var _Vue$util = Vue.util; @@ -543,7 +543,7 @@ function Validate (Vue) { Vue.directive('validate', { deep: true, terminal: true, - priority: vIf.priority + PRIORITY_VALIDATE, + priority: PRIORITY_VALIDATE, params: ['group', 'field', 'detect-blur', 'detect-change', 'initial', 'classes'], paramWatchers: { @@ -1261,7 +1261,7 @@ var BaseValidation = function () { BaseValidation.prototype._invokeValidator = function _invokeValidator(vm, validator, val, arg, cb) { var future = validator.call(this, val, arg); if (typeof future === 'function') { - // function + // function future(function () { // resolve cb(true); @@ -1921,7 +1921,7 @@ var Validator$1 = function () { var validation = this._getValidationFrom(field); var validations = this._groupValidations[group]; - validations && ! ~indexOf(validations, validation) && validations.push(validation); + validations && !~indexOf(validations, validation) && validations.push(validation); }; Validator.prototype.removeGroupValidation = function removeGroupValidation(group, field) { @@ -2604,7 +2604,7 @@ function plugin(Vue) { Validate(Vue); } -plugin.version = '2.1.5'; +plugin.version = '2.1.6'; if (typeof window !== 'undefined' && window.Vue) { window.Vue.use(plugin); diff --git a/dist/vue-validator.js b/dist/vue-validator.js index 7400a56..144edad 100644 --- a/dist/vue-validator.js +++ b/dist/vue-validator.js @@ -1,5 +1,5 @@ /*! - * vue-validator v2.1.5 + * vue-validator v2.1.6 * (c) 2016 kazuya kawaguchi * Released under the MIT License. */ @@ -428,7 +428,7 @@ var validators = Object.freeze({ } var VALIDATE_UPDATE = '__vue-validator-validate-update__'; - var PRIORITY_VALIDATE = 16; + var PRIORITY_VALIDATE = 4096; var PRIORITY_VALIDATE_CLASS = 32; var REGEX_FILTER = /[^|]\|[^|]/; var REGEX_VALIDATE_DIRECTIVE = /^v-validate(?:$|:(.*)$)/; @@ -436,6 +436,7 @@ var validators = Object.freeze({ var classId = 0; // ID for validation class + function ValidateClass (Vue) { var vIf = Vue.directive('if'); var FragmentFactory = Vue.FragmentFactory; @@ -514,7 +515,6 @@ var validators = Object.freeze({ } function Validate (Vue) { - var vIf = Vue.directive('if'); var FragmentFactory = Vue.FragmentFactory; var parseDirective = Vue.parsers.directive.parseDirective; var _Vue$util = Vue.util; @@ -547,7 +547,7 @@ var validators = Object.freeze({ Vue.directive('validate', { deep: true, terminal: true, - priority: vIf.priority + PRIORITY_VALIDATE, + priority: PRIORITY_VALIDATE, params: ['group', 'field', 'detect-blur', 'detect-change', 'initial', 'classes'], paramWatchers: { @@ -1265,7 +1265,7 @@ var validators = Object.freeze({ BaseValidation.prototype._invokeValidator = function _invokeValidator(vm, validator, val, arg, cb) { var future = validator.call(this, val, arg); if (typeof future === 'function') { - // function + // function future(function () { // resolve cb(true); @@ -1925,7 +1925,7 @@ var validators = Object.freeze({ var validation = this._getValidationFrom(field); var validations = this._groupValidations[group]; - validations && ! ~indexOf(validations, validation) && validations.push(validation); + validations && !~indexOf(validations, validation) && validations.push(validation); }; Validator.prototype.removeGroupValidation = function removeGroupValidation(group, field) { @@ -2608,7 +2608,7 @@ var validators = Object.freeze({ Validate(Vue); } - plugin.version = '2.1.5'; + plugin.version = '2.1.6'; 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 765723f..59280db 100644 --- a/dist/vue-validator.min.js +++ b/dist/vue-validator.min.js @@ -1,7 +1,7 @@ /*! - * vue-validator v2.1.5 + * vue-validator v2.1.6 * (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(C.Vue.util.isPlainObject(t))for(var i in t)if(C.Vue.util.hasOwn(t,i))return!1;return!0}function e(t,i,e){if(Array.isArray(t))for(var n=0;n0:null!==t&&"object"===("undefined"==typeof t?"undefined":w.typeof(t))?Object.keys(t).length>0:null!==t&&void 0!==t&&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)}function d(t,i){return"string"==typeof t?f(i,10)&&t.length>=parseInt(i,10):!!Array.isArray(t)&&t.length>=parseInt(i,10)}function u(t,i){return"string"==typeof t?f(i,10)&&t.length<=parseInt(i,10):!!Array.isArray(t)&&t.length<=parseInt(i,10)}function h(t,i){return!isNaN(+t)&&!isNaN(+i)&&+t>=+i}function c(t,i){return!isNaN(+t)&&!isNaN(+i)&&+t<=+i}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,r=n.createAnchor;t.directive("validate-class",{terminal:!0,priority:i.priority+F,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;n',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."):(C.Vue=i,p(i),V(i),v(i),m(i),_(i),void g(i))}var w={};w.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},w.classCallCheck=function(t,i){if(!(t instanceof i))throw new TypeError("Cannot call a class as a function")},w.createClass=function(){function t(t,i){for(var e=0;e=a&&i()})})},t.prototype._invokeValidator=function(t,i,e,n,a){var r=i.call(this,e,n);"function"==typeof r?r(function(){a(!0)},function(t){a(!1,t)}):o(r)?r.then(function(){a(!0)},function(t){a(!1,t)}).catch(function(t){a(!1,t.message)}):a(r)},t.prototype._resolveValidator=function(t){var i=C.Vue.util.resolveAsset;return i(this._vm.$options,"validators",t)},w.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}(),$=function(t){function i(e,n,a,o,r,s,l,d,u){w.classCallCheck(this,i);var h=w.possibleConstructorReturn(this,t.call(this,e,n,a,o,r,s,l,d,u));return h._inits=[],h}return w.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 r=this._evalModel(o,this._filters);Array.isArray(r)?(this._setChecked(r,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=r||!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 s={field:this.field,noopable:i};this._checkClassIds(t)&&(s.el=t),this._validator.validate(s)}},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))}),i!==-1&&(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])&&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;e1?i-1:0),n=1;n=n&&i()})})},t.prototype._walkValidations=function(t,i,n){var a=this,o=C.Vue.util.hasOwn,r=n;return e(t,function(t,e){if(r!==!n&&o(a._scope,t.field)){var s=a._scope[t.field];s&&s[i]===!n&&(r=!n)}}),r},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=C.Vue.util.hasOwn,o=C.Vue.util.isPlainObject,r=[];return e(t(),function(t,s){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),r.push(n)})}}),i(r)?void 0:r.sort(function(t,i){return t.field0)return!1;if(0===t.length)return!0}else if(C.Vue.util.isPlainObject(t))for(var i in t)if(C.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 s(t){if(Array.isArray(t)){if(0!==t.length){for(var i=!0,e=0,n=t.length;n>e&&(i=s(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":w["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 g(t){var i=t.directive("if"),e=t.FragmentFactory,n=t.util,a=n.toArray,o=n.replace,r=n.createAnchor;t.directive("validate-class",{terminal:!0,priority:i.priority+F,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 r=e[n];if(1===r.nodeType)for(var s=r.hasAttributes(),l=s&&a(r.attributes),d=0,u=l.length;u>d;d++){var h=l[d];if(h.name.match(N)){var c=r.getAttribute(E),f=c?c+","+i:i;r.setAttribute(E,f)}}r.hasChildNodes()&&this.setClassIds(r,i)}},setupFragment:function(){this.anchor=r("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 _(t){function i(){if(r){var t=document.createElement("textarea");return t.placeholder="t","t"===t.cloneNode(!0).value}return!1}var n=t.FragmentFactory,a=t.parsers.directive.parseDirective,o=t.util,r=o.inBrowser,s=o.bind,l=o.on,d=o.off,u=o.createAnchor,h=o.replace,c=o.camelize,f=o.isPlainObject,p=i();t.directive("validate",{deep:!0,terminal:!0,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){f(t)||i&&f(i)?this.handleObject(t,i):(Array.isArray(t)||i&&Array.isArray(i))&&this.handleArray(t,i);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=a(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=c(this.arg?this.arg:n.field),this.validation=a.manageValidation(this.field,i,this.vm,this.getElementFrom(this.frag),this._scope,e,n.initial,this.isDetectBlur(n.detectBlur),this.isDetectChange(n.detectChange)),f(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.getElementFrom(this.frag);this.onBlur=s(i.listener,i),l(e,"blur",this.onBlur),"radio"!==e.type&&"SELECT"!==e.tagName||t?"checkbox"===e.type?t?(this.onClick=s(i.listener,i),l(e,"click",this.onClick)):(this.onChange=s(i.listener,i),l(e,"change",this.onChange)):t||(this.onInput=s(i.listener,i),l(e,"input",this.onInput)):(this.onChange=s(i.listener,i),l(e,"change",this.onChange))},unlisten:function(){var t=this.getElementFrom(this.frag);this.onInput&&(d(t,"input",this.onInput),this.onInput=null),this.onClick&&(d(t,"click",this.onClick),this.onClick=null),this.onChange&&(d(t,"change",this.onChange),this.onChange=null),this.onBlur&&(d(t,"blur",this.onBlur),this.onBlur=null)},teardownValidate:function(){if(this.validator&&this.validation){var t=this.getElementFrom(this.frag);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=u("v-validate"),h(this.el,this.anchor),this.factory=new n(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),h(this.anchor,this.el),this.anchor=null},handleArray:function(t,i){var n=this;i&&this.validation.resetValidation(),e(t,function(t){n.validation.setValidation(t)})},handleObject:function(t,i){var n=this;i&&this.validation.resetValidation(),e(t,function(t,i){if(f(t)){if("rule"in t){var e="message"in t?t.message:null,a="initial"in t?t.initial:null;n.validation.setValidation(i,t.rule,e,a)}}else n.validation.setValidation(i,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(p&&"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},getElementFrom:function(t){return t.single?t.node:t.node.nextSibling}})}function m(t){var i=t.FragmentFactory,e=t.directive("if"),n=t.util,a=n.isArray,o=n.isPlainObject,r=n.createAnchor,s=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=r("vue-validator"),s(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."):(C.Vue=i,p(i),V(i),v(i),m(i),g(i),void _(i))}var w={};w["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},w.classCallCheck=function(t,i){if(!(t instanceof i))throw new TypeError("Cannot call a class as a function")},w.createClass=function(){function t(t,i){for(var e=0;eh;h++)if(r=e[h],s=a(this._vm.$options,"filters",r.name),s&&(s=n?s.write:s.read||s,"function"==typeof s)){if(l=n?[t,i]:[t],u=n?2:1,r.args)for(f=0,p=r.args.length;p>f;f++)d=r.args[f],l[f+u]=d.dynamic?o.$get(d.value):d.value;t=s.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 r=i.call(this,e,n);"function"==typeof r?r(function(){a(!0)},function(t){a(!1,t)}):o(r)?r.then(function(){a(!0)},function(t){a(!1,t)})["catch"](function(t){a(!1,t.message)}):a(r)},t.prototype._resolveValidator=function(t){var i=C.Vue.util.resolveAsset;return i(this._vm.$options,"validators",t)},w.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}(),$=function(t){function i(e,n,a,o,r,s,l,d,u){w.classCallCheck(this,i);var h=w.possibleConstructorReturn(this,t.call(this,e,n,a,o,r,s,l,d,u));return h._inits=[],h}return w.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 r=this._evalModel(o,this._filters);Array.isArray(r)?(this._setChecked(r,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=r||!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 s={field:this.field,noopable:i};this._checkClassIds(t)&&(s.el=t),this._validator.validate(s)}},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":w["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":w["typeof"](n))?n.v:void 0},i}(O),M=function(t){function i(e,n,a,o,r,s,l,d,u){w.classCallCheck(this,i);var h=w.possibleConstructorReturn(this,t.call(this,e,n,a,o,r,s,l,d,u));return h._inits=[],h}return w.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 r=this._evalModel(o,this._filters);this._setChecked(r,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 s={field:this.field,noopable:i};this._checkClassIds(t)&&(s.el=t),this._validator.validate(s)}},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":w["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":w["typeof"](n))?n.v:void 0},i}(O),j=function(t){function i(e,n,a,o,r,s,l,d,u){w.classCallCheck(this,i);var h=w.possibleConstructorReturn(this,t.call(this,e,n,a,o,r,s,l,d,u));return h._multiple=h._el.hasAttribute("multiple"),h}return w.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 r=this._evalModel(a,this._filters),s=Array.isArray(r)?r:[r];this._setOption(s,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,r=i.options.length;r>o;o++){var s=i.options[o];s.disabled||s.value!==a||s.hasAttribute("selected")&&s.selected||(s.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 r=this;w.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){r._groupValidations[t]=[]})}return t.prototype.enableReactive=function(){var t=this._dir.vm;C.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=null,delete t.$setValidationErrors,t.$validate=null,delete t.$validate,t.$validatorReset=null,delete t.$validatorReset,t._validatorMaps[this.name]=null,delete t._validatorMaps[this.name],t[this.name]=null,delete t[this.name]},t.prototype.registerEvents=function(){for(var t=C.Vue.parsers.expression.isSimplePath,i=this._dir.el.attributes,e=0,n=i.length;n>e;e++){var a=i[e].name;if(x.test(a)){var o=i[e].value;t(o)&&(o+=".apply(this, $arguments)"),a=a.replace(x,""),this._events[this._getEventName(a)]=this._dir.vm.$eval(o,!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,r,s,l){var d=null;return d="SELECT"===n.tagName?this._manageSelectValidation(t,i,e,n,a,o,r,s,l):"checkbox"===n.type?this._manageCheckboxValidation(t,i,e,n,a,o,r,s,l):"radio"===n.type?this._manageRadioValidation(t,i,e,n,a,o,r,s,l):this._manageBaseValidation(t,i,e,n,a,o,r,s,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=C.Vue.util.indexOf,n=this._getValidationFrom(i),a=this._groupValidations[t];a&&!~e(a,n)&&a.push(n)},t.prototype.removeGroupValidation=function(t,i){var e=this._getValidationFrom(i),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,r=t.touched,s=void 0===r?!1:r,l=t.noopable,d=void 0===l?!1:l,u=t.cb,h=void 0===u?null:u;o?this._validate(o,s,d,n,h):(e(this.validations,function(t,i){t.willUpdateFlags(s)}),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={};C.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,r=!1,s=null;e(n,function(t,i){"string"==typeof t?o=t:"boolean"==typeof t?r=t:"function"==typeof t&&(s=t)}),t.validate({field:o,touched:r,cb:s})}},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],r=this._scope,s=this._getValidationFrom(t);s&&(s.willUpdateFlags(i),s.validate(function(i){C.Vue.set(r,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){C.Vue.set(e,i,t),n()})},function(){i._fireEvents(),t&&t()})},t.prototype._getValidationFrom=function(t){return this._validations[t]||this._checkboxValidations[t]&&this._checkboxValidations[t].validation||this._radioValidations[t]&&this._radioValidations[t].validation},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=C.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],r={};e(t,function(t){t.validator&&(o[t.validator]=t.message)}),o.valid=!1,o.invalid=!0,o.errors=t,n(r,o);var s=i._getValidationFrom(a);s.willUpdateClasses(r,s.el),C.Vue.set(i._scope,a,r)})},t.prototype._manageBaseValidation=function(t,i,e,n,a,o,r,s,l){var d=this._validations[t]=new O(t,i,e,n,a,this,o,s,l);return d.manageElement(n,r),d},t.prototype._unmanageBaseValidation=function(t,i){var e=this._validations[t];e&&(e.unmanageElement(i),C.Vue["delete"](this._scope,t),this._validations[t]=null,delete this._validations[t])},t.prototype._manageCheckboxValidation=function(t,i,e,n,a,o,r,s,l){var d=this._checkboxValidations[t];if(!d){var u=new $(t,i,e,n,a,this,o,s,l);d={validation:u,elements:0},this._checkboxValidations[t]=d}return d.elements++,d.validation.manageElement(n,r),d.validation},t.prototype._unmanageCheckboxValidation=function(t,i){var e=this._checkboxValidations[t];e&&(e.elements--,e.validation.unmanageElement(i),0===e.elements&&(C.Vue["delete"](this._scope,t),this._checkboxValidations[t]=null,delete this._checkboxValidations[t]))},t.prototype._manageRadioValidation=function(t,i,e,n,a,o,r,s,l){var d=this._radioValidations[t];if(!d){var u=new M(t,i,e,n,a,this,o,s,l);d={validation:u,elements:0},this._radioValidations[t]=d}return d.elements++,d.validation.manageElement(n,r),d.validation},t.prototype._unmanageRadioValidation=function(t,i){var e=this._radioValidations[t];e&&(e.elements--,e.validation.unmanageElement(i),0===e.elements&&(C.Vue["delete"](this._scope,t),this._radioValidations[t]=null,delete this._radioValidations[t]))},t.prototype._manageSelectValidation=function(t,i,e,n,a,o,r,s,l){var d=this._validations[t]=new j(t,i,e,n,a,this,o,s,l);return d.manageElement(n,r),d},t.prototype._unmanageSelectValidation=function(t,i){var e=this._validations[t];e&&(e.unmanageElement(i),C.Vue["delete"](this._scope,t),this._validations[t]=null,delete this._validations[t])},t.prototype._fireEvent=function(t){for(var i=arguments.length,e=Array(i>1?i-1:0),n=1;i>n;n++)e[n-1]=arguments[n];var a=this._events[this._getEventName(t)];a&&this._dir.vm.$nextTick(function(){a.apply(null,e)})},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=C.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=C.Vue.util.hasOwn,r=n;return e(t,function(t,e){if(r!==!n&&o(a._scope,t.field)){var s=a._scope[t.field];s&&s[i]===!n&&(r=!n)}}),r},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=C.Vue.util.hasOwn,o=C.Vue.util.isPlainObject,r=[];return e(t(),function(t,s){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),r.push(n)})}}),i(r)?void 0:r.sort(function(t,i){return t.field + ``` ## NPM diff --git a/docs/ja/installation.md b/docs/ja/installation.md index e0b3301..49723c5 100644 --- a/docs/ja/installation.md +++ b/docs/ja/installation.md @@ -9,7 +9,7 @@ ### jsdelivr ```html - + ``` ## NPM diff --git a/docs/zh-cn/installation.md b/docs/zh-cn/installation.md index 28fc1e7..88e4240 100644 --- a/docs/zh-cn/installation.md +++ b/docs/zh-cn/installation.md @@ -9,7 +9,7 @@ ### jsdelivr ```html - + ``` ## NPM diff --git a/package.json b/package.json index 224b155..a0f0f2b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "vue-validator", "description": "Validator component for Vue.js", - "version": "2.1.5", + "version": "2.1.6", "author": { "name": "kazuya kawaguchi", "email": "kawakazu80@gmail.com" diff --git a/src/index.js b/src/index.js index 1d4ab3c..58e003e 100644 --- a/src/index.js +++ b/src/index.js @@ -30,7 +30,7 @@ function plugin (Vue, options = {}) { Validate(Vue) } -plugin.version = '2.1.5' +plugin.version = '2.1.6' export default plugin