From 527d1f451be87d3efe956abac7be2ec83e8b3553 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Mon, 14 Dec 2015 01:43:18 +0900 Subject: [PATCH] release v2.0.0-alpha.8 --- CHANGELOG.md | 15 +++++++++ README.md | 2 +- dist/vue-validator.common.js | 61 +++++++++++++++++++++++++----------- dist/vue-validator.js | 61 +++++++++++++++++++++++++----------- dist/vue-validator.min.js | 4 +-- package.json | 2 +- src/index.js | 2 +- 7 files changed, 106 insertions(+), 41 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d02fbff..dd445db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,18 @@ + +# [2.0.0-alpha.8](https://github.com/vuejs/vue-validator/compare/v2.0.0-alpha.7...v2.0.0-alpha.8) (2015-12-13) + + +### Bug Fixes + +* **asset:** fix cannot register validator issue ([dce7e96](https://github.com/vuejs/vue-validator/commit/dce7e96)), closes [#108](https://github.com/vuejs/vue-validator/issues/108) + +### Features + +* **lazy:** support lazy initialization ([f5c24c9](https://github.com/vuejs/vue-validator/commit/f5c24c9)), closes [#25](https://github.com/vuejs/vue-validator/issues/25) +* **validation:** support kebab-case ([b26a108](https://github.com/vuejs/vue-validator/commit/b26a108)), closes [#102](https://github.com/vuejs/vue-validator/issues/102) + + + # [2.0.0-alpha.7](https://github.com/vuejs/vue-validator/compare/v2.0.0-alpha.6...v2.0.0-alpha.7) (2015-12-10) diff --git a/README.md b/README.md index 4418999..ea8f8e0 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ You don't need to do this when using the standalone build because it installs it ## CDN jsdelivr ```html - + ``` diff --git a/dist/vue-validator.common.js b/dist/vue-validator.common.js index 1a58893..4916768 100644 --- a/dist/vue-validator.common.js +++ b/dist/vue-validator.common.js @@ -1,5 +1,5 @@ /*! - * vue-validator v2.0.0-alpha.7 + * vue-validator v2.0.0-alpha.8 * (c) 2015 kazuya kawaguchi * Released under the MIT License. */ @@ -276,7 +276,9 @@ function Asset (Vue) { Vue.config._assetTypes.push('validator'); // set global validators asset - Vue.options.validators = validators; + var assets = Object.create(null); + Vue.util.extend(assets, validators); + Vue.options.validators = assets; // set option merge strategy var strats = Vue.config.optionMergeStrategies; @@ -327,7 +329,9 @@ var Validation = (function () { function Validation(dir) { babelHelpers.classCallCheck(this, Validation); - this.model = dir.arg; + var camelize = exports$1.Vue.util.camelize; + + this.model = camelize(dir.arg); this.el = dir.el; this.dir = dir; this.init = dir.el.value; @@ -339,23 +343,17 @@ var Validation = (function () { babelHelpers.createClass(Validation, [{ key: 'setValidation', - value: function setValidation(name, arg, msg, fn) { - var resolveAsset = exports$1.Vue.util.resolveAsset; - + value: function setValidation(name, arg, msg) { var validator = this.validators[name]; if (!validator) { validator = this.validators[name] = {}; - validator.fn = resolveAsset(this.dir.vm.$options, 'validators', name); + validator.name = name; } validator.arg = arg; if (msg) { validator.msg = msg; } - - if (fn) { - validator.fn = fn; - } } }, { key: 'listener', @@ -387,7 +385,8 @@ var Validation = (function () { var valid = true; each(this.validators, function (descriptor, name) { - var res = descriptor.fn.call(_this.dir.vm, _this.el.value, descriptor.arg); + var validator = _this._resolveValidator(name); + var res = validator.call(_this.dir.vm, _this.el.value, descriptor.arg); if (!res) { valid = false; var msg = descriptor.msg; @@ -416,6 +415,12 @@ var Validation = (function () { return ret; } + }, { + key: '_resolveValidator', + value: function _resolveValidator(name) { + var resolveAsset = exports$1.Vue.util.resolveAsset; + return resolveAsset(this.dir.vm.$options, 'validators', name); + } }]); return Validation; })(); @@ -579,6 +584,17 @@ var Validator$1 = (function () { _this3._defineProperties(validations, group); }, this); } + }, { + key: 'waitFor', + value: function waitFor(cb) { + var vm = this._dir.vm; + var method = '$activateValidator'; + + this._dir.vm[method] = function () { + cb(); + vm[method] = null; + }; + } }, { key: '_defineProperties', value: function _defineProperties(validations, target) { @@ -690,11 +706,14 @@ function Validator (Vue) { var _ = Vue.util; var FragmentFactory = Vue.FragmentFactory; var vIf = Vue.directive('if'); + var _bind = Vue.util.bind; Vue.elementDirective('validator', { - params: ['name', 'groups'], + params: ['name', 'groups', 'lazy'], bind: function bind() { + var _this = this; + if (!this.params.name) { // TODO: should be implemented validator:bind name params nothing error' warn('TODO: should be implemented validator:bind name params nothing error'); @@ -721,13 +740,19 @@ function Validator (Vue) { validator.enableReactive(); validator.setupScope(); + validator.waitFor(_bind(function () { + _this.render(validator, validatorName); + validator.validate(); + }, this)); + + if (!this.params.lazy) { + this.vm.$activateValidator(); + } + }, + render: function render(validator, validatorName) { this.anchor = _.createAnchor('vue-validator'); _.replace(this.el, this.anchor); this.insert(validatorName); - - this.vm.$on('hook:compiled', function () { - validator.validate(); - }); }, insert: function insert(name) { _.extend(this.vm.$options, { _validator: name }); @@ -770,7 +795,7 @@ function plugin(Vue) { Validate(Vue); } -plugin.version = '2.0.0-alpha.7'; +plugin.version = '2.0.0-alpha.8'; if (typeof window !== 'undefined' && window.Vue) { window.Vue.use(plugin); diff --git a/dist/vue-validator.js b/dist/vue-validator.js index 646a454..e348d3b 100644 --- a/dist/vue-validator.js +++ b/dist/vue-validator.js @@ -1,5 +1,5 @@ /*! - * vue-validator v2.0.0-alpha.7 + * vue-validator v2.0.0-alpha.8 * (c) 2015 kazuya kawaguchi * Released under the MIT License. */ @@ -280,7 +280,9 @@ Vue.config._assetTypes.push('validator'); // set global validators asset - Vue.options.validators = validators; + var assets = Object.create(null); + Vue.util.extend(assets, validators); + Vue.options.validators = assets; // set option merge strategy var strats = Vue.config.optionMergeStrategies; @@ -331,7 +333,9 @@ function Validation(dir) { babelHelpers.classCallCheck(this, Validation); - this.model = dir.arg; + var camelize = exports$1.Vue.util.camelize; + + this.model = camelize(dir.arg); this.el = dir.el; this.dir = dir; this.init = dir.el.value; @@ -343,23 +347,17 @@ babelHelpers.createClass(Validation, [{ key: 'setValidation', - value: function setValidation(name, arg, msg, fn) { - var resolveAsset = exports$1.Vue.util.resolveAsset; - + value: function setValidation(name, arg, msg) { var validator = this.validators[name]; if (!validator) { validator = this.validators[name] = {}; - validator.fn = resolveAsset(this.dir.vm.$options, 'validators', name); + validator.name = name; } validator.arg = arg; if (msg) { validator.msg = msg; } - - if (fn) { - validator.fn = fn; - } } }, { key: 'listener', @@ -391,7 +389,8 @@ var valid = true; each(this.validators, function (descriptor, name) { - var res = descriptor.fn.call(_this.dir.vm, _this.el.value, descriptor.arg); + var validator = _this._resolveValidator(name); + var res = validator.call(_this.dir.vm, _this.el.value, descriptor.arg); if (!res) { valid = false; var msg = descriptor.msg; @@ -420,6 +419,12 @@ return ret; } + }, { + key: '_resolveValidator', + value: function _resolveValidator(name) { + var resolveAsset = exports$1.Vue.util.resolveAsset; + return resolveAsset(this.dir.vm.$options, 'validators', name); + } }]); return Validation; })(); @@ -583,6 +588,17 @@ _this3._defineProperties(validations, group); }, this); } + }, { + key: 'waitFor', + value: function waitFor(cb) { + var vm = this._dir.vm; + var method = '$activateValidator'; + + this._dir.vm[method] = function () { + cb(); + vm[method] = null; + }; + } }, { key: '_defineProperties', value: function _defineProperties(validations, target) { @@ -694,11 +710,14 @@ var _ = Vue.util; var FragmentFactory = Vue.FragmentFactory; var vIf = Vue.directive('if'); + var _bind = Vue.util.bind; Vue.elementDirective('validator', { - params: ['name', 'groups'], + params: ['name', 'groups', 'lazy'], bind: function bind() { + var _this = this; + if (!this.params.name) { // TODO: should be implemented validator:bind name params nothing error' warn('TODO: should be implemented validator:bind name params nothing error'); @@ -725,13 +744,19 @@ validator.enableReactive(); validator.setupScope(); + validator.waitFor(_bind(function () { + _this.render(validator, validatorName); + validator.validate(); + }, this)); + + if (!this.params.lazy) { + this.vm.$activateValidator(); + } + }, + render: function render(validator, validatorName) { this.anchor = _.createAnchor('vue-validator'); _.replace(this.el, this.anchor); this.insert(validatorName); - - this.vm.$on('hook:compiled', function () { - validator.validate(); - }); }, insert: function insert(name) { _.extend(this.vm.$options, { _validator: name }); @@ -774,7 +799,7 @@ Validate(Vue); } - plugin.version = '2.0.0-alpha.7'; + plugin.version = '2.0.0-alpha.8'; 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 dfd8357..1e72c26 100644 --- a/dist/vue-validator.min.js +++ b/dist/vue-validator.min.js @@ -1,6 +1,6 @@ /*! - * vue-validator v2.0.0-alpha.7 + * vue-validator v2.0.0-alpha.8 * (c) 2015 kazuya kawaguchi * Released under the MIT License. */ -!function(i,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):i.VueValidator=t()}(this,function(){"use strict";function i(i,t){window.console&&(console.warn("[vue-validator] "+i),t&&console.warn(t.stack))}function t(i){if(null===i)return!0;if(Array.isArray(i)){if(i.length>0)return!1;if(0===i.length)return!0}else if(g.Vue.util.isPlainObject(i))for(var t in i)if(g.Vue.util.hasOwn(i,t))return!1;return!0}function e(i,t,e){if(Array.isArray(i))for(var a=0;a0:"number"==typeof i||"function"==typeof i?!0:"boolean"==typeof i?i:"string"==typeof i?i.length>0:null!==i&&"object"===("undefined"==typeof i?"undefined":y["typeof"](i))?Object.keys(i).length>0:null===i||void 0===i?!1:void 0}function s(i,t){if("string"!=typeof t)return!1;var e=t.match(new RegExp("^/(.*?)/([gimy]*)$"));return e?new RegExp(e[1],e[2]).test(i):!1}function o(i,t){return"string"==typeof i&&h(t,10)&&i.length>=parseInt(t,10)}function l(i,t){return"string"==typeof i&&h(t,10)&&i.length<=parseInt(t,10)}function u(i,t){return!isNaN(+i)&&!isNaN(+t)&&+i>=+t}function d(i,t){return!isNaN(+i)&&!isNaN(+t)&&+t>=+i}function h(i){return/^(-?[1-9]\d*|0)$/.test(i)}function c(i){i.config._assetTypes.push("validator"),i.options.validators=_;var t=i.config.optionMergeStrategies;t&&(t.validators=t.methods),i.validator=function(t,e){return e?void(i.options.validators[t]=e):i.options.validators[t]}}function v(i){var t=i.prototype._init;i.prototype._init=function(i){this._validatorMaps||(this._validatorMaps=Object.create(null)),t.call(this,i)};var e=i.prototype._destroy;i.prototype._destroy=function(){e.apply(this,arguments),this._validatorMaps=null}}function f(t){var a=t.util;t.directive("validate",{params:["group"],bind:function(){var t=this.vm,e=t.$options._validator;if(!e)return void i("TODO: should be implemented error message");var n=this.validator=this.vm._validatorMaps[e],r=this.validation=new b(this);n.addValidation(r),this.params.group&&n.addGroupValidation(this.params.group,r),this.on("blur",a.bind(this.validation.listener,this.validation)),this.on("input",a.bind(this.validation.listener,this.validation))},update:function(i,t){i&&(a.isPlainObject(i)?this.handleObject(i):Array.isArray(i)&&this.handleArray(i),this.validator.validate(this.validation))},handleArray:function(i){var t=this;e(i,function(i){t.validation.setValidation(i)},this)},handleObject:function(i){var t=this;e(i,function(i,e){if(a.isPlainObject(i)){if("rule"in i){var n="message"in i?i.message:null;t.validation.setValidation(e,i.rule,n)}}else t.validation.setValidation(e,i)},this)},unbind:function(){this.validator&&this.validation&&(this.params.group&&this.validator.removeGroupValidation(this.params.group,this.validation),this.validator.removeValidation(this.validation),this.validator=null,this.validation=null)}})}function p(t){var e=t.util,a=t.FragmentFactory,n=t.directive("if");t.elementDirective("validator",{params:["name","groups"],bind:function(){if(!this.params.name)return void i("TODO: should be implemented validator:bind name params nothing error");var t=this.validatorName="$"+this.params.name;if(!this.vm._validatorMaps)return void i("TODO: should be implemented error message");var a=[];this.params.groups&&(e.isArray(this.params.groups)?a=this.params.groups:e.isPlainObject(this.params.groups)||"string"!=typeof this.params.groups||a.push(this.params.groups));var n=this.validator=new V(t,this,a);n.enableReactive(),n.setupScope(),this.anchor=e.createAnchor("vue-validator"),e.replace(this.el,this.anchor),this.insert(t),this.vm.$on("hook:compiled",function(){n.validate()})},insert:function(i){e.extend(this.vm.$options,{_validator:i}),this.factory=new a(this.vm,this.el.innerHTML),n.insert.call(this)},unbind:function(){n.unbind.call(this),this.validator.disableReactive(),this.validatorName&&(this.validatorName=null,this.validator=null)}})}function m(t){arguments.length<=1||void 0===arguments[1]?{}:arguments[1];return m.installed?void i("already installed."):(g.Vue=t,c(t),v(t),p(t),void f(t))}var y={};y["typeof"]=function(i){return i&&"undefined"!=typeof Symbol&&i.constructor===Symbol?"symbol":typeof i},y.classCallCheck=function(i,t){if(!(i instanceof t))throw new TypeError("Cannot call a class as a function")},y.createClass=function(){function i(i,t){for(var e=0;e0)return!1;if(0===i.length)return!0}else if(g.Vue.util.isPlainObject(i))for(var t in i)if(g.Vue.util.hasOwn(i,t))return!1;return!0}function e(i,t,e){if(Array.isArray(i))for(var a=0;a0:"number"==typeof i||"function"==typeof i?!0:"boolean"==typeof i?i:"string"==typeof i?i.length>0:null!==i&&"object"===("undefined"==typeof i?"undefined":y["typeof"](i))?Object.keys(i).length>0:null===i||void 0===i?!1:void 0}function s(i,t){if("string"!=typeof t)return!1;var e=t.match(new RegExp("^/(.*?)/([gimy]*)$"));return e?new RegExp(e[1],e[2]).test(i):!1}function o(i,t){return"string"==typeof i&&h(t,10)&&i.length>=parseInt(t,10)}function l(i,t){return"string"==typeof i&&h(t,10)&&i.length<=parseInt(t,10)}function u(i,t){return!isNaN(+i)&&!isNaN(+t)&&+i>=+t}function d(i,t){return!isNaN(+i)&&!isNaN(+t)&&+t>=+i}function h(i){return/^(-?[1-9]\d*|0)$/.test(i)}function v(i){i.config._assetTypes.push("validator");var t=Object.create(null);i.util.extend(t,_),i.options.validators=t;var e=i.config.optionMergeStrategies;e&&(e.validators=e.methods),i.validator=function(t,e){return e?void(i.options.validators[t]=e):i.options.validators[t]}}function c(i){var t=i.prototype._init;i.prototype._init=function(i){this._validatorMaps||(this._validatorMaps=Object.create(null)),t.call(this,i)};var e=i.prototype._destroy;i.prototype._destroy=function(){e.apply(this,arguments),this._validatorMaps=null}}function f(t){var a=t.util;t.directive("validate",{params:["group"],bind:function(){var t=this.vm,e=t.$options._validator;if(!e)return void i("TODO: should be implemented error message");var n=this.validator=this.vm._validatorMaps[e],r=this.validation=new b(this);n.addValidation(r),this.params.group&&n.addGroupValidation(this.params.group,r),this.on("blur",a.bind(this.validation.listener,this.validation)),this.on("input",a.bind(this.validation.listener,this.validation))},update:function(i,t){i&&(a.isPlainObject(i)?this.handleObject(i):Array.isArray(i)&&this.handleArray(i),this.validator.validate(this.validation))},handleArray:function(i){var t=this;e(i,function(i){t.validation.setValidation(i)},this)},handleObject:function(i){var t=this;e(i,function(i,e){if(a.isPlainObject(i)){if("rule"in i){var n="message"in i?i.message:null;t.validation.setValidation(e,i.rule,n)}}else t.validation.setValidation(e,i)},this)},unbind:function(){this.validator&&this.validation&&(this.params.group&&this.validator.removeGroupValidation(this.params.group,this.validation),this.validator.removeValidation(this.validation),this.validator=null,this.validation=null)}})}function p(t){var e=t.util,a=t.FragmentFactory,n=t.directive("if"),r=t.util.bind;t.elementDirective("validator",{params:["name","groups","lazy"],bind:function(){var t=this;if(!this.params.name)return void i("TODO: should be implemented validator:bind name params nothing error");var a=this.validatorName="$"+this.params.name;if(!this.vm._validatorMaps)return void i("TODO: should be implemented error message");var n=[];this.params.groups&&(e.isArray(this.params.groups)?n=this.params.groups:e.isPlainObject(this.params.groups)||"string"!=typeof this.params.groups||n.push(this.params.groups));var s=this.validator=new V(a,this,n);s.enableReactive(),s.setupScope(),s.waitFor(r(function(){t.render(s,a),s.validate()},this)),this.params.lazy||this.vm.$activateValidator()},render:function(i,t){this.anchor=e.createAnchor("vue-validator"),e.replace(this.el,this.anchor),this.insert(t)},insert:function(i){e.extend(this.vm.$options,{_validator:i}),this.factory=new a(this.vm,this.el.innerHTML),n.insert.call(this)},unbind:function(){n.unbind.call(this),this.validator.disableReactive(),this.validatorName&&(this.validatorName=null,this.validator=null)}})}function m(t){arguments.length<=1||void 0===arguments[1]?{}:arguments[1];return m.installed?void i("already installed."):(g.Vue=t,v(t),c(t),p(t),void f(t))}var y={};y["typeof"]=function(i){return i&&"undefined"!=typeof Symbol&&i.constructor===Symbol?"symbol":typeof i},y.classCallCheck=function(i,t){if(!(i instanceof t))throw new TypeError("Cannot call a class as a function")},y.createClass=function(){function i(i,t){for(var e=0;e