diff --git a/dist/vue-validator.common.js b/dist/vue-validator.common.js index 0f6cb50..49125a2 100644 --- a/dist/vue-validator.common.js +++ b/dist/vue-validator.common.js @@ -1,66 +1,10 @@ /*! * vue-validator v2.1.7 - * (c) 2016 kazuya kawaguchi + * (c) 2017 kazuya kawaguchi * Released under the MIT License. */ 'use strict'; -var babelHelpers = {}; -babelHelpers.typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { - return typeof obj; -} : function (obj) { - return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; -}; - -babelHelpers.classCallCheck = function (instance, Constructor) { - if (!(instance instanceof Constructor)) { - throw new TypeError("Cannot call a class as a function"); - } -}; - -babelHelpers.createClass = function () { - function defineProperties(target, props) { - for (var i = 0; i < props.length; i++) { - var descriptor = props[i]; - descriptor.enumerable = descriptor.enumerable || false; - descriptor.configurable = true; - if ("value" in descriptor) descriptor.writable = true; - Object.defineProperty(target, descriptor.key, descriptor); - } - } - - return function (Constructor, protoProps, staticProps) { - if (protoProps) defineProperties(Constructor.prototype, protoProps); - if (staticProps) defineProperties(Constructor, staticProps); - return Constructor; - }; -}(); - -babelHelpers.inherits = function (subClass, superClass) { - if (typeof superClass !== "function" && superClass !== null) { - throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); - } - - subClass.prototype = Object.create(superClass && superClass.prototype, { - constructor: { - value: subClass, - enumerable: false, - writable: true, - configurable: true - } - }); - if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; -}; - -babelHelpers.possibleConstructorReturn = function (self, call) { - if (!self) { - throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - } - - return call && (typeof call === "object" || typeof call === "function") ? call : self; -}; - -babelHelpers; /** * Utilties */ @@ -207,6 +151,173 @@ function toggleClasses(el, key, fn) { } } +var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { + return typeof obj; +} : function (obj) { + return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; +}; + +var asyncGenerator = function () { + function AwaitValue(value) { + this.value = value; + } + + function AsyncGenerator(gen) { + var front, back; + + function send(key, arg) { + return new Promise(function (resolve, reject) { + var request = { + key: key, + arg: arg, + resolve: resolve, + reject: reject, + next: null + }; + + if (back) { + back = back.next = request; + } else { + front = back = request; + resume(key, arg); + } + }); + } + + function resume(key, arg) { + try { + var result = gen[key](arg); + var value = result.value; + + if (value instanceof AwaitValue) { + Promise.resolve(value.value).then(function (arg) { + resume("next", arg); + }, function (arg) { + resume("throw", arg); + }); + } else { + settle(result.done ? "return" : "normal", result.value); + } + } catch (err) { + settle("throw", err); + } + } + + function settle(type, value) { + switch (type) { + case "return": + front.resolve({ + value: value, + done: true + }); + break; + + case "throw": + front.reject(value); + break; + + default: + front.resolve({ + value: value, + done: false + }); + break; + } + + front = front.next; + + if (front) { + resume(front.key, front.arg); + } else { + back = null; + } + } + + this._invoke = send; + + if (typeof gen.return !== "function") { + this.return = undefined; + } + } + + if (typeof Symbol === "function" && Symbol.asyncIterator) { + AsyncGenerator.prototype[Symbol.asyncIterator] = function () { + return this; + }; + } + + AsyncGenerator.prototype.next = function (arg) { + return this._invoke("next", arg); + }; + + AsyncGenerator.prototype.throw = function (arg) { + return this._invoke("throw", arg); + }; + + AsyncGenerator.prototype.return = function (arg) { + return this._invoke("return", arg); + }; + + return { + wrap: function (fn) { + return function () { + return new AsyncGenerator(fn.apply(this, arguments)); + }; + }, + await: function (value) { + return new AwaitValue(value); + } + }; +}(); + +var classCallCheck = function (instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } +}; + +var createClass = function () { + function defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } + } + + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; + }; +}(); + +var inherits = function (subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); + } + + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + enumerable: false, + writable: true, + configurable: true + } + }); + if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; +}; + +var possibleConstructorReturn = function (self, call) { + if (!self) { + throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + } + + return call && (typeof call === "object" || typeof call === "function") ? call : self; +}; + /** * Fundamental validate functions */ @@ -240,7 +351,7 @@ function required(val) { return val; } else if (typeof val === 'string') { return val.length > 0; - } else if (val !== null && (typeof val === 'undefined' ? 'undefined' : babelHelpers.typeof(val)) === 'object') { + } else if (val !== null && (typeof val === 'undefined' ? 'undefined' : _typeof(val)) === 'object') { return Object.keys(val).length > 0; } else if (val === null || val === undefined) { return false; @@ -353,6 +464,8 @@ function isInteger(val) { ); } + + var validators = Object.freeze({ required: required, pattern: pattern, @@ -436,10 +549,10 @@ var classId = 0; // ID for validation class function ValidateClass (Vue) { var vIf = Vue.directive('if'); var FragmentFactory = Vue.FragmentFactory; - var _Vue$util = Vue.util; - var toArray = _Vue$util.toArray; - var replace = _Vue$util.replace; - var createAnchor = _Vue$util.createAnchor; + var _Vue$util = Vue.util, + toArray = _Vue$util.toArray, + replace = _Vue$util.replace, + createAnchor = _Vue$util.createAnchor; /** * `v-validate-class` directive @@ -513,15 +626,15 @@ function ValidateClass (Vue) { function Validate (Vue) { var FragmentFactory = Vue.FragmentFactory; var parseDirective = Vue.parsers.directive.parseDirective; - var _Vue$util = Vue.util; - var inBrowser = _Vue$util.inBrowser; - var bind = _Vue$util.bind; - var on = _Vue$util.on; - var off = _Vue$util.off; - var createAnchor = _Vue$util.createAnchor; - var replace = _Vue$util.replace; - var camelize = _Vue$util.camelize; - var isPlainObject = _Vue$util.isPlainObject; + var _Vue$util = Vue.util, + inBrowser = _Vue$util.inBrowser, + bind = _Vue$util.bind, + on = _Vue$util.on, + off = _Vue$util.off, + createAnchor = _Vue$util.createAnchor, + replace = _Vue$util.replace, + camelize = _Vue$util.camelize, + isPlainObject = _Vue$util.isPlainObject; // Test for IE10/11 textarea placeholder clone bug @@ -593,10 +706,9 @@ function Validate (Vue) { var raw = el.getAttribute('v-model'); - var _parseModelRaw = this.parseModelRaw(raw); - - var model = _parseModelRaw.model; - var filters = _parseModelRaw.filters; + var _parseModelRaw = this.parseModelRaw(raw), + model = _parseModelRaw.model, + filters = _parseModelRaw.filters; this.model = model; @@ -792,7 +904,7 @@ function Validate (Vue) { var BaseValidation = function () { function BaseValidation(field, model, vm, el, scope, validator, filters, detectBlur, detectChange) { - babelHelpers.classCallCheck(this, BaseValidation); + classCallCheck(this, BaseValidation); this.field = field; this.touched = false; @@ -893,7 +1005,7 @@ var BaseValidation = function () { }; BaseValidation.prototype.willUpdateFlags = function willUpdateFlags() { - var touched = arguments.length <= 0 || arguments[0] === undefined ? false : arguments[0]; + var touched = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; touched && this.willUpdateTouched(this._el, 'blur'); this.willUpdateDirty(this._el); @@ -931,12 +1043,11 @@ var BaseValidation = function () { }; BaseValidation.prototype.handleValidate = function handleValidate(el) { - var _ref = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; - - var _ref$type = _ref.type; - var type = _ref$type === undefined ? null : _ref$type; - var _ref$noopable = _ref.noopable; - var noopable = _ref$noopable === undefined ? false : _ref$noopable; + var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + _ref$type = _ref.type, + type = _ref$type === undefined ? null : _ref$type, + _ref$noopable = _ref.noopable, + noopable = _ref$noopable === undefined ? false : _ref$noopable; this.willUpdateTouched(el, type); this.willUpdateDirty(el); @@ -948,8 +1059,8 @@ var BaseValidation = function () { BaseValidation.prototype.validate = function validate(cb) { var _this4 = this; - var noopable = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1]; - var el = arguments.length <= 2 || arguments[2] === undefined ? null : arguments[2]; + var noopable = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + var el = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; var _ = exports$1.Vue.util; @@ -1054,22 +1165,20 @@ var BaseValidation = function () { BaseValidation.prototype.willUpdateClasses = function willUpdateClasses(results) { var _this5 = this; - var el = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1]; + var el = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; if (this._checkClassIds(el)) { - (function () { - var classIds = _this5._getClassIds(el); - _this5.vm.$nextTick(function () { - _this5.vm.$emit(VALIDATE_UPDATE, classIds, _this5, results); - }); - })(); + var classIds = this._getClassIds(el); + this.vm.$nextTick(function () { + _this5.vm.$emit(VALIDATE_UPDATE, classIds, _this5, results); + }); } else { this.updateClasses(results); } }; BaseValidation.prototype.updateClasses = function updateClasses(results) { - var el = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1]; + var el = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; this._updateClasses(el || this._el, results); }; @@ -1139,9 +1248,9 @@ var BaseValidation = function () { }; BaseValidation.prototype._toggleValid = function _toggleValid(el, valid) { - var _util$Vue$util = exports$1.Vue.util; - var addClass = _util$Vue$util.addClass; - var removeClass = _util$Vue$util.removeClass; + var _util$Vue$util = exports$1.Vue.util, + addClass = _util$Vue$util.addClass, + removeClass = _util$Vue$util.removeClass; var validClass = this._classes.valid || 'valid'; var invalidClass = this._classes.invalid || 'invalid'; @@ -1156,9 +1265,9 @@ var BaseValidation = function () { }; BaseValidation.prototype._toggleTouched = function _toggleTouched(el, touched) { - var _util$Vue$util2 = exports$1.Vue.util; - var addClass = _util$Vue$util2.addClass; - var removeClass = _util$Vue$util2.removeClass; + var _util$Vue$util2 = exports$1.Vue.util, + addClass = _util$Vue$util2.addClass, + removeClass = _util$Vue$util2.removeClass; var touchedClass = this._classes.touched || 'touched'; var untouchedClass = this._classes.untouched || 'untouched'; @@ -1173,9 +1282,9 @@ var BaseValidation = function () { }; BaseValidation.prototype._togglePristine = function _togglePristine(el, pristine) { - var _util$Vue$util3 = exports$1.Vue.util; - var addClass = _util$Vue$util3.addClass; - var removeClass = _util$Vue$util3.removeClass; + var _util$Vue$util3 = exports$1.Vue.util, + addClass = _util$Vue$util3.addClass, + removeClass = _util$Vue$util3.removeClass; var pristineClass = this._classes.pristine || 'pristine'; var dirtyClass = this._classes.dirty || 'dirty'; @@ -1190,9 +1299,9 @@ var BaseValidation = function () { }; BaseValidation.prototype._toggleModfied = function _toggleModfied(el, modified) { - var _util$Vue$util4 = exports$1.Vue.util; - var addClass = _util$Vue$util4.addClass; - var removeClass = _util$Vue$util4.removeClass; + var _util$Vue$util4 = exports$1.Vue.util, + addClass = _util$Vue$util4.addClass, + removeClass = _util$Vue$util4.removeClass; var modifiedClass = this._classes.modified || 'modified'; @@ -1289,7 +1398,7 @@ var BaseValidation = function () { return resolveAsset(this._vm.$options, 'validators', name); }; - babelHelpers.createClass(BaseValidation, [{ + createClass(BaseValidation, [{ key: 'vm', get: function get() { return this._vm; @@ -1324,12 +1433,12 @@ var BaseValidation = function () { */ var CheckboxValidation = function (_BaseValidation) { - babelHelpers.inherits(CheckboxValidation, _BaseValidation); + inherits(CheckboxValidation, _BaseValidation); function CheckboxValidation(field, model, vm, el, scope, validator, filters, detectBlur, detectChange) { - babelHelpers.classCallCheck(this, CheckboxValidation); + classCallCheck(this, CheckboxValidation); - var _this = babelHelpers.possibleConstructorReturn(this, _BaseValidation.call(this, field, model, vm, el, scope, validator, filters, detectBlur, detectChange)); + var _this = possibleConstructorReturn(this, _BaseValidation.call(this, field, model, vm, el, scope, validator, filters, detectBlur, detectChange)); _this._inits = []; return _this; @@ -1408,7 +1517,7 @@ var CheckboxValidation = function (_BaseValidation) { CheckboxValidation.prototype.willUpdateFlags = function willUpdateFlags() { var _this3 = this; - var touched = arguments.length <= 0 || arguments[0] === undefined ? false : arguments[0]; + var touched = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; each(this._inits, function (item, index) { touched && _this3.willUpdateTouched(item.el, 'blur'); @@ -1429,7 +1538,7 @@ var CheckboxValidation = function (_BaseValidation) { CheckboxValidation.prototype.updateClasses = function updateClasses(results) { var _this4 = this; - var el = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1]; + var el = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; if (el) { // for another element @@ -1469,22 +1578,14 @@ var CheckboxValidation = function (_BaseValidation) { }; CheckboxValidation.prototype._getValue = function _getValue(el) { - var _this5 = this; - if (!this._inits || this._inits.length === 0) { return el.checked; } else { - var _ret = function () { - var vals = []; - each(_this5._inits, function (item, index) { - item.el.checked && vals.push(item.el.value); - }); - return { - v: vals - }; - }(); - - if ((typeof _ret === 'undefined' ? 'undefined' : babelHelpers.typeof(_ret)) === "object") return _ret.v; + var vals = []; + each(this._inits, function (item, index) { + item.el.checked && vals.push(item.el.value); + }); + return vals; } }; @@ -1499,24 +1600,16 @@ var CheckboxValidation = function (_BaseValidation) { }; CheckboxValidation.prototype._checkModified = function _checkModified(target) { - var _this6 = this; - if (this._inits.length === 0) { return this._init !== target.checked; } else { - var _ret2 = function () { - var modified = false; - each(_this6._inits, function (item, index) { - if (!modified) { - modified = item.init !== item.el.checked; - } - }); - return { - v: modified - }; - }(); - - if ((typeof _ret2 === 'undefined' ? 'undefined' : babelHelpers.typeof(_ret2)) === "object") return _ret2.v; + var modified = false; + each(this._inits, function (item, index) { + if (!modified) { + modified = item.init !== item.el.checked; + } + }); + return modified; } }; @@ -1528,12 +1621,12 @@ var CheckboxValidation = function (_BaseValidation) { */ var RadioValidation = function (_BaseValidation) { - babelHelpers.inherits(RadioValidation, _BaseValidation); + inherits(RadioValidation, _BaseValidation); function RadioValidation(field, model, vm, el, scope, validator, filters, detectBlur, detectChange) { - babelHelpers.classCallCheck(this, RadioValidation); + classCallCheck(this, RadioValidation); - var _this = babelHelpers.possibleConstructorReturn(this, _BaseValidation.call(this, field, model, vm, el, scope, validator, filters, detectBlur, detectChange)); + var _this = possibleConstructorReturn(this, _BaseValidation.call(this, field, model, vm, el, scope, validator, filters, detectBlur, detectChange)); _this._inits = []; return _this; @@ -1588,7 +1681,7 @@ var RadioValidation = function (_BaseValidation) { RadioValidation.prototype.willUpdateFlags = function willUpdateFlags() { var _this3 = this; - var touched = arguments.length <= 0 || arguments[0] === undefined ? false : arguments[0]; + var touched = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; each(this._inits, function (item, index) { touched && _this3.willUpdateTouched(item.el, 'blur'); @@ -1609,7 +1702,7 @@ var RadioValidation = function (_BaseValidation) { RadioValidation.prototype.updateClasses = function updateClasses(results) { var _this4 = this; - var el = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1]; + var el = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; if (el) { // for another element @@ -1649,22 +1742,14 @@ var RadioValidation = function (_BaseValidation) { }; RadioValidation.prototype._getValue = function _getValue(el) { - var _this5 = this; - if (!this._inits || this._inits.length === 0) { return el.checked; } else { - var _ret = function () { - var vals = []; - each(_this5._inits, function (item, index) { - item.el.checked && vals.push(item.el.value); - }); - return { - v: vals - }; - }(); - - if ((typeof _ret === 'undefined' ? 'undefined' : babelHelpers.typeof(_ret)) === "object") return _ret.v; + var vals = []; + each(this._inits, function (item, index) { + item.el.checked && vals.push(item.el.value); + }); + return vals; } }; @@ -1679,24 +1764,16 @@ var RadioValidation = function (_BaseValidation) { }; RadioValidation.prototype._checkModified = function _checkModified(target) { - var _this6 = this; - if (this._inits.length === 0) { return this._init !== target.checked; } else { - var _ret2 = function () { - var modified = false; - each(_this6._inits, function (item, index) { - if (!modified) { - modified = item.init !== item.el.checked; - } - }); - return { - v: modified - }; - }(); - - if ((typeof _ret2 === 'undefined' ? 'undefined' : babelHelpers.typeof(_ret2)) === "object") return _ret2.v; + var modified = false; + each(this._inits, function (item, index) { + if (!modified) { + modified = item.init !== item.el.checked; + } + }); + return modified; } }; @@ -1708,12 +1785,12 @@ var RadioValidation = function (_BaseValidation) { */ var SelectValidation = function (_BaseValidation) { - babelHelpers.inherits(SelectValidation, _BaseValidation); + inherits(SelectValidation, _BaseValidation); function SelectValidation(field, model, vm, el, scope, validator, filters, detectBlur, detectChange) { - babelHelpers.classCallCheck(this, SelectValidation); + classCallCheck(this, SelectValidation); - var _this = babelHelpers.possibleConstructorReturn(this, _BaseValidation.call(this, field, model, vm, el, scope, validator, filters, detectBlur, detectChange)); + var _this = possibleConstructorReturn(this, _BaseValidation.call(this, field, model, vm, el, scope, validator, filters, detectBlur, detectChange)); _this._multiple = _this._el.hasAttribute('multiple'); return _this; @@ -1804,7 +1881,7 @@ var Validator$1 = function () { function Validator(name, dir, groups, classes) { var _this = this; - babelHelpers.classCallCheck(this, Validator); + classCallCheck(this, Validator); this.name = name; @@ -1834,6 +1911,9 @@ var Validator$1 = function () { // define the validation resetting meta method to vue instance this._defineResetValidation(); + // define the validation resetting for a single field + this._defineResetField(); + // define the validate manually meta method to vue instance this._defineValidate(); @@ -1849,6 +1929,8 @@ var Validator$1 = function () { delete vm['$validate']; vm.$resetValidation = null; delete vm['$resetValidation']; + vm.$resetField = null; + delete vm['$resetField']; vm._validatorMaps[this.name] = null; delete vm._validatorMaps[this.name]; vm[this.name] = null; @@ -1928,18 +2010,17 @@ var Validator$1 = function () { }; Validator.prototype.validate = function validate() { - var _ref = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; - - var _ref$el = _ref.el; - var el = _ref$el === undefined ? null : _ref$el; - var _ref$field = _ref.field; - var field = _ref$field === undefined ? null : _ref$field; - var _ref$touched = _ref.touched; - var touched = _ref$touched === undefined ? false : _ref$touched; - var _ref$noopable = _ref.noopable; - var noopable = _ref$noopable === undefined ? false : _ref$noopable; - var _ref$cb = _ref.cb; - var cb = _ref$cb === undefined ? null : _ref$cb; + var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, + _ref$el = _ref.el, + el = _ref$el === undefined ? null : _ref$el, + _ref$field = _ref.field, + field = _ref$field === undefined ? null : _ref$field, + _ref$touched = _ref.touched, + touched = _ref$touched === undefined ? false : _ref$touched, + _ref$noopable = _ref.noopable, + noopable = _ref$noopable === undefined ? false : _ref$noopable, + _ref$cb = _ref.cb, + cb = _ref$cb === undefined ? null : _ref$cb; if (!field) { // all @@ -1992,14 +2073,37 @@ var Validator$1 = function () { }; }; - Validator.prototype._defineValidate = function _defineValidate() { + Validator.prototype._defineResetField = function _defineResetField() { var _this5 = this; - this._dir.vm.$validate = function () { + this._dir.vm.$resetField = function () { for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } + var field = null; + var cb = null; + + each(args, function (arg, index) { + if (typeof arg === 'string') { + field = arg; + } else if (typeof arg === 'function') { + cb = arg; + } + }); + + _this5._resetField(field, cb); + }; + }; + + Validator.prototype._defineValidate = function _defineValidate() { + var _this6 = this; + + this._dir.vm.$validate = function () { + for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { + args[_key2] = arguments[_key2]; + } + var field = null; var touched = false; var cb = null; @@ -2014,26 +2118,26 @@ var Validator$1 = function () { } }); - _this5.validate({ field: field, touched: touched, cb: cb }); + _this6.validate({ field: field, touched: touched, cb: cb }); }; }; Validator.prototype._defineSetValidationErrors = function _defineSetValidationErrors() { - var _this6 = this; + var _this7 = this; this._dir.vm.$setValidationErrors = function (errors) { - _this6._setValidationErrors(errors); + _this7._setValidationErrors(errors); }; }; Validator.prototype._validate = function _validate(field) { - var touched = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1]; - var noopable = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2]; + var touched = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + var noopable = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; - var _this7 = this; + var _this8 = this; - var el = arguments.length <= 3 || arguments[3] === undefined ? null : arguments[3]; - var cb = arguments.length <= 4 || arguments[4] === undefined ? null : arguments[4]; + var el = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null; + var cb = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null; var scope = this._scope; @@ -2042,14 +2146,14 @@ var Validator$1 = function () { validation.willUpdateFlags(touched); validation.validate(function (results) { exports$1.Vue.set(scope, field, results); - _this7._fireEvents(); + _this8._fireEvents(); cb && cb(); }, noopable, el); } }; Validator.prototype._validates = function _validates(cb) { - var _this8 = this; + var _this9 = this; var scope = this._scope; @@ -2060,7 +2164,7 @@ var Validator$1 = function () { }); }, function () { // finished - _this8._fireEvents(); + _this9._fireEvents(); cb && cb(); }); }; @@ -2069,6 +2173,14 @@ var Validator$1 = function () { return this._validations[field] || this._checkboxValidations[field] && this._checkboxValidations[field].validation || this._radioValidations[field] && this._radioValidations[field].validation; }; + Validator.prototype._resetField = function _resetField(field, cb) { + var validation = this._getValidationFrom(field); + if (validation) { + validation.reset(); + } + this._validates(cb); + }; + Validator.prototype._resetValidation = function _resetValidation(cb) { each(this.validations, function (validation, key) { validation.reset(); @@ -2077,7 +2189,7 @@ var Validator$1 = function () { }; Validator.prototype._setValidationErrors = function _setValidationErrors(errors) { - var _this9 = this; + var _this10 = this; var extend = exports$1.Vue.util.extend; @@ -2093,7 +2205,7 @@ var Validator$1 = function () { // set errors each(temp, function (values, field) { - var results = _this9._scope[field]; + var results = _this10._scope[field]; var newResults = {}; each(values, function (error) { @@ -2107,10 +2219,10 @@ var Validator$1 = function () { results.errors = values; extend(newResults, results); - var validation = _this9._getValidationFrom(field); + var validation = _this10._getValidationFrom(field); validation.willUpdateClasses(newResults, validation.el); - exports$1.Vue.set(_this9._scope, field, newResults); + exports$1.Vue.set(_this10._scope, field, newResults); }); }; @@ -2199,8 +2311,8 @@ var Validator$1 = function () { }; Validator.prototype._fireEvent = function _fireEvent(type) { - for (var _len2 = arguments.length, args = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { - args[_key2 - 1] = arguments[_key2]; + for (var _len3 = arguments.length, args = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { + args[_key3 - 1] = arguments[_key3]; } var handler = this._events[this._getEventName(type)]; @@ -2229,7 +2341,7 @@ var Validator$1 = function () { }; Validator.prototype._defineProperties = function _defineProperties(validationsGetter, targetGetter) { - var _this10 = this; + var _this11 = this; var bind = exports$1.Vue.util.bind; @@ -2247,7 +2359,7 @@ var Validator$1 = function () { enumerable: true, configurable: true, get: function get() { - return bind(descriptor.fn, _this10)(descriptor.arg); + return bind(descriptor.fn, _this11)(descriptor.arg); } }); }); @@ -2266,7 +2378,7 @@ var Validator$1 = function () { }; Validator.prototype._walkValidations = function _walkValidations(validations, property, condition) { - var _this11 = this; + var _this12 = this; var hasOwn = exports$1.Vue.util.hasOwn; var ret = condition; @@ -2275,8 +2387,8 @@ var Validator$1 = function () { if (ret === !condition) { return; } - if (hasOwn(_this11._scope, validation.field)) { - var target = _this11._scope[validation.field]; + if (hasOwn(_this12._scope, validation.field)) { + var target = _this12._scope[validation.field]; if (target && target[property] === !condition) { ret = !condition; } @@ -2315,15 +2427,15 @@ var Validator$1 = function () { }; Validator.prototype._defineErrors = function _defineErrors(validationsGetter) { - var _this12 = this; + var _this13 = this; var hasOwn = exports$1.Vue.util.hasOwn; var isPlainObject = exports$1.Vue.util.isPlainObject; var errors = []; each(validationsGetter(), function (validation, key) { - if (hasOwn(_this12._scope, validation.field)) { - var target = _this12._scope[validation.field]; + if (hasOwn(_this13._scope, validation.field)) { + var target = _this13._scope[validation.field]; if (target && !empty(target.errors)) { each(target.errors, function (err, index) { var error = { field: validation.field }; @@ -2346,7 +2458,7 @@ var Validator$1 = function () { }); }; - babelHelpers.createClass(Validator, [{ + createClass(Validator, [{ key: 'validations', get: function get() { var extend = exports$1.Vue.util.extend; @@ -2371,13 +2483,13 @@ var Validator$1 = function () { function Validator (Vue) { var FragmentFactory = Vue.FragmentFactory; var vIf = Vue.directive('if'); - var _Vue$util = Vue.util; - var isArray = _Vue$util.isArray; - var isPlainObject = _Vue$util.isPlainObject; - var createAnchor = _Vue$util.createAnchor; - var replace = _Vue$util.replace; - var extend = _Vue$util.extend; - var camelize = _Vue$util.camelize; + var _Vue$util = Vue.util, + isArray = _Vue$util.isArray, + isPlainObject = _Vue$util.isPlainObject, + createAnchor = _Vue$util.createAnchor, + replace = _Vue$util.replace, + extend = _Vue$util.extend, + camelize = _Vue$util.camelize; /** * `validator` element directive @@ -2490,10 +2602,9 @@ function ValidatorError (Vue) { template: '
', partials: {} - }; - // only use ValidatorError component - error.partials['validator-error-default'] = '

{{field}}: {{message}}

'; + // only use ValidatorError component + };error.partials['validator-error-default'] = '

{{field}}: {{message}}

'; return error; } @@ -2561,10 +2672,9 @@ function Errors (Vue) { template: '', components: {} - }; - // define 'partial' prop - errors.props['partial'] = error.props['partial']; + // define 'partial' prop + };errors.props['partial'] = error.props['partial']; // only use ValidatorErrors component errors.components[error.name] = error; @@ -2583,7 +2693,7 @@ function Errors (Vue) { */ function plugin(Vue) { - var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; if (plugin.installed) { warn('already installed.'); diff --git a/dist/vue-validator.js b/dist/vue-validator.js index 3551df0..5dd6b9e 100644 --- a/dist/vue-validator.js +++ b/dist/vue-validator.js @@ -1,6 +1,6 @@ /*! * vue-validator v2.1.7 - * (c) 2016 kazuya kawaguchi + * (c) 2017 kazuya kawaguchi * Released under the MIT License. */ (function (global, factory) { @@ -9,62 +9,6 @@ (global.VueValidator = factory()); }(this, function () { 'use strict'; - var babelHelpers = {}; - babelHelpers.typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { - return typeof obj; - } : function (obj) { - return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; - }; - - babelHelpers.classCallCheck = function (instance, Constructor) { - if (!(instance instanceof Constructor)) { - throw new TypeError("Cannot call a class as a function"); - } - }; - - babelHelpers.createClass = function () { - function defineProperties(target, props) { - for (var i = 0; i < props.length; i++) { - var descriptor = props[i]; - descriptor.enumerable = descriptor.enumerable || false; - descriptor.configurable = true; - if ("value" in descriptor) descriptor.writable = true; - Object.defineProperty(target, descriptor.key, descriptor); - } - } - - return function (Constructor, protoProps, staticProps) { - if (protoProps) defineProperties(Constructor.prototype, protoProps); - if (staticProps) defineProperties(Constructor, staticProps); - return Constructor; - }; - }(); - - babelHelpers.inherits = function (subClass, superClass) { - if (typeof superClass !== "function" && superClass !== null) { - throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); - } - - subClass.prototype = Object.create(superClass && superClass.prototype, { - constructor: { - value: subClass, - enumerable: false, - writable: true, - configurable: true - } - }); - if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; - }; - - babelHelpers.possibleConstructorReturn = function (self, call) { - if (!self) { - throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - } - - return call && (typeof call === "object" || typeof call === "function") ? call : self; - }; - - babelHelpers; /** * Utilties */ @@ -211,6 +155,173 @@ } } + var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { + return typeof obj; + } : function (obj) { + return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; + }; + + var asyncGenerator = function () { + function AwaitValue(value) { + this.value = value; + } + + function AsyncGenerator(gen) { + var front, back; + + function send(key, arg) { + return new Promise(function (resolve, reject) { + var request = { + key: key, + arg: arg, + resolve: resolve, + reject: reject, + next: null + }; + + if (back) { + back = back.next = request; + } else { + front = back = request; + resume(key, arg); + } + }); + } + + function resume(key, arg) { + try { + var result = gen[key](arg); + var value = result.value; + + if (value instanceof AwaitValue) { + Promise.resolve(value.value).then(function (arg) { + resume("next", arg); + }, function (arg) { + resume("throw", arg); + }); + } else { + settle(result.done ? "return" : "normal", result.value); + } + } catch (err) { + settle("throw", err); + } + } + + function settle(type, value) { + switch (type) { + case "return": + front.resolve({ + value: value, + done: true + }); + break; + + case "throw": + front.reject(value); + break; + + default: + front.resolve({ + value: value, + done: false + }); + break; + } + + front = front.next; + + if (front) { + resume(front.key, front.arg); + } else { + back = null; + } + } + + this._invoke = send; + + if (typeof gen.return !== "function") { + this.return = undefined; + } + } + + if (typeof Symbol === "function" && Symbol.asyncIterator) { + AsyncGenerator.prototype[Symbol.asyncIterator] = function () { + return this; + }; + } + + AsyncGenerator.prototype.next = function (arg) { + return this._invoke("next", arg); + }; + + AsyncGenerator.prototype.throw = function (arg) { + return this._invoke("throw", arg); + }; + + AsyncGenerator.prototype.return = function (arg) { + return this._invoke("return", arg); + }; + + return { + wrap: function (fn) { + return function () { + return new AsyncGenerator(fn.apply(this, arguments)); + }; + }, + await: function (value) { + return new AwaitValue(value); + } + }; + }(); + + var classCallCheck = function (instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + }; + + var createClass = function () { + function defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } + } + + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; + }; + }(); + + var inherits = function (subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); + } + + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + enumerable: false, + writable: true, + configurable: true + } + }); + if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; + }; + + var possibleConstructorReturn = function (self, call) { + if (!self) { + throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + } + + return call && (typeof call === "object" || typeof call === "function") ? call : self; + }; + /** * Fundamental validate functions */ @@ -244,7 +355,7 @@ return val; } else if (typeof val === 'string') { return val.length > 0; - } else if (val !== null && (typeof val === 'undefined' ? 'undefined' : babelHelpers.typeof(val)) === 'object') { + } else if (val !== null && (typeof val === 'undefined' ? 'undefined' : _typeof(val)) === 'object') { return Object.keys(val).length > 0; } else if (val === null || val === undefined) { return false; @@ -357,7 +468,9 @@ ); } -var validators = Object.freeze({ + + + var validators = Object.freeze({ required: required, pattern: pattern, minlength: minlength, @@ -440,10 +553,10 @@ var validators = Object.freeze({ function ValidateClass (Vue) { var vIf = Vue.directive('if'); var FragmentFactory = Vue.FragmentFactory; - var _Vue$util = Vue.util; - var toArray = _Vue$util.toArray; - var replace = _Vue$util.replace; - var createAnchor = _Vue$util.createAnchor; + var _Vue$util = Vue.util, + toArray = _Vue$util.toArray, + replace = _Vue$util.replace, + createAnchor = _Vue$util.createAnchor; /** * `v-validate-class` directive @@ -517,15 +630,15 @@ var validators = Object.freeze({ function Validate (Vue) { var FragmentFactory = Vue.FragmentFactory; var parseDirective = Vue.parsers.directive.parseDirective; - var _Vue$util = Vue.util; - var inBrowser = _Vue$util.inBrowser; - var bind = _Vue$util.bind; - var on = _Vue$util.on; - var off = _Vue$util.off; - var createAnchor = _Vue$util.createAnchor; - var replace = _Vue$util.replace; - var camelize = _Vue$util.camelize; - var isPlainObject = _Vue$util.isPlainObject; + var _Vue$util = Vue.util, + inBrowser = _Vue$util.inBrowser, + bind = _Vue$util.bind, + on = _Vue$util.on, + off = _Vue$util.off, + createAnchor = _Vue$util.createAnchor, + replace = _Vue$util.replace, + camelize = _Vue$util.camelize, + isPlainObject = _Vue$util.isPlainObject; // Test for IE10/11 textarea placeholder clone bug @@ -597,10 +710,9 @@ var validators = Object.freeze({ var raw = el.getAttribute('v-model'); - var _parseModelRaw = this.parseModelRaw(raw); - - var model = _parseModelRaw.model; - var filters = _parseModelRaw.filters; + var _parseModelRaw = this.parseModelRaw(raw), + model = _parseModelRaw.model, + filters = _parseModelRaw.filters; this.model = model; @@ -796,7 +908,7 @@ var validators = Object.freeze({ var BaseValidation = function () { function BaseValidation(field, model, vm, el, scope, validator, filters, detectBlur, detectChange) { - babelHelpers.classCallCheck(this, BaseValidation); + classCallCheck(this, BaseValidation); this.field = field; this.touched = false; @@ -897,7 +1009,7 @@ var validators = Object.freeze({ }; BaseValidation.prototype.willUpdateFlags = function willUpdateFlags() { - var touched = arguments.length <= 0 || arguments[0] === undefined ? false : arguments[0]; + var touched = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; touched && this.willUpdateTouched(this._el, 'blur'); this.willUpdateDirty(this._el); @@ -935,12 +1047,11 @@ var validators = Object.freeze({ }; BaseValidation.prototype.handleValidate = function handleValidate(el) { - var _ref = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; - - var _ref$type = _ref.type; - var type = _ref$type === undefined ? null : _ref$type; - var _ref$noopable = _ref.noopable; - var noopable = _ref$noopable === undefined ? false : _ref$noopable; + var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + _ref$type = _ref.type, + type = _ref$type === undefined ? null : _ref$type, + _ref$noopable = _ref.noopable, + noopable = _ref$noopable === undefined ? false : _ref$noopable; this.willUpdateTouched(el, type); this.willUpdateDirty(el); @@ -952,8 +1063,8 @@ var validators = Object.freeze({ BaseValidation.prototype.validate = function validate(cb) { var _this4 = this; - var noopable = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1]; - var el = arguments.length <= 2 || arguments[2] === undefined ? null : arguments[2]; + var noopable = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + var el = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; var _ = exports$1.Vue.util; @@ -1058,22 +1169,20 @@ var validators = Object.freeze({ BaseValidation.prototype.willUpdateClasses = function willUpdateClasses(results) { var _this5 = this; - var el = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1]; + var el = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; if (this._checkClassIds(el)) { - (function () { - var classIds = _this5._getClassIds(el); - _this5.vm.$nextTick(function () { - _this5.vm.$emit(VALIDATE_UPDATE, classIds, _this5, results); - }); - })(); + var classIds = this._getClassIds(el); + this.vm.$nextTick(function () { + _this5.vm.$emit(VALIDATE_UPDATE, classIds, _this5, results); + }); } else { this.updateClasses(results); } }; BaseValidation.prototype.updateClasses = function updateClasses(results) { - var el = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1]; + var el = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; this._updateClasses(el || this._el, results); }; @@ -1143,9 +1252,9 @@ var validators = Object.freeze({ }; BaseValidation.prototype._toggleValid = function _toggleValid(el, valid) { - var _util$Vue$util = exports$1.Vue.util; - var addClass = _util$Vue$util.addClass; - var removeClass = _util$Vue$util.removeClass; + var _util$Vue$util = exports$1.Vue.util, + addClass = _util$Vue$util.addClass, + removeClass = _util$Vue$util.removeClass; var validClass = this._classes.valid || 'valid'; var invalidClass = this._classes.invalid || 'invalid'; @@ -1160,9 +1269,9 @@ var validators = Object.freeze({ }; BaseValidation.prototype._toggleTouched = function _toggleTouched(el, touched) { - var _util$Vue$util2 = exports$1.Vue.util; - var addClass = _util$Vue$util2.addClass; - var removeClass = _util$Vue$util2.removeClass; + var _util$Vue$util2 = exports$1.Vue.util, + addClass = _util$Vue$util2.addClass, + removeClass = _util$Vue$util2.removeClass; var touchedClass = this._classes.touched || 'touched'; var untouchedClass = this._classes.untouched || 'untouched'; @@ -1177,9 +1286,9 @@ var validators = Object.freeze({ }; BaseValidation.prototype._togglePristine = function _togglePristine(el, pristine) { - var _util$Vue$util3 = exports$1.Vue.util; - var addClass = _util$Vue$util3.addClass; - var removeClass = _util$Vue$util3.removeClass; + var _util$Vue$util3 = exports$1.Vue.util, + addClass = _util$Vue$util3.addClass, + removeClass = _util$Vue$util3.removeClass; var pristineClass = this._classes.pristine || 'pristine'; var dirtyClass = this._classes.dirty || 'dirty'; @@ -1194,9 +1303,9 @@ var validators = Object.freeze({ }; BaseValidation.prototype._toggleModfied = function _toggleModfied(el, modified) { - var _util$Vue$util4 = exports$1.Vue.util; - var addClass = _util$Vue$util4.addClass; - var removeClass = _util$Vue$util4.removeClass; + var _util$Vue$util4 = exports$1.Vue.util, + addClass = _util$Vue$util4.addClass, + removeClass = _util$Vue$util4.removeClass; var modifiedClass = this._classes.modified || 'modified'; @@ -1293,7 +1402,7 @@ var validators = Object.freeze({ return resolveAsset(this._vm.$options, 'validators', name); }; - babelHelpers.createClass(BaseValidation, [{ + createClass(BaseValidation, [{ key: 'vm', get: function get() { return this._vm; @@ -1328,12 +1437,12 @@ var validators = Object.freeze({ */ var CheckboxValidation = function (_BaseValidation) { - babelHelpers.inherits(CheckboxValidation, _BaseValidation); + inherits(CheckboxValidation, _BaseValidation); function CheckboxValidation(field, model, vm, el, scope, validator, filters, detectBlur, detectChange) { - babelHelpers.classCallCheck(this, CheckboxValidation); + classCallCheck(this, CheckboxValidation); - var _this = babelHelpers.possibleConstructorReturn(this, _BaseValidation.call(this, field, model, vm, el, scope, validator, filters, detectBlur, detectChange)); + var _this = possibleConstructorReturn(this, _BaseValidation.call(this, field, model, vm, el, scope, validator, filters, detectBlur, detectChange)); _this._inits = []; return _this; @@ -1412,7 +1521,7 @@ var validators = Object.freeze({ CheckboxValidation.prototype.willUpdateFlags = function willUpdateFlags() { var _this3 = this; - var touched = arguments.length <= 0 || arguments[0] === undefined ? false : arguments[0]; + var touched = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; each(this._inits, function (item, index) { touched && _this3.willUpdateTouched(item.el, 'blur'); @@ -1433,7 +1542,7 @@ var validators = Object.freeze({ CheckboxValidation.prototype.updateClasses = function updateClasses(results) { var _this4 = this; - var el = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1]; + var el = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; if (el) { // for another element @@ -1473,22 +1582,14 @@ var validators = Object.freeze({ }; CheckboxValidation.prototype._getValue = function _getValue(el) { - var _this5 = this; - if (!this._inits || this._inits.length === 0) { return el.checked; } else { - var _ret = function () { - var vals = []; - each(_this5._inits, function (item, index) { - item.el.checked && vals.push(item.el.value); - }); - return { - v: vals - }; - }(); - - if ((typeof _ret === 'undefined' ? 'undefined' : babelHelpers.typeof(_ret)) === "object") return _ret.v; + var vals = []; + each(this._inits, function (item, index) { + item.el.checked && vals.push(item.el.value); + }); + return vals; } }; @@ -1503,24 +1604,16 @@ var validators = Object.freeze({ }; CheckboxValidation.prototype._checkModified = function _checkModified(target) { - var _this6 = this; - if (this._inits.length === 0) { return this._init !== target.checked; } else { - var _ret2 = function () { - var modified = false; - each(_this6._inits, function (item, index) { - if (!modified) { - modified = item.init !== item.el.checked; - } - }); - return { - v: modified - }; - }(); - - if ((typeof _ret2 === 'undefined' ? 'undefined' : babelHelpers.typeof(_ret2)) === "object") return _ret2.v; + var modified = false; + each(this._inits, function (item, index) { + if (!modified) { + modified = item.init !== item.el.checked; + } + }); + return modified; } }; @@ -1532,12 +1625,12 @@ var validators = Object.freeze({ */ var RadioValidation = function (_BaseValidation) { - babelHelpers.inherits(RadioValidation, _BaseValidation); + inherits(RadioValidation, _BaseValidation); function RadioValidation(field, model, vm, el, scope, validator, filters, detectBlur, detectChange) { - babelHelpers.classCallCheck(this, RadioValidation); + classCallCheck(this, RadioValidation); - var _this = babelHelpers.possibleConstructorReturn(this, _BaseValidation.call(this, field, model, vm, el, scope, validator, filters, detectBlur, detectChange)); + var _this = possibleConstructorReturn(this, _BaseValidation.call(this, field, model, vm, el, scope, validator, filters, detectBlur, detectChange)); _this._inits = []; return _this; @@ -1592,7 +1685,7 @@ var validators = Object.freeze({ RadioValidation.prototype.willUpdateFlags = function willUpdateFlags() { var _this3 = this; - var touched = arguments.length <= 0 || arguments[0] === undefined ? false : arguments[0]; + var touched = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; each(this._inits, function (item, index) { touched && _this3.willUpdateTouched(item.el, 'blur'); @@ -1613,7 +1706,7 @@ var validators = Object.freeze({ RadioValidation.prototype.updateClasses = function updateClasses(results) { var _this4 = this; - var el = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1]; + var el = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; if (el) { // for another element @@ -1653,22 +1746,14 @@ var validators = Object.freeze({ }; RadioValidation.prototype._getValue = function _getValue(el) { - var _this5 = this; - if (!this._inits || this._inits.length === 0) { return el.checked; } else { - var _ret = function () { - var vals = []; - each(_this5._inits, function (item, index) { - item.el.checked && vals.push(item.el.value); - }); - return { - v: vals - }; - }(); - - if ((typeof _ret === 'undefined' ? 'undefined' : babelHelpers.typeof(_ret)) === "object") return _ret.v; + var vals = []; + each(this._inits, function (item, index) { + item.el.checked && vals.push(item.el.value); + }); + return vals; } }; @@ -1683,24 +1768,16 @@ var validators = Object.freeze({ }; RadioValidation.prototype._checkModified = function _checkModified(target) { - var _this6 = this; - if (this._inits.length === 0) { return this._init !== target.checked; } else { - var _ret2 = function () { - var modified = false; - each(_this6._inits, function (item, index) { - if (!modified) { - modified = item.init !== item.el.checked; - } - }); - return { - v: modified - }; - }(); - - if ((typeof _ret2 === 'undefined' ? 'undefined' : babelHelpers.typeof(_ret2)) === "object") return _ret2.v; + var modified = false; + each(this._inits, function (item, index) { + if (!modified) { + modified = item.init !== item.el.checked; + } + }); + return modified; } }; @@ -1712,12 +1789,12 @@ var validators = Object.freeze({ */ var SelectValidation = function (_BaseValidation) { - babelHelpers.inherits(SelectValidation, _BaseValidation); + inherits(SelectValidation, _BaseValidation); function SelectValidation(field, model, vm, el, scope, validator, filters, detectBlur, detectChange) { - babelHelpers.classCallCheck(this, SelectValidation); + classCallCheck(this, SelectValidation); - var _this = babelHelpers.possibleConstructorReturn(this, _BaseValidation.call(this, field, model, vm, el, scope, validator, filters, detectBlur, detectChange)); + var _this = possibleConstructorReturn(this, _BaseValidation.call(this, field, model, vm, el, scope, validator, filters, detectBlur, detectChange)); _this._multiple = _this._el.hasAttribute('multiple'); return _this; @@ -1808,7 +1885,7 @@ var validators = Object.freeze({ function Validator(name, dir, groups, classes) { var _this = this; - babelHelpers.classCallCheck(this, Validator); + classCallCheck(this, Validator); this.name = name; @@ -1838,6 +1915,9 @@ var validators = Object.freeze({ // define the validation resetting meta method to vue instance this._defineResetValidation(); + // define the validation resetting for a single field + this._defineResetField(); + // define the validate manually meta method to vue instance this._defineValidate(); @@ -1853,6 +1933,8 @@ var validators = Object.freeze({ delete vm['$validate']; vm.$resetValidation = null; delete vm['$resetValidation']; + vm.$resetField = null; + delete vm['$resetField']; vm._validatorMaps[this.name] = null; delete vm._validatorMaps[this.name]; vm[this.name] = null; @@ -1932,18 +2014,17 @@ var validators = Object.freeze({ }; Validator.prototype.validate = function validate() { - var _ref = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; - - var _ref$el = _ref.el; - var el = _ref$el === undefined ? null : _ref$el; - var _ref$field = _ref.field; - var field = _ref$field === undefined ? null : _ref$field; - var _ref$touched = _ref.touched; - var touched = _ref$touched === undefined ? false : _ref$touched; - var _ref$noopable = _ref.noopable; - var noopable = _ref$noopable === undefined ? false : _ref$noopable; - var _ref$cb = _ref.cb; - var cb = _ref$cb === undefined ? null : _ref$cb; + var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, + _ref$el = _ref.el, + el = _ref$el === undefined ? null : _ref$el, + _ref$field = _ref.field, + field = _ref$field === undefined ? null : _ref$field, + _ref$touched = _ref.touched, + touched = _ref$touched === undefined ? false : _ref$touched, + _ref$noopable = _ref.noopable, + noopable = _ref$noopable === undefined ? false : _ref$noopable, + _ref$cb = _ref.cb, + cb = _ref$cb === undefined ? null : _ref$cb; if (!field) { // all @@ -1996,14 +2077,37 @@ var validators = Object.freeze({ }; }; - Validator.prototype._defineValidate = function _defineValidate() { + Validator.prototype._defineResetField = function _defineResetField() { var _this5 = this; - this._dir.vm.$validate = function () { + this._dir.vm.$resetField = function () { for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } + var field = null; + var cb = null; + + each(args, function (arg, index) { + if (typeof arg === 'string') { + field = arg; + } else if (typeof arg === 'function') { + cb = arg; + } + }); + + _this5._resetField(field, cb); + }; + }; + + Validator.prototype._defineValidate = function _defineValidate() { + var _this6 = this; + + this._dir.vm.$validate = function () { + for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { + args[_key2] = arguments[_key2]; + } + var field = null; var touched = false; var cb = null; @@ -2018,26 +2122,26 @@ var validators = Object.freeze({ } }); - _this5.validate({ field: field, touched: touched, cb: cb }); + _this6.validate({ field: field, touched: touched, cb: cb }); }; }; Validator.prototype._defineSetValidationErrors = function _defineSetValidationErrors() { - var _this6 = this; + var _this7 = this; this._dir.vm.$setValidationErrors = function (errors) { - _this6._setValidationErrors(errors); + _this7._setValidationErrors(errors); }; }; Validator.prototype._validate = function _validate(field) { - var touched = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1]; - var noopable = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2]; + var touched = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + var noopable = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; - var _this7 = this; + var _this8 = this; - var el = arguments.length <= 3 || arguments[3] === undefined ? null : arguments[3]; - var cb = arguments.length <= 4 || arguments[4] === undefined ? null : arguments[4]; + var el = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null; + var cb = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null; var scope = this._scope; @@ -2046,14 +2150,14 @@ var validators = Object.freeze({ validation.willUpdateFlags(touched); validation.validate(function (results) { exports$1.Vue.set(scope, field, results); - _this7._fireEvents(); + _this8._fireEvents(); cb && cb(); }, noopable, el); } }; Validator.prototype._validates = function _validates(cb) { - var _this8 = this; + var _this9 = this; var scope = this._scope; @@ -2064,7 +2168,7 @@ var validators = Object.freeze({ }); }, function () { // finished - _this8._fireEvents(); + _this9._fireEvents(); cb && cb(); }); }; @@ -2073,6 +2177,14 @@ var validators = Object.freeze({ return this._validations[field] || this._checkboxValidations[field] && this._checkboxValidations[field].validation || this._radioValidations[field] && this._radioValidations[field].validation; }; + Validator.prototype._resetField = function _resetField(field, cb) { + var validation = this._getValidationFrom(field); + if (validation) { + validation.reset(); + } + this._validates(cb); + }; + Validator.prototype._resetValidation = function _resetValidation(cb) { each(this.validations, function (validation, key) { validation.reset(); @@ -2081,7 +2193,7 @@ var validators = Object.freeze({ }; Validator.prototype._setValidationErrors = function _setValidationErrors(errors) { - var _this9 = this; + var _this10 = this; var extend = exports$1.Vue.util.extend; @@ -2097,7 +2209,7 @@ var validators = Object.freeze({ // set errors each(temp, function (values, field) { - var results = _this9._scope[field]; + var results = _this10._scope[field]; var newResults = {}; each(values, function (error) { @@ -2111,10 +2223,10 @@ var validators = Object.freeze({ results.errors = values; extend(newResults, results); - var validation = _this9._getValidationFrom(field); + var validation = _this10._getValidationFrom(field); validation.willUpdateClasses(newResults, validation.el); - exports$1.Vue.set(_this9._scope, field, newResults); + exports$1.Vue.set(_this10._scope, field, newResults); }); }; @@ -2203,8 +2315,8 @@ var validators = Object.freeze({ }; Validator.prototype._fireEvent = function _fireEvent(type) { - for (var _len2 = arguments.length, args = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { - args[_key2 - 1] = arguments[_key2]; + for (var _len3 = arguments.length, args = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { + args[_key3 - 1] = arguments[_key3]; } var handler = this._events[this._getEventName(type)]; @@ -2233,7 +2345,7 @@ var validators = Object.freeze({ }; Validator.prototype._defineProperties = function _defineProperties(validationsGetter, targetGetter) { - var _this10 = this; + var _this11 = this; var bind = exports$1.Vue.util.bind; @@ -2251,7 +2363,7 @@ var validators = Object.freeze({ enumerable: true, configurable: true, get: function get() { - return bind(descriptor.fn, _this10)(descriptor.arg); + return bind(descriptor.fn, _this11)(descriptor.arg); } }); }); @@ -2270,7 +2382,7 @@ var validators = Object.freeze({ }; Validator.prototype._walkValidations = function _walkValidations(validations, property, condition) { - var _this11 = this; + var _this12 = this; var hasOwn = exports$1.Vue.util.hasOwn; var ret = condition; @@ -2279,8 +2391,8 @@ var validators = Object.freeze({ if (ret === !condition) { return; } - if (hasOwn(_this11._scope, validation.field)) { - var target = _this11._scope[validation.field]; + if (hasOwn(_this12._scope, validation.field)) { + var target = _this12._scope[validation.field]; if (target && target[property] === !condition) { ret = !condition; } @@ -2319,15 +2431,15 @@ var validators = Object.freeze({ }; Validator.prototype._defineErrors = function _defineErrors(validationsGetter) { - var _this12 = this; + var _this13 = this; var hasOwn = exports$1.Vue.util.hasOwn; var isPlainObject = exports$1.Vue.util.isPlainObject; var errors = []; each(validationsGetter(), function (validation, key) { - if (hasOwn(_this12._scope, validation.field)) { - var target = _this12._scope[validation.field]; + if (hasOwn(_this13._scope, validation.field)) { + var target = _this13._scope[validation.field]; if (target && !empty(target.errors)) { each(target.errors, function (err, index) { var error = { field: validation.field }; @@ -2350,7 +2462,7 @@ var validators = Object.freeze({ }); }; - babelHelpers.createClass(Validator, [{ + createClass(Validator, [{ key: 'validations', get: function get() { var extend = exports$1.Vue.util.extend; @@ -2375,13 +2487,13 @@ var validators = Object.freeze({ function Validator (Vue) { var FragmentFactory = Vue.FragmentFactory; var vIf = Vue.directive('if'); - var _Vue$util = Vue.util; - var isArray = _Vue$util.isArray; - var isPlainObject = _Vue$util.isPlainObject; - var createAnchor = _Vue$util.createAnchor; - var replace = _Vue$util.replace; - var extend = _Vue$util.extend; - var camelize = _Vue$util.camelize; + var _Vue$util = Vue.util, + isArray = _Vue$util.isArray, + isPlainObject = _Vue$util.isPlainObject, + createAnchor = _Vue$util.createAnchor, + replace = _Vue$util.replace, + extend = _Vue$util.extend, + camelize = _Vue$util.camelize; /** * `validator` element directive @@ -2494,10 +2606,9 @@ var validators = Object.freeze({ template: '
', partials: {} - }; - // only use ValidatorError component - error.partials['validator-error-default'] = '

{{field}}: {{message}}

'; + // only use ValidatorError component + };error.partials['validator-error-default'] = '

{{field}}: {{message}}

'; return error; } @@ -2565,10 +2676,9 @@ var validators = Object.freeze({ template: '', components: {} - }; - // define 'partial' prop - errors.props['partial'] = error.props['partial']; + // define 'partial' prop + };errors.props['partial'] = error.props['partial']; // only use ValidatorErrors component errors.components[error.name] = error; @@ -2587,7 +2697,7 @@ var validators = Object.freeze({ */ function plugin(Vue) { - var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; if (plugin.installed) { warn('already installed.'); diff --git a/dist/vue-validator.min.js b/dist/vue-validator.min.js index 6c2a2b9..db0b484 100644 --- a/dist/vue-validator.min.js +++ b/dist/vue-validator.min.js @@ -1,7 +1,7 @@ /*! * vue-validator v2.1.7 - * (c) 2016 kazuya kawaguchi + * (c) 2017 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;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(x)){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,this.params.initial):(Array.isArray(t)||i&&Array.isArray(i))&&this.handleArray(t,i,this.params.initial);var e={field:this.field};this.frag&&(e.el=this.frag.node),this.validator.validate(e)}},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)},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,n){var a=this;i&&this.validation.resetValidation(),e(t,function(t){a.validation.setValidation(t,void 0,void 0,n)})},handleObject:function(t,i,n){var a=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,o="initial"in t?t.initial:null;a.validation.setValidation(i,t.rule,e,o||n)}}else a.validation.setValidation(i,t,void 0,n)})},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.resetValidationNoopable(),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.resetValidationNoopable(),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._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.$resetValidation=null,delete t.$resetValidation,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(N.test(a)){var o=i[e].value;t(o)&&(o+=".apply(this, $arguments)"),a=a.replace(N,""),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.field0)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;n0:null!==t&&"object"===(void 0===t?"undefined":k(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)&&t.length>=parseInt(i,10):!!Array.isArray(t)&&t.length>=parseInt(i,10)}function u(t,i){return"string"==typeof t?f(i)&&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,x),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){if(!e)return t.options.validators[i];t.options.validators[i]=e}}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+I,bind:function(){var t=this,i=String(j++);this.setClassIds(this.el,i),this.vm.$on(S,this.cb=function(e,n,a){e.indexOf(i)>-1&&n.updateClasses(a,t.frag.node)}),this.setupFragment()},unbind:function(){this.vm.$off(S,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];if(b.installed)return void t("already installed.");w.Vue=i,p(i),V(i),v(i),m(i),_(i),g(i)}var w={},k="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},C=(function(){function t(t){this.value=t}function i(i){function e(t,i){return new Promise(function(e,a){var s={key:t,arg:i,resolve:e,reject:a,next:null};r?r=r.next=s:(o=r=s,n(t,i))})}function n(e,o){try{var r=i[e](o),s=r.value;s instanceof t?Promise.resolve(s.value).then(function(t){n("next",t)},function(t){n("throw",t)}):a(r.done?"return":"normal",r.value)}catch(t){a("throw",t)}}function a(t,i){switch(t){case"return":o.resolve({value:i,done:!0});break;case"throw":o.reject(i);break;default:o.resolve({value:i,done:!1})}o=o.next,o?n(o.key,o.arg):r=null}var o,r;this._invoke=e,"function"!=typeof i.return&&(this.return=void 0)}"function"==typeof Symbol&&Symbol.asyncIterator&&(i.prototype[Symbol.asyncIterator]=function(){return this}),i.prototype.next=function(t){return this._invoke("next",t)},i.prototype.throw=function(t){return this._invoke("throw",t)},i.prototype.return=function(t){return this._invoke("return",t)}}(),function(t,i){if(!(t instanceof i))throw new TypeError("Cannot call a class as a function")}),E=function(){function t(t,i){for(var e=0;e0&&void 0!==arguments[0]&&arguments[0]&&this.willUpdateTouched(this._el,"blur"),this.willUpdateDirty(this._el),this.willUpdateModified(this._el)},t.prototype.willUpdateTouched=function(t,i){i&&"blur"===i&&(this.touched=!0,this._fireEvent(t,"touched"))},t.prototype.willUpdateDirty=function(t){!this.dirty&&this._checkModified(t)&&(this.dirty=!0,this._fireEvent(t,"dirty"))},t.prototype.willUpdateModified=function(t){this.modified=this._checkModified(t),this._modified!==this.modified&&(this._fireEvent(t,"modified",{modified:this.modified}),this._modified=this.modified)},t.prototype.listener=function(t){this.guardValidate(t.target,t.type)||this.handleValidate(t.target,{type:t.type})},t.prototype.handleValidate=function(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},e=i.type,n=void 0===e?null:e,a=i.noopable,o=void 0!==a&&a;this.willUpdateTouched(t,n),this.willUpdateDirty(t),this.willUpdateModified(t),this._validator.validate({field:this.field,el:t,noopable:o})},t.prototype.validate=function(t){var e=this,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,o=w.Vue.util,r={},s=[],l=!0;this._runValidators(function(t,i,a){var d=e._resolveValidator(i),u=null,h=null;if(o.isPlainObject(d)?(d.check&&"function"==typeof d.check&&(u=d.check),d.message&&(h=d.message)):"function"==typeof d&&(u=d),t.msg&&(h=t.msg),n)return r[i]=!1,a();if(t._isNoopable)return r[i]=!1,t._isNoopable=null,a();if(u){var c=e._getValue(e._el);e._invokeValidator(e._vm,u,c,t.arg,function(n,o){if(n)r[i]=!n;else if(l=!1,o)s.push({validator:i,message:o}),r[i]=o;else if(h){var d={validator:i};d.message="function"==typeof h?h.call(e._vm,e.field,t.arg):h,s.push(d),r[i]=d.message}else r[i]=!n;a()})}else a()},function(){e._fireEvent(e._el,l?"valid":"invalid");var n={valid:l,invalid:!l,touched:e.touched,untouched:!e.touched,dirty:e.dirty,pristine:!e.dirty,modified:e.modified};i(s)||(n.errors=s),o.extend(r,n),e.willUpdateClasses(r,a),t(r)})},t.prototype.resetFlags=function(){this.touched=!1,this.dirty=!1,this.modified=!1,this._modified=!1},t.prototype.reset=function(){this.resetValidationNoopable(),this.resetFlags(),this._init=this._getValue(this._el)},t.prototype.willUpdateClasses=function(t){var i=this,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;if(this._checkClassIds(e)){var n=this._getClassIds(e);this.vm.$nextTick(function(){i.vm.$emit(S,n,i,t)})}else this.updateClasses(t)},t.prototype.updateClasses=function(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;this._updateClasses(i||this._el,t)},t.prototype.guardValidate=function(t,i){return!(!i||"blur"!==i||this.detectBlur)||(!(!i||"input"!==i||this.detectChange)||(!(!i||"change"!==i||this.detectChange)||!(!i||"click"!==i||this.detectChange)))},t.prototype._getValue=function(t){return t.value},t.prototype._getScope=function(){return this._forScope||this._vm},t.prototype._getClassIds=function(t){return this._classIds},t.prototype._checkModified=function(t){return this._init!==this._getValue(t)},t.prototype._checkClassIds=function(t){return this._getClassIds(t)},t.prototype._fireEvent=function(t,i,e){a(t,i,e)},t.prototype._evalModel=function(t,i){var e=this._getScope(),n=null;return i?(n=e.$get(t),i?this._applyFilters(n,null,i):n):(n=e.$get(t),void 0===n||null===n?"":n)},t.prototype._updateClasses=function(t,i){this._toggleValid(t,i.valid),this._toggleTouched(t,i.touched),this._togglePristine(t,i.pristine),this._toggleModfied(t,i.modified)},t.prototype._toggleValid=function(t,i){var e=w.Vue.util,n=e.addClass,a=e.removeClass,o=this._classes.valid||"valid",s=this._classes.invalid||"invalid";i?(r(t,o,n),r(t,s,a)):(r(t,o,a),r(t,s,n))},t.prototype._toggleTouched=function(t,i){var e=w.Vue.util,n=e.addClass,a=e.removeClass,o=this._classes.touched||"touched",s=this._classes.untouched||"untouched";i?(r(t,o,n),r(t,s,a)):(r(t,o,a),r(t,s,n))},t.prototype._togglePristine=function(t,i){var e=w.Vue.util,n=e.addClass,a=e.removeClass,o=this._classes.pristine||"pristine",s=this._classes.dirty||"dirty";i?(r(t,o,n),r(t,s,a)):(r(t,o,a),r(t,s,n))},t.prototype._toggleModfied=function(t,i){var e=w.Vue.util,n=e.addClass,a=e.removeClass,o=this._classes.modified||"modified";i?r(t,o,n):r(t,o,a)},t.prototype._applyFilters=function(t,i,e,n){var a=w.Vue.util.resolveAsset,o=this._getScope(),r=void 0,s=void 0,l=void 0,d=void 0,u=void 0,h=void 0,c=void 0,f=void 0,p=void 0;for(h=0,c=e.length;h=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){return(0,w.Vue.util.resolveAsset)(this._vm.$options,"validators",t)},E(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}(),B=function(t){function i(e,n,a,o,r,s,l,d,u){C(this,i);var h=F(this,t.call(this,e,n,a,o,r,s,l,d,u));return h._inits=[],h}return A(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]&&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.resetValidationNoopable(),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]?arguments[1]:null;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(S);return n&&(t.removeAttribute(S),e.classIds=n.split(",")),this._inits.push(e),e},i.prototype._setChecked=function(t,i){for(var e=0,n=t.length;e0&&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.resetValidationNoopable(),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]?arguments[1]:null;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(S);return n&&(t.removeAttribute(S),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){if(this._inits&&0!==this._inits.length){var i=[];return e(this._inits,function(t,e){t.el.checked&&i.push(t.el.value)}),i}return t.checked},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){if(0===this._inits.length)return this._init!==t.checked;var i=!1;return e(this._inits,function(t,e){i||(i=t.init!==t.el.checked)}),i},i}(U),T=function(t){function i(e,n,a,o,r,s,l,d,u){C(this,i);var h=F(this,t.call(this,e,n,a,o,r,s,l,d,u));return h._multiple=h._el.hasAttribute("multiple"),h}return A(i,t),i.prototype.manageElement=function(t,i){var e=this,n=this._getScope(),a=this._model;this._initial=i;var o=t.getAttribute(S);if(o&&(t.removeAttribute(S),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._getValue=function(t){for(var i=[],e=0,n=t.options.length;e0&&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&&r,l=t.noopable,d=void 0!==l&&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={};w.Vue.set(t._scope,i,n),t._defineProperties(function(){return e},function(){return n})})},t.prototype.waitFor=function(t){var i=this._dir.vm;i.$activateValidator=function(){t(),i.$activateValidator=null}},t.prototype._defineResetValidation=function(){var t=this;this._dir.vm.$resetValidation=function(i){t._resetValidation(i)}},t.prototype._defineResetField=function(){var t=this;this._dir.vm.$resetField=function(){for(var i=arguments.length,n=Array(i),a=0;a1&&void 0!==arguments[1]&&arguments[1],e=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n=this,a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,r=this._scope,s=this._getValidationFrom(t);s&&(s.willUpdateFlags(i),s.validate(function(i){w.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){w.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._resetField=function(t,i){var e=this._getValidationFrom(t);e&&e.reset(),this._validates(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],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),w.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 U(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),w.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){d={validation:new B(t,i,e,n,a,this,o,s,l),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&&(w.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){d={validation:new P(t,i,e,n,a,this,o,s,l),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&&(w.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 T(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),w.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;n=n&&i()})})},t.prototype._walkValidations=function(t,i,n){var a=this,o=w.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=w.Vue.util.hasOwn,o=w.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 + + + + validation result resetting example + + + + + +
+ +
+
+ + + +
+
+ + + +
+
+

Your name is required.

+

Your password is required.

+

Your password is too long.

+
+ + +
+
{{ $validation1 | json }}
+
+
+ + + diff --git a/src/validator.js b/src/validator.js index b69598e..ff95a24 100644 --- a/src/validator.js +++ b/src/validator.js @@ -41,6 +41,9 @@ export default class Validator { // define the validation resetting meta method to vue instance this._defineResetValidation() + // define the validation resetting for a single field + this._defineResetField() + // define the validate manually meta method to vue instance this._defineValidate() @@ -56,6 +59,8 @@ export default class Validator { delete vm['$validate'] vm.$resetValidation = null delete vm['$resetValidation'] + vm.$resetField = null + delete vm['$resetField'] vm._validatorMaps[this.name] = null delete vm._validatorMaps[this.name] vm[this.name] = null @@ -193,6 +198,23 @@ export default class Validator { } } + _defineResetField () { + this._dir.vm.$resetField = (...args) => { + let field = null + let cb = null + + each(args, (arg, index) => { + if (typeof arg === 'string') { + field = arg + } else if (typeof arg === 'function') { + cb = arg + } + }) + + this._resetField(field, cb) + } + } + _defineValidate () { this._dir.vm.$validate = (...args) => { let field = null @@ -255,6 +277,14 @@ export default class Validator { || (this._radioValidations[field] && this._radioValidations[field].validation) } + _resetField (field, cb) { + var validation = this._getValidationFrom(field) + if (validation) { + validation.reset() + } + this._validates(cb) + } + _resetValidation (cb) { each(this.validations, (validation, key) => { validation.reset() diff --git a/test/specs/index.js b/test/specs/index.js index 634377e..4b78382 100644 --- a/test/specs/index.js +++ b/test/specs/index.js @@ -30,6 +30,7 @@ require('./checkbox') require('./radio') require('./select') require('./reset') +require('./reset-single') require('./validate') require('./initial') require('./async') diff --git a/test/specs/issues.js b/test/specs/issues.js index 83a4278..a2b4e1b 100644 --- a/test/specs/issues.js +++ b/test/specs/issues.js @@ -212,8 +212,8 @@ describe('github issues', () => { trigger(foo, 'blur') vm.$nextTick(() => { assert(vm.$validator1.field1.required === false) - assert(vm.$validator1.field1.minlength === true) - assert(vm.$validator1.field1.valid === false) + assert(vm.$validator1.field1.minlength === false) + assert(vm.$validator1.field1.valid === true) assert(vm.$validator1.field1.touched === true) assert(vm.$validator1.field1.dirty === true) assert(vm.$validator1.field1.modified === true) diff --git a/test/specs/reset-single.js b/test/specs/reset-single.js new file mode 100644 index 0000000..b9eb9cc --- /dev/null +++ b/test/specs/reset-single.js @@ -0,0 +1,264 @@ +import assert from 'power-assert' +import Vue from 'vue' +import { trigger } from '../../src/util' + + +describe('reset single field', () => { + let el, vm + + beforeEach(() => { + el = document.createElement('div') + }) + + + describe('text', () => { + beforeEach((done) => { + el.innerHTML = ` + +
+ + +
+
+ ` + vm = new Vue({ el }) + vm.$nextTick(done) + }) + + it('should be reset', (done) => { + assert(vm.$validator1.field1.required) + assert(vm.$validator1.field1.min === false) + assert(vm.$validator1.field1.max === false) + assert(vm.$validator1.field1.valid === false) + assert(vm.$validator1.field1.dirty === false) + assert(vm.$validator1.field1.modified === false) + assert(vm.$validator1.field1.touched === false) + assert(vm.$validator1.field2.minlength === false) + assert(vm.$validator1.field2.valid === true) + assert(vm.$validator1.field2.dirty === false) + assert(vm.$validator1.field2.modified === false) + assert(vm.$validator1.field2.touched === false) + assert(vm.$validator1.valid === false) + assert(vm.$validator1.dirty === false) + assert(vm.$validator1.modified === false) + assert(vm.$validator1.touched === false) + // change + const field1 = el.getElementsByTagName('input')[0] + const field2 = el.getElementsByTagName('input')[1] + field1.value = '200' + field2.value = 'World' + trigger(field1, 'input') + trigger(field1, 'blur') + trigger(field2, 'input') + trigger(field2, 'blur') + vm.$nextTick(() => { + // reset + vm.$resetField('field1', () => { + assert(vm.$validator1.field1.required === false) + assert(vm.$validator1.field1.min === false) + assert(vm.$validator1.field1.max === true) + assert(vm.$validator1.field1.valid === false) + assert(vm.$validator1.field1.dirty === false) + assert(vm.$validator1.field1.modified === false) + assert(vm.$validator1.field1.touched === false) + assert(vm.$validator1.field2.minlength === false) + assert(vm.$validator1.field2.valid === true) + assert(vm.$validator1.field2.dirty === true) + assert(vm.$validator1.field2.modified === true) + assert(vm.$validator1.field2.touched === true) + assert(vm.$validator1.valid === false) + assert(vm.$validator1.dirty === true) + assert(vm.$validator1.modified === true) + assert(vm.$validator1.touched === true) + done() + }) + }) + }) + }) + + + describe('checkbox', () => { + beforeEach((done) => { + el.innerHTML = ` + +
+ + +
+
+ ` + vm = new Vue({ el }) + vm.$nextTick(done) + }) + + it('should be reset', (done) => { + assert(vm.$validator1.field1.required) + assert(vm.$validator1.field1.minlength === true) + assert(vm.$validator1.field1.valid === false) + assert(vm.$validator1.field1.touched === false) + assert(vm.$validator1.field1.dirty === false) + assert(vm.$validator1.field1.modified === false) + assert(vm.$validator1.valid === false) + assert(vm.$validator1.dirty === false) + assert(vm.$validator1.modified === false) + assert(vm.$validator1.touched === false) + // change + const checkbox1 = el.getElementsByTagName('input')[0] + const checkbox2 = el.getElementsByTagName('input')[1] + checkbox1.checked = true + checkbox2.checked = true + trigger(checkbox1, 'change') + trigger(checkbox1, 'blur') + trigger(checkbox2, 'change') + trigger(checkbox2, 'blur') + vm.$nextTick(() => { + // reset + vm.$resetField('field1', () => { + assert(vm.$validator1.field1.required === false) + assert(vm.$validator1.field1.minlength === false) + assert(vm.$validator1.field1.valid === true) + assert(vm.$validator1.field1.touched === false) + assert(vm.$validator1.field1.dirty === false) + assert(vm.$validator1.field1.modified === false) + assert(vm.$validator1.valid === true) + assert(vm.$validator1.dirty === false) + assert(vm.$validator1.modified === false) + assert(vm.$validator1.touched === false) + done() + }) + }) + }) + }) + + + describe('radio', () => { + beforeEach((done) => { + el.innerHTML = ` + +
+
+ + + + +
+
+ + + + +
+
+
+ ` + vm = new Vue({ el }) + vm.$nextTick(done) + }) + + it('should be reset', (done) => { + // default + assert(vm.$validator1.field1.required === false) + assert(vm.$validator1.field1.valid === true) + assert(vm.$validator1.field1.touched === false) + assert(vm.$validator1.field1.dirty === false) + assert(vm.$validator1.field1.modified === false) + assert(vm.$validator1.field2.required) + assert(vm.$validator1.field2.valid === false) + assert(vm.$validator1.field2.touched === false) + assert(vm.$validator1.field2.dirty === false) + assert(vm.$validator1.field2.modified === false) + assert(vm.$validator1.valid === false) + assert(vm.$validator1.touched === false) + assert(vm.$validator1.dirty === false) + assert(vm.$validator1.modified === false) + // change + const radio2 = el.getElementsByTagName('input')[1] + const radio3 = el.getElementsByTagName('input')[2] + radio2.checked = true + radio3.checked = true + trigger(radio2, 'change') + trigger(radio2, 'blur') + trigger(radio3, 'change') + trigger(radio3, 'blur') + vm.$nextTick(() => { + // reset + vm.$resetField('field1', () => { + assert(vm.$validator1.field1.required === false) + assert(vm.$validator1.field1.valid === true) + assert(vm.$validator1.field1.touched === false) + assert(vm.$validator1.field1.dirty === false) + assert(vm.$validator1.field1.modified === false) + assert(vm.$validator1.field2.required === false) + assert(vm.$validator1.field2.valid === true) + assert(vm.$validator1.field2.touched === true) + assert(vm.$validator1.field2.dirty === true) + assert(vm.$validator1.field2.modified === true) + assert(vm.$validator1.valid === true) + assert(vm.$validator1.touched === true) + assert(vm.$validator1.dirty === true) + assert(vm.$validator1.modified === true) + done() + }) + }) + }) + }) + + + describe('select', () => { + beforeEach((done) => { + el.innerHTML = ` + +
+ +
+
+ ` + vm = new Vue({ el }) + vm.$nextTick(done) + }) + + it('should be reset', (done) => { + // default + assert(vm.$validator1.lang.required) + assert(vm.$validator1.lang.minlength === true) + assert(vm.$validator1.lang.valid === false) + assert(vm.$validator1.lang.touched === false) + assert(vm.$validator1.lang.dirty === false) + assert(vm.$validator1.lang.modified === false) + assert(vm.$validator1.valid === false) + assert(vm.$validator1.touched === false) + assert(vm.$validator1.dirty === false) + assert(vm.$validator1.modified === false) + // change + const select = el.getElementsByTagName('select')[0] + const option2 = el.getElementsByTagName('option')[1] + const option3 = el.getElementsByTagName('option')[2] + option2.selected = true + option3.selected = true + trigger(select, 'change') + trigger(select, 'blur') + vm.$nextTick(() => { + // reset + vm.$resetField('lang', () => { + assert(vm.$validator1.lang.required === false) + assert(vm.$validator1.lang.minlength === false) + assert(vm.$validator1.lang.valid === true) + assert(vm.$validator1.lang.touched === false) + assert(vm.$validator1.lang.dirty === false) + assert(vm.$validator1.lang.modified === false) + assert(vm.$validator1.valid === true) + assert(vm.$validator1.touched === false) + assert(vm.$validator1.dirty === false) + assert(vm.$validator1.modified === false) + done() + }) + }) + }) + }) +})