diff --git a/CHANGELOG.md b/CHANGELOG.md index e7f0e04..ab2d1a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,23 @@ + +# [2.1.0](https://github.com/vuejs/vue-validator/compare/v2.0.2...v2.1.0) (2016-04-30) + + +### Bug Fixes + +* **initial:** cannot work 'initial="off"' on the checkbox([0d705d8](https://github.com/vuejs/vue-validator/commit/0d705d8)), closes [#208](https://github.com/vuejs/vue-validator/issues/208) +* **v-validate:** friendly error for field name missing ([#205](https://github.com/vuejs/vue-validator/issues/205)) by [@xjchengo](https://github.com/xjchengo)([35c01d3](https://github.com/vuejs/vue-validator/commit/35c01d3)) + + +### Features + +* **active:** add validation active classes([5a71499](https://github.com/vuejs/vue-validator/commit/5a71499)) +* **api:** fix $validate API when using touched ([#211](https://github.com/vuejs/vue-validator/issues/211)) by [@losadaem](https://github.com/losadaem)([68282d1](https://github.com/vuejs/vue-validator/commit/68282d1)), closes [(#211](https://github.com/(/issues/211) +* **classes:** add custom validation classes([1d52746](https://github.com/vuejs/vue-validator/commit/1d52746)) +* **classes:** add validation classes([85fe201](https://github.com/vuejs/vue-validator/commit/85fe201)) +* **validator:** add classes params to validator element directive([6103e8d](https://github.com/vuejs/vue-validator/commit/6103e8d)) + + + ## [2.0.2](https://github.com/vuejs/vue-validator/compare/v2.0.1...v2.0.2) (2016-04-20) diff --git a/dist/vue-validator.common.js b/dist/vue-validator.common.js index 1d784da..20ecc22 100644 --- a/dist/vue-validator.common.js +++ b/dist/vue-validator.common.js @@ -1,5 +1,5 @@ /*! - * vue-validator v2.0.2 + * vue-validator v2.1.0 * (c) 2016 kazuya kawaguchi * Released under the MIT License. */ @@ -187,6 +187,27 @@ function isPromise(p) { return p && typeof p.then === 'function'; } +/** + * Togging classes + * + * @param {Element} el + * @param {String} key + * @param {Function} fn + */ + +function toggleClasses(el, key, fn) { + key = key.trim(); + if (key.indexOf(' ') === -1) { + fn(el, key); + return; + } + + var keys = key.split(/\s+/); + for (var i = 0, l = keys.length; i < l; i++) { + fn(el, keys[i]); + } +} + /** * Fundamental validate functions */ @@ -403,16 +424,109 @@ function Override (Vue) { }; } +var VALIDATE_UPDATE = '__vue-validator-validate-update__'; +var PRIORITY_VALIDATE = 16; +var PRIORITY_VALIDATE_CLASS = 32; +var REGEX_FILTER = /[^|]\|[^|]/; +var REGEX_VALIDATE_DIRECTIVE = /^v-validate(?:$|:(.*)$)/; + +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; + + /** + * `v-validate-class` directive + */ + + Vue.directive('validate-class', { + terminal: true, + priority: vIf.priority + PRIORITY_VALIDATE_CLASS, + + bind: function bind() { + var _this = this; + + var id = String(classId++); + this.setClassIds(this.el, id); + + this.vm.$on(VALIDATE_UPDATE, this.cb = function (classIds, validation, results) { + if (classIds.indexOf(id) > -1) { + validation.updateClasses(results, _this.frag.node); + } + }); + + this.setupFragment(); + }, + unbind: function unbind() { + this.vm.$off(VALIDATE_UPDATE, this.cb); + this.teardownFragment(); + }, + setClassIds: function setClassIds(el, id) { + var childNodes = toArray(el.childNodes); + for (var i = 0, l = childNodes.length; i < l; i++) { + var element = childNodes[i]; + if (element.nodeType === 1) { + var hasAttrs = element.hasAttributes(); + var attrs = hasAttrs && toArray(element.attributes); + for (var k = 0, _l = attrs.length; k < _l; k++) { + var attr = attrs[k]; + if (attr.name.match(REGEX_VALIDATE_DIRECTIVE)) { + var existingId = element.getAttribute(VALIDATE_UPDATE); + var value = existingId ? existingId + ',' + id : id; + element.setAttribute(VALIDATE_UPDATE, value); + } + } + } + + if (element.hasChildNodes()) { + this.setClassIds(element, id); + } + } + }, + setupFragment: function setupFragment() { + this.anchor = createAnchor('v-validate-class'); + replace(this.el, this.anchor); + + this.factory = new FragmentFactory(this.vm, this.el); + this.frag = this.factory.create(this._host, this._scope, this._frag); + this.frag.before(this.anchor); + }, + teardownFragment: function teardownFragment() { + if (this.frag) { + this.frag.remove(); + this.frag = null; + this.factory = null; + } + + replace(this.anchor, this.el); + this.anchor = null; + } + }); +} + function Validate (Vue) { - var _ = Vue.util; var vIf = Vue.directive('if'); var FragmentFactory = Vue.FragmentFactory; var parseDirective = Vue.parsers.directive.parseDirective; - var REGEX_FILTER = /[^|]\|[^|]/; + 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; // Test for IE10/11 textarea placeholder clone bug + function checkTextareaCloneBug() { - if (_.inBrowser) { + if (inBrowser) { var t = document.createElement('textarea'); t.placeholder = 't'; return t.cloneNode(true).value === 't'; @@ -428,8 +542,8 @@ function Validate (Vue) { Vue.directive('validate', { terminal: true, - priority: vIf.priority + 16, - params: ['group', 'field', 'detect-blur', 'detect-change', 'initial'], + priority: vIf.priority + PRIORITY_VALIDATE, + params: ['group', 'field', 'detect-blur', 'detect-change', 'initial', 'classes'], paramWatchers: { detectBlur: function detectBlur(val, old) { @@ -463,6 +577,12 @@ function Validate (Vue) { return; } + if (process.env.NODE_ENV !== 'production' && !(this.arg || this.params.field)) { + warn('you need specify field name for v-validate directive.'); + this._invalid = true; + return; + } + var validatorName = this.vm.$options._validator; if (process.env.NODE_ENV !== 'production' && !validatorName) { warn('v-validate need to use into validator element directive: ' + '(e.g. ' + '' + ').'); @@ -488,13 +608,18 @@ function Validate (Vue) { return; } - if (_.isPlainObject(value)) { + if (isPlainObject(value)) { this.handleObject(value); } else if (Array.isArray(value)) { this.handleArray(value); } - this.validator.validate({ field: this.field, noopable: this._initialNoopValidation }); + var options = { field: this.field, noopable: this._initialNoopValidation }; + if (this.frag) { + options.el = this.frag.node; + } + this.validator.validate(options); + if (this._initialNoopValidation) { this._initialNoopValidation = null; } @@ -522,9 +647,11 @@ function Validate (Vue) { var params = this.params; var validator = this.validator = this.vm._validatorMaps[name]; - this.field = _.camelize(this.arg ? this.arg : params.field); + this.field = camelize(this.arg ? this.arg : params.field); - this.validation = validator.manageValidation(this.field, model, this.vm, this.frag.node, this._scope, filters, this.isDetectBlur(params.detectBlur), this.isDetectChange(params.detectChange)); + this.validation = validator.manageValidation(this.field, model, this.vm, this.frag.node, this._scope, filters, params.initial, this.isDetectBlur(params.detectBlur), this.isDetectChange(params.detectChange)); + + isPlainObject(params.classes) && this.validation.setValidationClasses(params.classes); params.group && validator.addGroupValidation(params.group, this.field); @@ -535,23 +662,23 @@ function Validate (Vue) { var validation = this.validation; var el = this.frag.node; - this.onBlur = _.bind(validation.listener, validation); - _.on(el, 'blur', this.onBlur); + this.onBlur = bind(validation.listener, validation); + on(el, 'blur', this.onBlur); if ((el.type === 'radio' || el.tagName === 'SELECT') && !model) { - this.onChange = _.bind(validation.listener, validation); - _.on(el, 'change', this.onChange); + this.onChange = bind(validation.listener, validation); + on(el, 'change', this.onChange); } else if (el.type === 'checkbox') { if (!model) { - this.onChange = _.bind(validation.listener, validation); - _.on(el, 'change', this.onChange); + this.onChange = bind(validation.listener, validation); + on(el, 'change', this.onChange); } else { - this.onClick = _.bind(validation.listener, validation); - _.on(el, 'click', this.onClick); + this.onClick = bind(validation.listener, validation); + on(el, 'click', this.onClick); } } else { if (!model) { - this.onInput = _.bind(validation.listener, validation); - _.on(el, 'input', this.onInput); + this.onInput = bind(validation.listener, validation); + on(el, 'input', this.onInput); } } }, @@ -559,22 +686,22 @@ function Validate (Vue) { var el = this.frag.node; if (this.onInput) { - _.off(el, 'input', this.onInput); + off(el, 'input', this.onInput); this.onInput = null; } if (this.onClick) { - _.off(el, 'click', this.onClick); + off(el, 'click', this.onClick); this.onClick = null; } if (this.onChange) { - _.off(el, 'change', this.onChange); + off(el, 'change', this.onChange); this.onChange = null; } if (this.onBlur) { - _.off(el, 'blur', this.onBlur); + off(el, 'blur', this.onBlur); this.onBlur = null; } }, @@ -592,8 +719,8 @@ function Validate (Vue) { } }, setupFragment: function setupFragment() { - this.anchor = _.createAnchor('v-validate'); - _.replace(this.el, this.anchor); + this.anchor = createAnchor('v-validate'); + replace(this.el, this.anchor); this.factory = new FragmentFactory(this.vm, this.shimNode(this.el)); this.frag = this.factory.create(this._host, this._scope, this._frag); @@ -606,7 +733,7 @@ function Validate (Vue) { this.factory = null; } - _.replace(this.anchor, this.el); + replace(this.anchor, this.el); this.anchor = null; }, handleArray: function handleArray(value) { @@ -620,7 +747,7 @@ function Validate (Vue) { var _this2 = this; each(value, function (val, key) { - if (_.isPlainObject(val)) { + if (isPlainObject(val)) { if ('rule' in val) { var msg = 'message' in val ? val.message : null; var initial = 'initial' in val ? val.initial : null; @@ -681,13 +808,23 @@ var BaseValidation = function () { this._validators = {}; this._detectBlur = detectBlur; this._detectChange = detectChange; + this._classes = {}; } - BaseValidation.prototype.manageElement = function manageElement(el) { + BaseValidation.prototype.manageElement = function manageElement(el, initial) { var _this = this; var scope = this._getScope(); var model = this._model; + + this._initial = initial; + + var classIds = el.getAttribute(VALIDATE_UPDATE); + if (classIds) { + el.removeAttribute(VALIDATE_UPDATE); + this._classIds = classIds.split(','); + } + if (model) { el.value = this._evalModel(model, this._filters); this._unwatch = scope.$watch(model, function (val, old) { @@ -695,7 +832,11 @@ var BaseValidation = function () { if (_this.guardValidate(el, 'input')) { return; } - _this.handleValidate(el); + + _this.handleValidate(el, _this._initial); + if (_this._initial) { + _this._initial = null; + } } }, { deep: true }); } @@ -723,6 +864,14 @@ var BaseValidation = function () { } }; + BaseValidation.prototype.setValidationClasses = function setValidationClasses(classes) { + var _this2 = this; + + each(classes, function (value, key) { + _this2._classes[key] = value; + }); + }; + BaseValidation.prototype.willUpdateFlags = function willUpdateFlags() { var touched = arguments.length <= 0 || arguments[0] === undefined ? false : arguments[0]; @@ -758,21 +907,29 @@ var BaseValidation = function () { return; } - this.handleValidate(e.target, e.type); + this.handleValidate(e.target, { type: e.type }); }; - BaseValidation.prototype.handleValidate = function handleValidate(el, type) { + 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; + this.willUpdateTouched(el, type); this.willUpdateDirty(el); this.willUpdateModified(el); - this._validator.validate({ field: this.field }); + this._validator.validate({ field: this.field, el: el, noopable: noopable }); }; BaseValidation.prototype.validate = function validate(cb) { - var _this2 = this; + var _this3 = this; var noopable = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1]; + var el = arguments.length <= 2 || arguments[2] === undefined ? null : arguments[2]; var _ = exports$1.Vue.util; @@ -781,7 +938,7 @@ var BaseValidation = function () { var valid = true; this._runValidators(function (descriptor, name, done) { - var asset = _this2._resolveValidator(name); + var asset = _this3._resolveValidator(name); var validator = null; var msg = null; @@ -812,8 +969,8 @@ var BaseValidation = function () { } if (validator) { - var value = _this2._getValue(_this2._el); - _this2._invokeValidator(_this2._vm, validator, value, descriptor.arg, function (ret, err) { + var value = _this3._getValue(_this3._el); + _this3._invokeValidator(_this3._vm, validator, value, descriptor.arg, function (ret, err) { if (!ret) { valid = false; if (err) { @@ -822,7 +979,7 @@ var BaseValidation = function () { results[name] = err; } else if (msg) { var error = { validator: name }; - error.message = typeof msg === 'function' ? msg.call(_this2._vm, _this2.field, descriptor.arg) : msg; + error.message = typeof msg === 'function' ? msg.call(_this3._vm, _this3.field, descriptor.arg) : msg; errors.push(error); results[name] = error.message; } else { @@ -839,22 +996,24 @@ var BaseValidation = function () { } }, function () { // finished - _this2._fireEvent(_this2._el, valid ? 'valid' : 'invalid'); + _this3._fireEvent(_this3._el, valid ? 'valid' : 'invalid'); var props = { valid: valid, invalid: !valid, - touched: _this2.touched, - untouched: !_this2.touched, - dirty: _this2.dirty, - pristine: !_this2.dirty, - modified: _this2.modified + touched: _this3.touched, + untouched: !_this3.touched, + dirty: _this3.dirty, + pristine: !_this3.dirty, + modified: _this3.modified }; if (!empty(errors)) { props.errors = errors; } _.extend(results, props); + _this3.willUpdateClasses(results, el); + cb(results); }); }; @@ -876,6 +1035,29 @@ var BaseValidation = function () { this._init = this._getValue(this._el); }; + BaseValidation.prototype.willUpdateClasses = function willUpdateClasses(results) { + var _this4 = this; + + var el = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1]; + + if (this._checkClassIds(el)) { + (function () { + var classIds = _this4._getClassIds(el); + _this4.vm.$nextTick(function () { + _this4.vm.$emit(VALIDATE_UPDATE, classIds, _this4, results); + }); + })(); + } else { + this.updateClasses(results); + } + }; + + BaseValidation.prototype.updateClasses = function updateClasses(results) { + var el = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1]; + + this._updateClasses(el || this._el, results); + }; + BaseValidation.prototype.guardValidate = function guardValidate(el, type) { if (type && type === 'blur' && !this.detectBlur) { return true; @@ -904,10 +1086,18 @@ var BaseValidation = function () { return this._forScope || this._vm; }; + BaseValidation.prototype._getClassIds = function _getClassIds(el) { + return this._classIds; + }; + BaseValidation.prototype._checkModified = function _checkModified(target) { return this._init !== this._getValue(target); }; + BaseValidation.prototype._checkClassIds = function _checkClassIds(el) { + return this._getClassIds(el); + }; + BaseValidation.prototype._fireEvent = function _fireEvent(el, type, args) { trigger(el, type, args); }; @@ -925,6 +1115,78 @@ var BaseValidation = function () { } }; + BaseValidation.prototype._updateClasses = function _updateClasses(el, results) { + this._toggleValid(el, results.valid); + this._toggleTouched(el, results.touched); + this._togglePristine(el, results.pristine); + this._toggleModfied(el, results.modified); + }; + + 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 validClass = this._classes.valid || 'valid'; + var invalidClass = this._classes.invalid || 'invalid'; + + if (valid) { + toggleClasses(el, validClass, addClass); + toggleClasses(el, invalidClass, removeClass); + } else { + toggleClasses(el, validClass, removeClass); + toggleClasses(el, invalidClass, addClass); + } + }; + + 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 touchedClass = this._classes.touched || 'touched'; + var untouchedClass = this._classes.untouched || 'untouched'; + + if (touched) { + toggleClasses(el, touchedClass, addClass); + toggleClasses(el, untouchedClass, removeClass); + } else { + toggleClasses(el, touchedClass, removeClass); + toggleClasses(el, untouchedClass, addClass); + } + }; + + 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 pristineClass = this._classes.pristine || 'pristine'; + var dirtyClass = this._classes.dirty || 'dirty'; + + if (pristine) { + toggleClasses(el, pristineClass, addClass); + toggleClasses(el, dirtyClass, removeClass); + } else { + toggleClasses(el, pristineClass, removeClass); + toggleClasses(el, dirtyClass, addClass); + } + }; + + 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 modifiedClass = this._classes.modified || 'modified'; + + if (modified) { + toggleClasses(el, modifiedClass, addClass); + } else { + toggleClasses(el, modifiedClass, removeClass); + } + }; + BaseValidation.prototype._applyFilters = function _applyFilters(value, oldValue, filters, write) { var resolveAsset = exports$1.Vue.util.resolveAsset; var scope = this._getScope(); @@ -1072,11 +1334,12 @@ var CheckboxValidation = function (_BaseValidation) { return _this; } - CheckboxValidation.prototype.manageElement = function manageElement(el) { + CheckboxValidation.prototype.manageElement = function manageElement(el, initial) { var _this2 = this; var scope = this._getScope(); - var item = this._addItem(el); + var item = this._addItem(el, initial); + var model = item.model = this._model; if (model) { var value = this._evalModel(model, this._filters); @@ -1087,7 +1350,11 @@ var CheckboxValidation = function (_BaseValidation) { if (_this2.guardValidate(item.el, 'change')) { return; } - _this2.handleValidate(item.el); + + _this2.handleValidate(item.el, { noopable: item.initial }); + if (item.initial) { + item.initial = null; + } } }); } else { @@ -1100,12 +1367,20 @@ var CheckboxValidation = function (_BaseValidation) { if (_this2.guardValidate(el, 'change')) { return; } - _this2.handleValidate(el); + + _this2.handleValidate(el, { noopable: item.initial }); + if (item.initial) { + item.initial = null; + } } }); } } else { - this._validator.validate({ field: this.field }); + var options = { field: this.field, noopable: initial }; + if (this._checkClassIds(el)) { + options.el = el; + } + this._validator.validate(options); } }; @@ -1132,7 +1407,10 @@ var CheckboxValidation = function (_BaseValidation) { CheckboxValidation.prototype.willUpdateFlags = function willUpdateFlags() { var _this3 = this; + var touched = arguments.length <= 0 || arguments[0] === undefined ? false : arguments[0]; + each(this._inits, function (item, index) { + touched && _this3.willUpdateTouched(item.el, 'blur'); _this3.willUpdateDirty(item.el); _this3.willUpdateModified(item.el); }); @@ -1146,12 +1424,35 @@ var CheckboxValidation = function (_BaseValidation) { }); }; - CheckboxValidation.prototype._addItem = function _addItem(el) { + CheckboxValidation.prototype.updateClasses = function updateClasses(results) { + var _this4 = this; + + var el = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1]; + + if (el) { + // for another element + this._updateClasses(el, results); + } else { + each(this._inits, function (item, index) { + _this4._updateClasses(item.el, results); + }); + } + }; + + CheckboxValidation.prototype._addItem = function _addItem(el, initial) { var item = { el: el, init: el.checked, - value: el.value + value: el.value, + initial: initial }; + + var classIds = el.getAttribute(VALIDATE_UPDATE); + if (classIds) { + el.removeAttribute(VALIDATE_UPDATE); + item.classIds = classIds.split(','); + } + this._inits.push(item); return item; }; @@ -1166,14 +1467,14 @@ var CheckboxValidation = function (_BaseValidation) { }; CheckboxValidation.prototype._getValue = function _getValue(el) { - var _this4 = this; + var _this5 = this; if (!this._inits || this._inits.length === 0) { return el.checked; } else { var _ret = function () { var vals = []; - each(_this4._inits, function (item, index) { + each(_this5._inits, function (item, index) { item.el.checked && vals.push(item.el.value); }); return { @@ -1185,15 +1486,25 @@ var CheckboxValidation = function (_BaseValidation) { } }; + CheckboxValidation.prototype._getClassIds = function _getClassIds(el) { + var classIds = void 0; + each(this._inits, function (item, index) { + if (item.el === el) { + classIds = item.classIds; + } + }); + return classIds; + }; + CheckboxValidation.prototype._checkModified = function _checkModified(target) { - var _this5 = this; + var _this6 = this; if (this._inits.length === 0) { return this._init !== target.checked; } else { var _ret2 = function () { var modified = false; - each(_this5._inits, function (item, index) { + each(_this6._inits, function (item, index) { if (!modified) { modified = item.init !== item.el.checked; } @@ -1226,11 +1537,12 @@ var RadioValidation = function (_BaseValidation) { return _this; } - RadioValidation.prototype.manageElement = function manageElement(el) { + RadioValidation.prototype.manageElement = function manageElement(el, initial) { var _this2 = this; var scope = this._getScope(); - var item = this._addItem(el); + var item = this._addItem(el, initial); + var model = item.model = this._model; if (model) { var value = this._evalModel(model, this._filters); @@ -1240,11 +1552,19 @@ var RadioValidation = function (_BaseValidation) { if (_this2.guardValidate(item.el, 'change')) { return; } - _this2.handleValidate(el); + + _this2.handleValidate(el, { noopable: item.initial }); + if (item.initial) { + item.initial = null; + } } }); } else { - this._validator.validate({ field: this.field }); + var options = { field: this.field, noopable: initial }; + if (this._checkClassIds(el)) { + options.el = el; + } + this._validator.validate(options); } }; @@ -1266,7 +1586,10 @@ var RadioValidation = function (_BaseValidation) { RadioValidation.prototype.willUpdateFlags = function willUpdateFlags() { var _this3 = this; + var touched = arguments.length <= 0 || arguments[0] === undefined ? false : arguments[0]; + each(this._inits, function (item, index) { + touched && _this3.willUpdateTouched(item.el, 'blur'); _this3.willUpdateDirty(item.el); _this3.willUpdateModified(item.el); }); @@ -1280,12 +1603,35 @@ var RadioValidation = function (_BaseValidation) { }); }; - RadioValidation.prototype._addItem = function _addItem(el) { + RadioValidation.prototype.updateClasses = function updateClasses(results) { + var _this4 = this; + + var el = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1]; + + if (el) { + // for another element + this._updateClasses(el, results); + } else { + each(this._inits, function (item, index) { + _this4._updateClasses(item.el, results); + }); + } + }; + + RadioValidation.prototype._addItem = function _addItem(el, initial) { var item = { el: el, init: el.checked, - value: el.value + value: el.value, + initial: initial }; + + var classIds = el.getAttribute(VALIDATE_UPDATE); + if (classIds) { + el.removeAttribute(VALIDATE_UPDATE); + item.classIds = classIds.split(','); + } + this._inits.push(item); return item; }; @@ -1300,14 +1646,14 @@ var RadioValidation = function (_BaseValidation) { }; RadioValidation.prototype._getValue = function _getValue(el) { - var _this4 = this; + var _this5 = this; if (!this._inits || this._inits.length === 0) { return el.checked; } else { var _ret = function () { var vals = []; - each(_this4._inits, function (item, index) { + each(_this5._inits, function (item, index) { item.el.checked && vals.push(item.el.value); }); return { @@ -1319,15 +1665,25 @@ var RadioValidation = function (_BaseValidation) { } }; + RadioValidation.prototype._getClassIds = function _getClassIds(el) { + var classIds = void 0; + each(this._inits, function (item, index) { + if (item.el === el) { + classIds = item.classIds; + } + }); + return classIds; + }; + RadioValidation.prototype._checkModified = function _checkModified(target) { - var _this5 = this; + var _this6 = this; if (this._inits.length === 0) { return this._init !== target.checked; } else { var _ret2 = function () { var modified = false; - each(_this5._inits, function (item, index) { + each(_this6._inits, function (item, index) { if (!modified) { modified = item.init !== item.el.checked; } @@ -1360,11 +1716,20 @@ var SelectValidation = function (_BaseValidation) { return _this; } - SelectValidation.prototype.manageElement = function manageElement(el) { + SelectValidation.prototype.manageElement = function manageElement(el, initial) { var _this2 = this; var scope = this._getScope(); var model = this._model; + + this._initial = initial; + + var classIds = el.getAttribute(VALIDATE_UPDATE); + if (classIds) { + el.removeAttribute(VALIDATE_UPDATE); + this._classIds = classIds.split(','); + } + if (model) { var value = this._evalModel(model, this._filters); var values = !Array.isArray(value) ? [value] : value; @@ -1376,7 +1741,11 @@ var SelectValidation = function (_BaseValidation) { if (_this2.guardValidate(el, 'change')) { return; } - _this2.handleValidate(el); + + _this2.handleValidate(el, _this2._initial); + if (_this2._initial) { + _this2._initial = null; + } } }); } @@ -1435,7 +1804,7 @@ var eventRE = /^v-on:|^@/; */ var Validator$1 = function () { - function Validator(name, dir, groups) { + function Validator(name, dir, groups, classes) { var _this = this; babelHelpers.classCallCheck(this, Validator); @@ -1451,6 +1820,7 @@ var Validator$1 = function () { this._groupValidations = {}; this._events = {}; this._modified = false; + this._classes = classes; each(groups, function (group) { _this._groupValidations[group] = []; @@ -1503,19 +1873,21 @@ var Validator$1 = function () { }); }; - Validator.prototype.manageValidation = function manageValidation(field, model, vm, el, scope, filters, detectBlur, detectChange) { + Validator.prototype.manageValidation = function manageValidation(field, model, vm, el, scope, filters, initial, detectBlur, detectChange) { var validation = null; if (el.tagName === 'SELECT') { - validation = this._manageSelectValidation(field, model, vm, el, scope, filters, detectBlur, detectChange); + validation = this._manageSelectValidation(field, model, vm, el, scope, filters, initial, detectBlur, detectChange); } else if (el.type === 'checkbox') { - validation = this._manageCheckboxValidation(field, model, vm, el, scope, filters, detectBlur, detectChange); + validation = this._manageCheckboxValidation(field, model, vm, el, scope, filters, initial, detectBlur, detectChange); } else if (el.type === 'radio') { - validation = this._manageRadioValidation(field, model, vm, el, scope, filters, detectBlur, detectChange); + validation = this._manageRadioValidation(field, model, vm, el, scope, filters, initial, detectBlur, detectChange); } else { - validation = this._manageBaseValidation(field, model, vm, el, scope, filters, detectBlur, detectChange); + validation = this._manageBaseValidation(field, model, vm, el, scope, filters, initial, detectBlur, detectChange); } + validation.setValidationClasses(this._classes); + return validation; }; @@ -1550,6 +1922,8 @@ 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; @@ -1567,7 +1941,7 @@ var Validator$1 = function () { this._validates(cb); } else { // each field - this._validate(field, touched, noopable, cb); + this._validate(field, touched, noopable, el, cb); } }; @@ -1646,11 +2020,12 @@ var Validator$1 = function () { 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 _this7 = this; - var noopable = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2]; - var cb = arguments.length <= 3 || arguments[3] === undefined ? null : arguments[3]; + var el = arguments.length <= 3 || arguments[3] === undefined ? null : arguments[3]; + var cb = arguments.length <= 4 || arguments[4] === undefined ? null : arguments[4]; var scope = this._scope; @@ -1661,7 +2036,7 @@ var Validator$1 = function () { exports$1.Vue.set(scope, field, results); _this7._fireEvents(); cb && cb(); - }, noopable); + }, noopable, el); } }; @@ -1730,9 +2105,9 @@ var Validator$1 = function () { }); }; - Validator.prototype._manageBaseValidation = function _manageBaseValidation(field, model, vm, el, scope, filters, detectBlur, detectChange) { + Validator.prototype._manageBaseValidation = function _manageBaseValidation(field, model, vm, el, scope, filters, initial, detectBlur, detectChange) { var validation = this._validations[field] = new BaseValidation(field, model, vm, el, scope, this, filters, detectBlur, detectChange); - validation.manageElement(el); + validation.manageElement(el, initial); return validation; }; @@ -1746,7 +2121,7 @@ var Validator$1 = function () { } }; - Validator.prototype._manageCheckboxValidation = function _manageCheckboxValidation(field, model, vm, el, scope, filters, detectBlur, detectChange) { + Validator.prototype._manageCheckboxValidation = function _manageCheckboxValidation(field, model, vm, el, scope, filters, initial, detectBlur, detectChange) { var validationSet = this._checkboxValidations[field]; if (!validationSet) { var validation = new CheckboxValidation(field, model, vm, el, scope, this, filters, detectBlur, detectChange); @@ -1755,7 +2130,7 @@ var Validator$1 = function () { } validationSet.elements++; - validationSet.validation.manageElement(el); + validationSet.validation.manageElement(el, initial); return validationSet.validation; }; @@ -1772,7 +2147,7 @@ var Validator$1 = function () { } }; - Validator.prototype._manageRadioValidation = function _manageRadioValidation(field, model, vm, el, scope, filters, detectBlur, detectChange) { + Validator.prototype._manageRadioValidation = function _manageRadioValidation(field, model, vm, el, scope, filters, initial, detectBlur, detectChange) { var validationSet = this._radioValidations[field]; if (!validationSet) { var validation = new RadioValidation(field, model, vm, el, scope, this, filters, detectBlur, detectChange); @@ -1781,7 +2156,7 @@ var Validator$1 = function () { } validationSet.elements++; - validationSet.validation.manageElement(el); + validationSet.validation.manageElement(el, initial); return validationSet.validation; }; @@ -1798,9 +2173,9 @@ var Validator$1 = function () { } }; - Validator.prototype._manageSelectValidation = function _manageSelectValidation(field, model, vm, el, scope, filters, detectBlur, detectChange) { + Validator.prototype._manageSelectValidation = function _manageSelectValidation(field, model, vm, el, scope, filters, initial, detectBlur, detectChange) { var validation = this._validations[field] = new SelectValidation(field, model, vm, el, scope, this, filters, detectBlur, detectChange); - validation.manageElement(el); + validation.manageElement(el, initial); return validation; }; @@ -1982,17 +2357,22 @@ var Validator$1 = function () { }(); function Validator (Vue) { - var _ = Vue.util; var FragmentFactory = Vue.FragmentFactory; var vIf = Vue.directive('if'); - var camelize = Vue.util.camelize; + 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; /** * `validator` element directive */ Vue.elementDirective('validator', { - params: ['name', 'groups', 'lazy'], + params: ['name', 'groups', 'lazy', 'classes'], bind: function bind() { var params = this.params; @@ -2007,7 +2387,12 @@ function Validator (Vue) { throw new Error('Invalid validator management error'); } - this.setupValidator(); + var classes = {}; + if (isPlainObject(this.params.classes)) { + classes = this.params.classes; + } + + this.setupValidator(classes); this.setupFragment(params.lazy); }, unbind: function unbind() { @@ -2019,17 +2404,17 @@ function Validator (Vue) { var groups = []; if (params.groups) { - if (_.isArray(params.groups)) { + if (isArray(params.groups)) { groups = params.groups; - } else if (!_.isPlainObject(params.groups) && typeof params.groups === 'string') { + } else if (!isPlainObject(params.groups) && typeof params.groups === 'string') { groups.push(params.groups); } } return groups; }, - setupValidator: function setupValidator() { - var validator = this.validator = new Validator$1(this.validatorName, this, this.getGroups()); + setupValidator: function setupValidator(classes) { + var validator = this.validator = new Validator$1(this.validatorName, this, this.getGroups(), classes); validator.enableReactive(); validator.setupScope(); validator.registerEvents(); @@ -2049,9 +2434,9 @@ function Validator (Vue) { var vm = this.vm; this.validator.waitFor(function () { - _this.anchor = _.createAnchor('vue-validator'); - _.replace(_this.el, _this.anchor); - _.extend(vm.$options, { _validator: _this.validatorName }); + _this.anchor = createAnchor('vue-validator'); + replace(_this.el, _this.anchor); + extend(vm.$options, { _validator: _this.validatorName }); _this.factory = new FragmentFactory(vm, _this.el.innerHTML); vIf.insert.call(_this); }); @@ -2199,10 +2584,11 @@ function plugin(Vue) { Override(Vue); Validator(Vue); + ValidateClass(Vue); Validate(Vue); } -plugin.version = '2.0.2'; +plugin.version = '2.1.0'; if (typeof window !== 'undefined' && window.Vue) { window.Vue.use(plugin); diff --git a/dist/vue-validator.js b/dist/vue-validator.js index 9df00fc..434d42f 100644 --- a/dist/vue-validator.js +++ b/dist/vue-validator.js @@ -1,5 +1,5 @@ /*! - * vue-validator v2.0.2 + * vue-validator v2.1.0 * (c) 2016 kazuya kawaguchi * Released under the MIT License. */ @@ -191,6 +191,27 @@ return p && typeof p.then === 'function'; } + /** + * Togging classes + * + * @param {Element} el + * @param {String} key + * @param {Function} fn + */ + + function toggleClasses(el, key, fn) { + key = key.trim(); + if (key.indexOf(' ') === -1) { + fn(el, key); + return; + } + + var keys = key.split(/\s+/); + for (var i = 0, l = keys.length; i < l; i++) { + fn(el, keys[i]); + } + } + /** * Fundamental validate functions */ @@ -407,16 +428,109 @@ var validators = Object.freeze({ }; } + var VALIDATE_UPDATE = '__vue-validator-validate-update__'; + var PRIORITY_VALIDATE = 16; + var PRIORITY_VALIDATE_CLASS = 32; + var REGEX_FILTER = /[^|]\|[^|]/; + var REGEX_VALIDATE_DIRECTIVE = /^v-validate(?:$|:(.*)$)/; + + 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; + + /** + * `v-validate-class` directive + */ + + Vue.directive('validate-class', { + terminal: true, + priority: vIf.priority + PRIORITY_VALIDATE_CLASS, + + bind: function bind() { + var _this = this; + + var id = String(classId++); + this.setClassIds(this.el, id); + + this.vm.$on(VALIDATE_UPDATE, this.cb = function (classIds, validation, results) { + if (classIds.indexOf(id) > -1) { + validation.updateClasses(results, _this.frag.node); + } + }); + + this.setupFragment(); + }, + unbind: function unbind() { + this.vm.$off(VALIDATE_UPDATE, this.cb); + this.teardownFragment(); + }, + setClassIds: function setClassIds(el, id) { + var childNodes = toArray(el.childNodes); + for (var i = 0, l = childNodes.length; i < l; i++) { + var element = childNodes[i]; + if (element.nodeType === 1) { + var hasAttrs = element.hasAttributes(); + var attrs = hasAttrs && toArray(element.attributes); + for (var k = 0, _l = attrs.length; k < _l; k++) { + var attr = attrs[k]; + if (attr.name.match(REGEX_VALIDATE_DIRECTIVE)) { + var existingId = element.getAttribute(VALIDATE_UPDATE); + var value = existingId ? existingId + ',' + id : id; + element.setAttribute(VALIDATE_UPDATE, value); + } + } + } + + if (element.hasChildNodes()) { + this.setClassIds(element, id); + } + } + }, + setupFragment: function setupFragment() { + this.anchor = createAnchor('v-validate-class'); + replace(this.el, this.anchor); + + this.factory = new FragmentFactory(this.vm, this.el); + this.frag = this.factory.create(this._host, this._scope, this._frag); + this.frag.before(this.anchor); + }, + teardownFragment: function teardownFragment() { + if (this.frag) { + this.frag.remove(); + this.frag = null; + this.factory = null; + } + + replace(this.anchor, this.el); + this.anchor = null; + } + }); + } + function Validate (Vue) { - var _ = Vue.util; var vIf = Vue.directive('if'); var FragmentFactory = Vue.FragmentFactory; var parseDirective = Vue.parsers.directive.parseDirective; - var REGEX_FILTER = /[^|]\|[^|]/; + 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; // Test for IE10/11 textarea placeholder clone bug + function checkTextareaCloneBug() { - if (_.inBrowser) { + if (inBrowser) { var t = document.createElement('textarea'); t.placeholder = 't'; return t.cloneNode(true).value === 't'; @@ -432,8 +546,8 @@ var validators = Object.freeze({ Vue.directive('validate', { terminal: true, - priority: vIf.priority + 16, - params: ['group', 'field', 'detect-blur', 'detect-change', 'initial'], + priority: vIf.priority + PRIORITY_VALIDATE, + params: ['group', 'field', 'detect-blur', 'detect-change', 'initial', 'classes'], paramWatchers: { detectBlur: function detectBlur(val, old) { @@ -467,6 +581,12 @@ var validators = Object.freeze({ return; } + if ('development' !== 'production' && !(this.arg || this.params.field)) { + warn('you need specify field name for v-validate directive.'); + this._invalid = true; + return; + } + var validatorName = this.vm.$options._validator; if ('development' !== 'production' && !validatorName) { warn('v-validate need to use into validator element directive: ' + '(e.g. ' + '' + ').'); @@ -492,13 +612,18 @@ var validators = Object.freeze({ return; } - if (_.isPlainObject(value)) { + if (isPlainObject(value)) { this.handleObject(value); } else if (Array.isArray(value)) { this.handleArray(value); } - this.validator.validate({ field: this.field, noopable: this._initialNoopValidation }); + var options = { field: this.field, noopable: this._initialNoopValidation }; + if (this.frag) { + options.el = this.frag.node; + } + this.validator.validate(options); + if (this._initialNoopValidation) { this._initialNoopValidation = null; } @@ -526,9 +651,11 @@ var validators = Object.freeze({ var params = this.params; var validator = this.validator = this.vm._validatorMaps[name]; - this.field = _.camelize(this.arg ? this.arg : params.field); + this.field = camelize(this.arg ? this.arg : params.field); - this.validation = validator.manageValidation(this.field, model, this.vm, this.frag.node, this._scope, filters, this.isDetectBlur(params.detectBlur), this.isDetectChange(params.detectChange)); + this.validation = validator.manageValidation(this.field, model, this.vm, this.frag.node, this._scope, filters, params.initial, this.isDetectBlur(params.detectBlur), this.isDetectChange(params.detectChange)); + + isPlainObject(params.classes) && this.validation.setValidationClasses(params.classes); params.group && validator.addGroupValidation(params.group, this.field); @@ -539,23 +666,23 @@ var validators = Object.freeze({ var validation = this.validation; var el = this.frag.node; - this.onBlur = _.bind(validation.listener, validation); - _.on(el, 'blur', this.onBlur); + this.onBlur = bind(validation.listener, validation); + on(el, 'blur', this.onBlur); if ((el.type === 'radio' || el.tagName === 'SELECT') && !model) { - this.onChange = _.bind(validation.listener, validation); - _.on(el, 'change', this.onChange); + this.onChange = bind(validation.listener, validation); + on(el, 'change', this.onChange); } else if (el.type === 'checkbox') { if (!model) { - this.onChange = _.bind(validation.listener, validation); - _.on(el, 'change', this.onChange); + this.onChange = bind(validation.listener, validation); + on(el, 'change', this.onChange); } else { - this.onClick = _.bind(validation.listener, validation); - _.on(el, 'click', this.onClick); + this.onClick = bind(validation.listener, validation); + on(el, 'click', this.onClick); } } else { if (!model) { - this.onInput = _.bind(validation.listener, validation); - _.on(el, 'input', this.onInput); + this.onInput = bind(validation.listener, validation); + on(el, 'input', this.onInput); } } }, @@ -563,22 +690,22 @@ var validators = Object.freeze({ var el = this.frag.node; if (this.onInput) { - _.off(el, 'input', this.onInput); + off(el, 'input', this.onInput); this.onInput = null; } if (this.onClick) { - _.off(el, 'click', this.onClick); + off(el, 'click', this.onClick); this.onClick = null; } if (this.onChange) { - _.off(el, 'change', this.onChange); + off(el, 'change', this.onChange); this.onChange = null; } if (this.onBlur) { - _.off(el, 'blur', this.onBlur); + off(el, 'blur', this.onBlur); this.onBlur = null; } }, @@ -596,8 +723,8 @@ var validators = Object.freeze({ } }, setupFragment: function setupFragment() { - this.anchor = _.createAnchor('v-validate'); - _.replace(this.el, this.anchor); + this.anchor = createAnchor('v-validate'); + replace(this.el, this.anchor); this.factory = new FragmentFactory(this.vm, this.shimNode(this.el)); this.frag = this.factory.create(this._host, this._scope, this._frag); @@ -610,7 +737,7 @@ var validators = Object.freeze({ this.factory = null; } - _.replace(this.anchor, this.el); + replace(this.anchor, this.el); this.anchor = null; }, handleArray: function handleArray(value) { @@ -624,7 +751,7 @@ var validators = Object.freeze({ var _this2 = this; each(value, function (val, key) { - if (_.isPlainObject(val)) { + if (isPlainObject(val)) { if ('rule' in val) { var msg = 'message' in val ? val.message : null; var initial = 'initial' in val ? val.initial : null; @@ -685,13 +812,23 @@ var validators = Object.freeze({ this._validators = {}; this._detectBlur = detectBlur; this._detectChange = detectChange; + this._classes = {}; } - BaseValidation.prototype.manageElement = function manageElement(el) { + BaseValidation.prototype.manageElement = function manageElement(el, initial) { var _this = this; var scope = this._getScope(); var model = this._model; + + this._initial = initial; + + var classIds = el.getAttribute(VALIDATE_UPDATE); + if (classIds) { + el.removeAttribute(VALIDATE_UPDATE); + this._classIds = classIds.split(','); + } + if (model) { el.value = this._evalModel(model, this._filters); this._unwatch = scope.$watch(model, function (val, old) { @@ -699,7 +836,11 @@ var validators = Object.freeze({ if (_this.guardValidate(el, 'input')) { return; } - _this.handleValidate(el); + + _this.handleValidate(el, _this._initial); + if (_this._initial) { + _this._initial = null; + } } }, { deep: true }); } @@ -727,6 +868,14 @@ var validators = Object.freeze({ } }; + BaseValidation.prototype.setValidationClasses = function setValidationClasses(classes) { + var _this2 = this; + + each(classes, function (value, key) { + _this2._classes[key] = value; + }); + }; + BaseValidation.prototype.willUpdateFlags = function willUpdateFlags() { var touched = arguments.length <= 0 || arguments[0] === undefined ? false : arguments[0]; @@ -762,21 +911,29 @@ var validators = Object.freeze({ return; } - this.handleValidate(e.target, e.type); + this.handleValidate(e.target, { type: e.type }); }; - BaseValidation.prototype.handleValidate = function handleValidate(el, type) { + 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; + this.willUpdateTouched(el, type); this.willUpdateDirty(el); this.willUpdateModified(el); - this._validator.validate({ field: this.field }); + this._validator.validate({ field: this.field, el: el, noopable: noopable }); }; BaseValidation.prototype.validate = function validate(cb) { - var _this2 = this; + var _this3 = this; var noopable = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1]; + var el = arguments.length <= 2 || arguments[2] === undefined ? null : arguments[2]; var _ = exports$1.Vue.util; @@ -785,7 +942,7 @@ var validators = Object.freeze({ var valid = true; this._runValidators(function (descriptor, name, done) { - var asset = _this2._resolveValidator(name); + var asset = _this3._resolveValidator(name); var validator = null; var msg = null; @@ -816,8 +973,8 @@ var validators = Object.freeze({ } if (validator) { - var value = _this2._getValue(_this2._el); - _this2._invokeValidator(_this2._vm, validator, value, descriptor.arg, function (ret, err) { + var value = _this3._getValue(_this3._el); + _this3._invokeValidator(_this3._vm, validator, value, descriptor.arg, function (ret, err) { if (!ret) { valid = false; if (err) { @@ -826,7 +983,7 @@ var validators = Object.freeze({ results[name] = err; } else if (msg) { var error = { validator: name }; - error.message = typeof msg === 'function' ? msg.call(_this2._vm, _this2.field, descriptor.arg) : msg; + error.message = typeof msg === 'function' ? msg.call(_this3._vm, _this3.field, descriptor.arg) : msg; errors.push(error); results[name] = error.message; } else { @@ -843,22 +1000,24 @@ var validators = Object.freeze({ } }, function () { // finished - _this2._fireEvent(_this2._el, valid ? 'valid' : 'invalid'); + _this3._fireEvent(_this3._el, valid ? 'valid' : 'invalid'); var props = { valid: valid, invalid: !valid, - touched: _this2.touched, - untouched: !_this2.touched, - dirty: _this2.dirty, - pristine: !_this2.dirty, - modified: _this2.modified + touched: _this3.touched, + untouched: !_this3.touched, + dirty: _this3.dirty, + pristine: !_this3.dirty, + modified: _this3.modified }; if (!empty(errors)) { props.errors = errors; } _.extend(results, props); + _this3.willUpdateClasses(results, el); + cb(results); }); }; @@ -880,6 +1039,29 @@ var validators = Object.freeze({ this._init = this._getValue(this._el); }; + BaseValidation.prototype.willUpdateClasses = function willUpdateClasses(results) { + var _this4 = this; + + var el = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1]; + + if (this._checkClassIds(el)) { + (function () { + var classIds = _this4._getClassIds(el); + _this4.vm.$nextTick(function () { + _this4.vm.$emit(VALIDATE_UPDATE, classIds, _this4, results); + }); + })(); + } else { + this.updateClasses(results); + } + }; + + BaseValidation.prototype.updateClasses = function updateClasses(results) { + var el = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1]; + + this._updateClasses(el || this._el, results); + }; + BaseValidation.prototype.guardValidate = function guardValidate(el, type) { if (type && type === 'blur' && !this.detectBlur) { return true; @@ -908,10 +1090,18 @@ var validators = Object.freeze({ return this._forScope || this._vm; }; + BaseValidation.prototype._getClassIds = function _getClassIds(el) { + return this._classIds; + }; + BaseValidation.prototype._checkModified = function _checkModified(target) { return this._init !== this._getValue(target); }; + BaseValidation.prototype._checkClassIds = function _checkClassIds(el) { + return this._getClassIds(el); + }; + BaseValidation.prototype._fireEvent = function _fireEvent(el, type, args) { trigger(el, type, args); }; @@ -929,6 +1119,78 @@ var validators = Object.freeze({ } }; + BaseValidation.prototype._updateClasses = function _updateClasses(el, results) { + this._toggleValid(el, results.valid); + this._toggleTouched(el, results.touched); + this._togglePristine(el, results.pristine); + this._toggleModfied(el, results.modified); + }; + + 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 validClass = this._classes.valid || 'valid'; + var invalidClass = this._classes.invalid || 'invalid'; + + if (valid) { + toggleClasses(el, validClass, addClass); + toggleClasses(el, invalidClass, removeClass); + } else { + toggleClasses(el, validClass, removeClass); + toggleClasses(el, invalidClass, addClass); + } + }; + + 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 touchedClass = this._classes.touched || 'touched'; + var untouchedClass = this._classes.untouched || 'untouched'; + + if (touched) { + toggleClasses(el, touchedClass, addClass); + toggleClasses(el, untouchedClass, removeClass); + } else { + toggleClasses(el, touchedClass, removeClass); + toggleClasses(el, untouchedClass, addClass); + } + }; + + 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 pristineClass = this._classes.pristine || 'pristine'; + var dirtyClass = this._classes.dirty || 'dirty'; + + if (pristine) { + toggleClasses(el, pristineClass, addClass); + toggleClasses(el, dirtyClass, removeClass); + } else { + toggleClasses(el, pristineClass, removeClass); + toggleClasses(el, dirtyClass, addClass); + } + }; + + 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 modifiedClass = this._classes.modified || 'modified'; + + if (modified) { + toggleClasses(el, modifiedClass, addClass); + } else { + toggleClasses(el, modifiedClass, removeClass); + } + }; + BaseValidation.prototype._applyFilters = function _applyFilters(value, oldValue, filters, write) { var resolveAsset = exports$1.Vue.util.resolveAsset; var scope = this._getScope(); @@ -1076,11 +1338,12 @@ var validators = Object.freeze({ return _this; } - CheckboxValidation.prototype.manageElement = function manageElement(el) { + CheckboxValidation.prototype.manageElement = function manageElement(el, initial) { var _this2 = this; var scope = this._getScope(); - var item = this._addItem(el); + var item = this._addItem(el, initial); + var model = item.model = this._model; if (model) { var value = this._evalModel(model, this._filters); @@ -1091,7 +1354,11 @@ var validators = Object.freeze({ if (_this2.guardValidate(item.el, 'change')) { return; } - _this2.handleValidate(item.el); + + _this2.handleValidate(item.el, { noopable: item.initial }); + if (item.initial) { + item.initial = null; + } } }); } else { @@ -1104,12 +1371,20 @@ var validators = Object.freeze({ if (_this2.guardValidate(el, 'change')) { return; } - _this2.handleValidate(el); + + _this2.handleValidate(el, { noopable: item.initial }); + if (item.initial) { + item.initial = null; + } } }); } } else { - this._validator.validate({ field: this.field }); + var options = { field: this.field, noopable: initial }; + if (this._checkClassIds(el)) { + options.el = el; + } + this._validator.validate(options); } }; @@ -1136,7 +1411,10 @@ var validators = Object.freeze({ CheckboxValidation.prototype.willUpdateFlags = function willUpdateFlags() { var _this3 = this; + var touched = arguments.length <= 0 || arguments[0] === undefined ? false : arguments[0]; + each(this._inits, function (item, index) { + touched && _this3.willUpdateTouched(item.el, 'blur'); _this3.willUpdateDirty(item.el); _this3.willUpdateModified(item.el); }); @@ -1150,12 +1428,35 @@ var validators = Object.freeze({ }); }; - CheckboxValidation.prototype._addItem = function _addItem(el) { + CheckboxValidation.prototype.updateClasses = function updateClasses(results) { + var _this4 = this; + + var el = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1]; + + if (el) { + // for another element + this._updateClasses(el, results); + } else { + each(this._inits, function (item, index) { + _this4._updateClasses(item.el, results); + }); + } + }; + + CheckboxValidation.prototype._addItem = function _addItem(el, initial) { var item = { el: el, init: el.checked, - value: el.value + value: el.value, + initial: initial }; + + var classIds = el.getAttribute(VALIDATE_UPDATE); + if (classIds) { + el.removeAttribute(VALIDATE_UPDATE); + item.classIds = classIds.split(','); + } + this._inits.push(item); return item; }; @@ -1170,14 +1471,14 @@ var validators = Object.freeze({ }; CheckboxValidation.prototype._getValue = function _getValue(el) { - var _this4 = this; + var _this5 = this; if (!this._inits || this._inits.length === 0) { return el.checked; } else { var _ret = function () { var vals = []; - each(_this4._inits, function (item, index) { + each(_this5._inits, function (item, index) { item.el.checked && vals.push(item.el.value); }); return { @@ -1189,15 +1490,25 @@ var validators = Object.freeze({ } }; + CheckboxValidation.prototype._getClassIds = function _getClassIds(el) { + var classIds = void 0; + each(this._inits, function (item, index) { + if (item.el === el) { + classIds = item.classIds; + } + }); + return classIds; + }; + CheckboxValidation.prototype._checkModified = function _checkModified(target) { - var _this5 = this; + var _this6 = this; if (this._inits.length === 0) { return this._init !== target.checked; } else { var _ret2 = function () { var modified = false; - each(_this5._inits, function (item, index) { + each(_this6._inits, function (item, index) { if (!modified) { modified = item.init !== item.el.checked; } @@ -1230,11 +1541,12 @@ var validators = Object.freeze({ return _this; } - RadioValidation.prototype.manageElement = function manageElement(el) { + RadioValidation.prototype.manageElement = function manageElement(el, initial) { var _this2 = this; var scope = this._getScope(); - var item = this._addItem(el); + var item = this._addItem(el, initial); + var model = item.model = this._model; if (model) { var value = this._evalModel(model, this._filters); @@ -1244,11 +1556,19 @@ var validators = Object.freeze({ if (_this2.guardValidate(item.el, 'change')) { return; } - _this2.handleValidate(el); + + _this2.handleValidate(el, { noopable: item.initial }); + if (item.initial) { + item.initial = null; + } } }); } else { - this._validator.validate({ field: this.field }); + var options = { field: this.field, noopable: initial }; + if (this._checkClassIds(el)) { + options.el = el; + } + this._validator.validate(options); } }; @@ -1270,7 +1590,10 @@ var validators = Object.freeze({ RadioValidation.prototype.willUpdateFlags = function willUpdateFlags() { var _this3 = this; + var touched = arguments.length <= 0 || arguments[0] === undefined ? false : arguments[0]; + each(this._inits, function (item, index) { + touched && _this3.willUpdateTouched(item.el, 'blur'); _this3.willUpdateDirty(item.el); _this3.willUpdateModified(item.el); }); @@ -1284,12 +1607,35 @@ var validators = Object.freeze({ }); }; - RadioValidation.prototype._addItem = function _addItem(el) { + RadioValidation.prototype.updateClasses = function updateClasses(results) { + var _this4 = this; + + var el = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1]; + + if (el) { + // for another element + this._updateClasses(el, results); + } else { + each(this._inits, function (item, index) { + _this4._updateClasses(item.el, results); + }); + } + }; + + RadioValidation.prototype._addItem = function _addItem(el, initial) { var item = { el: el, init: el.checked, - value: el.value + value: el.value, + initial: initial }; + + var classIds = el.getAttribute(VALIDATE_UPDATE); + if (classIds) { + el.removeAttribute(VALIDATE_UPDATE); + item.classIds = classIds.split(','); + } + this._inits.push(item); return item; }; @@ -1304,14 +1650,14 @@ var validators = Object.freeze({ }; RadioValidation.prototype._getValue = function _getValue(el) { - var _this4 = this; + var _this5 = this; if (!this._inits || this._inits.length === 0) { return el.checked; } else { var _ret = function () { var vals = []; - each(_this4._inits, function (item, index) { + each(_this5._inits, function (item, index) { item.el.checked && vals.push(item.el.value); }); return { @@ -1323,15 +1669,25 @@ var validators = Object.freeze({ } }; + RadioValidation.prototype._getClassIds = function _getClassIds(el) { + var classIds = void 0; + each(this._inits, function (item, index) { + if (item.el === el) { + classIds = item.classIds; + } + }); + return classIds; + }; + RadioValidation.prototype._checkModified = function _checkModified(target) { - var _this5 = this; + var _this6 = this; if (this._inits.length === 0) { return this._init !== target.checked; } else { var _ret2 = function () { var modified = false; - each(_this5._inits, function (item, index) { + each(_this6._inits, function (item, index) { if (!modified) { modified = item.init !== item.el.checked; } @@ -1364,11 +1720,20 @@ var validators = Object.freeze({ return _this; } - SelectValidation.prototype.manageElement = function manageElement(el) { + SelectValidation.prototype.manageElement = function manageElement(el, initial) { var _this2 = this; var scope = this._getScope(); var model = this._model; + + this._initial = initial; + + var classIds = el.getAttribute(VALIDATE_UPDATE); + if (classIds) { + el.removeAttribute(VALIDATE_UPDATE); + this._classIds = classIds.split(','); + } + if (model) { var value = this._evalModel(model, this._filters); var values = !Array.isArray(value) ? [value] : value; @@ -1380,7 +1745,11 @@ var validators = Object.freeze({ if (_this2.guardValidate(el, 'change')) { return; } - _this2.handleValidate(el); + + _this2.handleValidate(el, _this2._initial); + if (_this2._initial) { + _this2._initial = null; + } } }); } @@ -1439,7 +1808,7 @@ var validators = Object.freeze({ */ var Validator$1 = function () { - function Validator(name, dir, groups) { + function Validator(name, dir, groups, classes) { var _this = this; babelHelpers.classCallCheck(this, Validator); @@ -1455,6 +1824,7 @@ var validators = Object.freeze({ this._groupValidations = {}; this._events = {}; this._modified = false; + this._classes = classes; each(groups, function (group) { _this._groupValidations[group] = []; @@ -1507,19 +1877,21 @@ var validators = Object.freeze({ }); }; - Validator.prototype.manageValidation = function manageValidation(field, model, vm, el, scope, filters, detectBlur, detectChange) { + Validator.prototype.manageValidation = function manageValidation(field, model, vm, el, scope, filters, initial, detectBlur, detectChange) { var validation = null; if (el.tagName === 'SELECT') { - validation = this._manageSelectValidation(field, model, vm, el, scope, filters, detectBlur, detectChange); + validation = this._manageSelectValidation(field, model, vm, el, scope, filters, initial, detectBlur, detectChange); } else if (el.type === 'checkbox') { - validation = this._manageCheckboxValidation(field, model, vm, el, scope, filters, detectBlur, detectChange); + validation = this._manageCheckboxValidation(field, model, vm, el, scope, filters, initial, detectBlur, detectChange); } else if (el.type === 'radio') { - validation = this._manageRadioValidation(field, model, vm, el, scope, filters, detectBlur, detectChange); + validation = this._manageRadioValidation(field, model, vm, el, scope, filters, initial, detectBlur, detectChange); } else { - validation = this._manageBaseValidation(field, model, vm, el, scope, filters, detectBlur, detectChange); + validation = this._manageBaseValidation(field, model, vm, el, scope, filters, initial, detectBlur, detectChange); } + validation.setValidationClasses(this._classes); + return validation; }; @@ -1554,6 +1926,8 @@ 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; @@ -1571,7 +1945,7 @@ var validators = Object.freeze({ this._validates(cb); } else { // each field - this._validate(field, touched, noopable, cb); + this._validate(field, touched, noopable, el, cb); } }; @@ -1650,11 +2024,12 @@ var validators = Object.freeze({ 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 _this7 = this; - var noopable = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2]; - var cb = arguments.length <= 3 || arguments[3] === undefined ? null : arguments[3]; + var el = arguments.length <= 3 || arguments[3] === undefined ? null : arguments[3]; + var cb = arguments.length <= 4 || arguments[4] === undefined ? null : arguments[4]; var scope = this._scope; @@ -1665,7 +2040,7 @@ var validators = Object.freeze({ exports$1.Vue.set(scope, field, results); _this7._fireEvents(); cb && cb(); - }, noopable); + }, noopable, el); } }; @@ -1734,9 +2109,9 @@ var validators = Object.freeze({ }); }; - Validator.prototype._manageBaseValidation = function _manageBaseValidation(field, model, vm, el, scope, filters, detectBlur, detectChange) { + Validator.prototype._manageBaseValidation = function _manageBaseValidation(field, model, vm, el, scope, filters, initial, detectBlur, detectChange) { var validation = this._validations[field] = new BaseValidation(field, model, vm, el, scope, this, filters, detectBlur, detectChange); - validation.manageElement(el); + validation.manageElement(el, initial); return validation; }; @@ -1750,7 +2125,7 @@ var validators = Object.freeze({ } }; - Validator.prototype._manageCheckboxValidation = function _manageCheckboxValidation(field, model, vm, el, scope, filters, detectBlur, detectChange) { + Validator.prototype._manageCheckboxValidation = function _manageCheckboxValidation(field, model, vm, el, scope, filters, initial, detectBlur, detectChange) { var validationSet = this._checkboxValidations[field]; if (!validationSet) { var validation = new CheckboxValidation(field, model, vm, el, scope, this, filters, detectBlur, detectChange); @@ -1759,7 +2134,7 @@ var validators = Object.freeze({ } validationSet.elements++; - validationSet.validation.manageElement(el); + validationSet.validation.manageElement(el, initial); return validationSet.validation; }; @@ -1776,7 +2151,7 @@ var validators = Object.freeze({ } }; - Validator.prototype._manageRadioValidation = function _manageRadioValidation(field, model, vm, el, scope, filters, detectBlur, detectChange) { + Validator.prototype._manageRadioValidation = function _manageRadioValidation(field, model, vm, el, scope, filters, initial, detectBlur, detectChange) { var validationSet = this._radioValidations[field]; if (!validationSet) { var validation = new RadioValidation(field, model, vm, el, scope, this, filters, detectBlur, detectChange); @@ -1785,7 +2160,7 @@ var validators = Object.freeze({ } validationSet.elements++; - validationSet.validation.manageElement(el); + validationSet.validation.manageElement(el, initial); return validationSet.validation; }; @@ -1802,9 +2177,9 @@ var validators = Object.freeze({ } }; - Validator.prototype._manageSelectValidation = function _manageSelectValidation(field, model, vm, el, scope, filters, detectBlur, detectChange) { + Validator.prototype._manageSelectValidation = function _manageSelectValidation(field, model, vm, el, scope, filters, initial, detectBlur, detectChange) { var validation = this._validations[field] = new SelectValidation(field, model, vm, el, scope, this, filters, detectBlur, detectChange); - validation.manageElement(el); + validation.manageElement(el, initial); return validation; }; @@ -1986,17 +2361,22 @@ var validators = Object.freeze({ }(); function Validator (Vue) { - var _ = Vue.util; var FragmentFactory = Vue.FragmentFactory; var vIf = Vue.directive('if'); - var camelize = Vue.util.camelize; + 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; /** * `validator` element directive */ Vue.elementDirective('validator', { - params: ['name', 'groups', 'lazy'], + params: ['name', 'groups', 'lazy', 'classes'], bind: function bind() { var params = this.params; @@ -2011,7 +2391,12 @@ var validators = Object.freeze({ throw new Error('Invalid validator management error'); } - this.setupValidator(); + var classes = {}; + if (isPlainObject(this.params.classes)) { + classes = this.params.classes; + } + + this.setupValidator(classes); this.setupFragment(params.lazy); }, unbind: function unbind() { @@ -2023,17 +2408,17 @@ var validators = Object.freeze({ var groups = []; if (params.groups) { - if (_.isArray(params.groups)) { + if (isArray(params.groups)) { groups = params.groups; - } else if (!_.isPlainObject(params.groups) && typeof params.groups === 'string') { + } else if (!isPlainObject(params.groups) && typeof params.groups === 'string') { groups.push(params.groups); } } return groups; }, - setupValidator: function setupValidator() { - var validator = this.validator = new Validator$1(this.validatorName, this, this.getGroups()); + setupValidator: function setupValidator(classes) { + var validator = this.validator = new Validator$1(this.validatorName, this, this.getGroups(), classes); validator.enableReactive(); validator.setupScope(); validator.registerEvents(); @@ -2053,9 +2438,9 @@ var validators = Object.freeze({ var vm = this.vm; this.validator.waitFor(function () { - _this.anchor = _.createAnchor('vue-validator'); - _.replace(_this.el, _this.anchor); - _.extend(vm.$options, { _validator: _this.validatorName }); + _this.anchor = createAnchor('vue-validator'); + replace(_this.el, _this.anchor); + extend(vm.$options, { _validator: _this.validatorName }); _this.factory = new FragmentFactory(vm, _this.el.innerHTML); vIf.insert.call(_this); }); @@ -2203,10 +2588,11 @@ var validators = Object.freeze({ Override(Vue); Validator(Vue); + ValidateClass(Vue); Validate(Vue); } - plugin.version = '2.0.2'; + plugin.version = '2.1.0'; if (typeof window !== 'undefined' && window.Vue) { window.Vue.use(plugin); diff --git a/dist/vue-validator.min.js b/dist/vue-validator.min.js index ca5f72a..62188a4 100644 --- a/dist/vue-validator.min.js +++ b/dist/vue-validator.min.js @@ -1,6 +1,7 @@ /*! - * vue-validator v2.0.2 + * vue-validator v2.1.0 * (c) 2016 kazuya kawaguchi * Released under the MIT License. */ -!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define(i):t.VueValidator=i()}(this,function(){"use strict";function t(t,i){window.console&&(console.warn("[vue-validator] "+t),i&&console.warn(i.stack))}function i(t){if(null===t||void 0===t)return!0;if(Array.isArray(t)){if(t.length>0)return!1;if(0===t.length)return!0}else if(b.Vue.util.isPlainObject(t))for(var i in t)if(b.Vue.util.hasOwn(t,i))return!1;return!0}function e(t,i,e){if(Array.isArray(t))for(var n=0;ne&&(i=r(t[e]),i);e++);return i}return!1}return"number"==typeof t||"function"==typeof t?!0:"boolean"==typeof t?t:"string"==typeof t?t.length>0:null!==t&&"object"===("undefined"==typeof t?"undefined":V["typeof"](t))?Object.keys(t).length>0:null===t||void 0===t?!1:void 0}function s(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 l(t,i){return"string"==typeof t?c(i,10)&&t.length>=parseInt(i,10):Array.isArray(t)?t.length>=parseInt(i,10):!1}function d(t,i){return"string"==typeof t?c(i,10)&&t.length<=parseInt(i,10):Array.isArray(t)?t.length<=parseInt(i,10):!1}function u(t,i){return!isNaN(+t)&&!isNaN(+i)&&+t>=+i}function h(t,i){return!isNaN(+t)&&!isNaN(+i)&&+i>=+t}function c(t){return/^(-?[1-9]\d*|0)$/.test(t)}function f(t){var i=t.util.extend,e=Object.create(null);i(e,w),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 p(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 v(t){function i(){if(n.inBrowser){var t=document.createElement("textarea");return t.placeholder="t","t"===t.cloneNode(!0).value}return!1}var n=t.util,a=t.directive("if"),o=t.FragmentFactory,r=t.parsers.directive.parseDirective,s=/[^|]\|[^|]/,l=i();t.directive("validate",{terminal:!0,priority:a.priority+16,params:["group","field","detect-blur","detect-change","initial"],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){t&&!this._invalid&&(n.isPlainObject(t)?this.handleObject(t):Array.isArray(t)&&this.handleArray(t),this.validator.validate({field:this.field,noopable:this._initialNoopValidation}),this._initialNoopValidation&&(this._initialNoopValidation=null))},unbind:function(){this._invalid||(this.unlisten(),this.teardownValidate(),this.teardownFragment(),this.model=null)},parseModelRaw:function(t){if(s.test(t)){var i=r(t);return{model:i.expression,filters:i.filters}}return{model:t}},setupValidate:function(t,i,e){var a=this.params,o=this.validator=this.vm._validatorMaps[t];this.field=n.camelize(this.arg?this.arg:a.field),this.validation=o.manageValidation(this.field,i,this.vm,this.frag.node,this._scope,e,this.isDetectBlur(a.detectBlur),this.isDetectChange(a.detectChange)),a.group&&o.addGroupValidation(a.group,this.field),this._initialNoopValidation=this.isInitialNoopValidation(a.initial)},listen:function(){var t=this.model,i=this.validation,e=this.frag.node;this.onBlur=n.bind(i.listener,i),n.on(e,"blur",this.onBlur),"radio"!==e.type&&"SELECT"!==e.tagName||t?"checkbox"===e.type?t?(this.onClick=n.bind(i.listener,i),n.on(e,"click",this.onClick)):(this.onChange=n.bind(i.listener,i),n.on(e,"change",this.onChange)):t||(this.onInput=n.bind(i.listener,i),n.on(e,"input",this.onInput)):(this.onChange=n.bind(i.listener,i),n.on(e,"change",this.onChange))},unlisten:function(){var t=this.frag.node;this.onInput&&(n.off(t,"input",this.onInput),this.onInput=null),this.onClick&&(n.off(t,"click",this.onClick),this.onClick=null),this.onChange&&(n.off(t,"change",this.onChange),this.onChange=null),this.onBlur&&(n.off(t,"blur",this.onBlur),this.onBlur=null)},teardownValidate:function(){if(this.validator&&this.validation){var t=this.frag.node;this.params.group&&this.validator.removeGroupValidation(this.params.group,this.field),this.validator.unmanageValidation(this.field,t),this.validator=null,this.validation=null,this.field=null}},setupFragment:function(){this.anchor=n.createAnchor("v-validate"),n.replace(this.el,this.anchor),this.factory=new o(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),n.replace(this.anchor,this.el),this.anchor=null},handleArray:function(t){var i=this;e(t,function(t){i.validation.setValidation(t)})},handleObject:function(t){var i=this;e(t,function(t,e){if(n.isPlainObject(t)){if("rule"in t){var a="message"in t?t.message:null,o="initial"in t?t.initial:null;i.validation.setValidation(e,t.rule,a,o)}}else i.validation.setValidation(e,t)})},isDetectBlur:function(t){return void 0===t||"on"===t||t===!0},isDetectChange:function(t){return void 0===t||"on"===t||t===!0},isInitialNoopValidation:function(t){return"off"===t||t===!1},shimNode:function(t){var i=t;if(l&&"TEXTAREA"===t.tagName){i=t.cloneNode(!0),i.value=t.value;for(var e=i.childNodes.length;e--;)i.removeChild(i.childNodes[e])}return i}})}function _(t){var i=t.util,e=t.FragmentFactory,n=t.directive("if"),a=t.util.camelize;t.elementDirective("validator",{params:["name","groups","lazy"],bind:function(){var t=this.params;if(this.validatorName="$"+a(t.name),!this.vm._validatorMaps)throw new Error("Invalid validator management error");this.setupValidator(),this.setupFragment(t.lazy)},unbind:function(){this.teardownFragment(),this.teardownValidator()},getGroups:function(){var t=this.params,e=[];return t.groups&&(i.isArray(t.groups)?e=t.groups:i.isPlainObject(t.groups)||"string"!=typeof t.groups||e.push(t.groups)),e},setupValidator:function(){var t=this.validator=new x(this.validatorName,this,this.getGroups());t.enableReactive(),t.setupScope(),t.registerEvents()},teardownValidator:function(){this.validator.unregisterEvents(),this.validator.disableReactive(),this.validatorName&&(this.validatorName=null,this.validator=null)},setupFragment:function(t){var a=this,o=this.vm;this.validator.waitFor(function(){a.anchor=i.createAnchor("vue-validator"),i.replace(a.el,a.anchor),i.extend(o.$options,{_validator:a.validatorName}),a.factory=new e(o,a.el.innerHTML),n.insert.call(a)}),!t&&o.$activateValidator()},teardownFragment:function(){n.unbind.call(this)}})}function g(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 m(t){var i=t.util,e=g(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 y(i){arguments.length<=1||void 0===arguments[1]?{}:arguments[1];return y.installed?void t("already installed."):(b.Vue=i,f(i),m(i),p(i),_(i),void v(i))}var V={};V["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},V.classCallCheck=function(t,i){if(!(t instanceof i))throw new TypeError("Cannot call a class as a function")},V.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.resolved?a(r.resolved):r.requested?r.pendingCallbacks.push(a):!function(){r.requested=!0;var t=r.pendingCallbacks=[a];r(function(){r.resolved=!0;for(var i=0,e=t.length;e>i;i++)t[i](!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=b.Vue.util.resolveAsset;return i(this._vm.$options,"validators",t)},V.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}(),E=function(t){function i(e,n,a,o,r,s,l,d,u){V.classCallCheck(this,i);var h=V.possibleConstructorReturn(this,t.call(this,e,n,a,o,r,s,l,d,u));return h._inits=[],h}return V.inherits(i,t),i.prototype.manageElement=function(t){var i=this,e=this._getScope(),n=this._addItem(t),a=n.model=this._model;if(a){var o=this._evalModel(a,this._filters);Array.isArray(o)?(this._setChecked(o,n.el),n.unwatch=e.$watch(a,function(t,e){if(t!==e){if(i.guardValidate(n.el,"change"))return;i.handleValidate(n.el)}})):(t.checked=o||!1,this._init=t.checked,n.init=t.checked,n.value=t.value,n.unwatch=e.$watch(a,function(e,n){if(e!==n){if(i.guardValidate(t,"change"))return;i.handleValidate(t)}}))}else this._validator.validate({field:this.field})},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;e(this._inits,function(i,e){t.willUpdateDirty(i.el),t.willUpdateModified(i.el)})},i.prototype.reset=function(){this.resetFlags(),e(this._inits,function(t,i){t.init=t.el.checked,t.value=t.el.value})},i.prototype._addItem=function(t){var i={el:t,init:t.checked,value:t.value};return this._inits.push(i),i},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":V["typeof"](n))?n.v:void 0},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":V["typeof"](n))?n.v:void 0},i}(k),C=function(t){function i(e,n,a,o,r,s,l,d,u){V.classCallCheck(this,i);var h=V.possibleConstructorReturn(this,t.call(this,e,n,a,o,r,s,l,d,u));return h._inits=[],h}return V.inherits(i,t),i.prototype.manageElement=function(t){var i=this,e=this._getScope(),n=this._addItem(t),a=n.model=this._model;if(a){var o=this._evalModel(a,this._filters);this._setChecked(o,t,n),n.unwatch=e.$watch(a,function(e,a){if(e!==a){if(i.guardValidate(n.el,"change"))return;i.handleValidate(t)}})}else this._validator.validate({field:this.field})},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;e(this._inits,function(i,e){t.willUpdateDirty(i.el),t.willUpdateModified(i.el)})},i.prototype.reset=function(){this.resetFlags(),e(this._inits,function(t,i){t.init=t.el.checked,t.value=t.el.value})},i.prototype._addItem=function(t){var i={el:t,init:t.checked,value:t.value};return this._inits.push(i),i},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":V["typeof"](n))?n.v:void 0},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":V["typeof"](n))?n.v:void 0},i}(k),N=function(t){function i(e,n,a,o,r,s,l,d,u){V.classCallCheck(this,i);var h=V.possibleConstructorReturn(this,t.call(this,e,n,a,o,r,s,l,d,u));return h._multiple=h._el.hasAttribute("multiple"),h}return V.inherits(i,t),i.prototype.manageElement=function(t){var i=this,e=this._getScope(),n=this._model;if(n){var a=this._evalModel(n,this._filters),o=Array.isArray(a)?a:[a];this._setOption(o,t),this._unwatch=e.$watch(n,function(e,n){var a=Array.isArray(e)?e:[e],o=Array.isArray(n)?n:[n];if(a.slice().sort().toString()!==o.slice().sort().toString()){if(i.guardValidate(t,"change"))return;i.handleValidate(t)}})}},i.prototype.unmanageElement=function(t){this._unwatch&&this._unwatch()},i.prototype.reset=function(){this.resetFlags()},i.prototype._getValue=function(t){for(var i=[],e=0,n=t.options.length;n>e;e++){var a=t.options[e];!a.disabled&&a.selected&&i.push(a.value)}return i},i.prototype._setOption=function(t,i){for(var e=0,n=t.length;n>e;e++)for(var a=t[e],o=0,r=i.options.length;r>o;o++){var s=i.options[o];s.disabled||s.value!==a||s.hasAttribute("selected")&&s.selected||(s.selected=!0)}},i.prototype._checkModified=function(t){var i=this._getValue(t).slice().sort();if(this._init.length!==i.length)return!0;var e=this._init.slice().sort();return e.toString()!==i.toString()},i}(k),S=/^v-on:|^@/,x=function(){function t(i,n,a){var o=this;V.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,e(a,function(t){o._groupValidations[t]=[]})}return t.prototype.enableReactive=function(){var t=this._dir.vm;b.Vue.util.defineReactive(t,this.name,this._scope),t._validatorMaps[this.name]=this,this._defineResetValidation(),this._defineValidate(),this._defineSetValidationErrors()},t.prototype.disableReactive=function(){var t=this._dir.vm;t.$setValidationErrors=void 0,t.$validate=void 0,t.$validatorReset=void 0,t._validatorMaps[this.name]=null,t[this.name]=null},t.prototype.registerEvents=function(){for(var t=this._dir.el.attributes,i=0,e=t.length;e>i;i++){var n=t[i].name;S.test(n)&&(n=n.replace(S,""),this._events[this._getEventName(n)]=this._dir.vm.$eval(t[i].value,!0))}},t.prototype.unregisterEvents=function(){var t=this;e(this._events,function(i,e){t._events[e]=null,delete t._events[e]})},t.prototype.manageValidation=function(t,i,e,n,a,o,r,s){var l=null;return l="SELECT"===n.tagName?this._manageSelectValidation(t,i,e,n,a,o,r,s):"checkbox"===n.type?this._manageCheckboxValidation(t,i,e,n,a,o,r,s):"radio"===n.type?this._manageRadioValidation(t,i,e,n,a,o,r,s):this._manageBaseValidation(t,i,e,n,a,o,r,s)},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=b.Vue.util.indexOf,n=this._validations[i]||this._checkboxValidations[i].validation||this._radioValidations[i].validation,a=this._groupValidations[t];a&&!~e(a,n)&&a.push(n)},t.prototype.removeGroupValidation=function(t,i){var e=this._validations[i]||this._checkboxValidations[i].validation||this._radioValidations[i].validation,a=this._groupValidations[t];a&&n(a,e)},t.prototype.validate=function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],i=t.field,n=void 0===i?null:i,a=t.touched,o=void 0===a?!1:a,r=t.noopable,s=void 0===r?!1:r,l=t.cb,d=void 0===l?null:l;n?this._validate(n,o,s,d):(e(this.validations,function(t,i){t.willUpdateFlags(o)}),this._validates(d))},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={};b.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=this,n=arguments.length<=2||void 0===arguments[2]?!1:arguments[2],a=arguments.length<=3||void 0===arguments[3]?null:arguments[3],o=this._scope,r=this._getValidationFrom(t);r&&(r.willUpdateFlags(i),r.validate(function(i){b.Vue.set(o,t,i),e._fireEvents(),a&&a()},n))},t.prototype._validates=function(t){var i=this,e=this._scope;this._runValidates(function(t,i,n){t.validate(function(t){b.Vue.set(e,i,t),n()})},function(){i._fireEvents(),t&&t()})},t.prototype._getValidationFrom=function(t){var i=this._validations[t];return!i&&this._checkboxValidations[t]?i=this._checkboxValidations[t].validation:!i&&this._radioValidations[t]&&(i=this._radioValidations[t].validation),i},t.prototype._resetValidation=function(t){e(this.validations,function(t,i){t.reset()}),this._validates(t)},t.prototype._setValidationErrors=function(t){var i=this,n=b.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),b.Vue.set(i._scope,a,r)})},t.prototype._manageBaseValidation=function(t,i,e,n,a,o,r,s){var l=this._validations[t]=new k(t,i,e,n,a,this,o,r,s);return l.manageElement(n),l},t.prototype._unmanageBaseValidation=function(t,i){var e=this._validations[t];e&&(e.unmanageElement(i),b.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){var l=this._checkboxValidations[t];if(!l){var d=new E(t,i,e,n,a,this,o,r,s);l={validation:d,elements:0},this._checkboxValidations[t]=l}return l.elements++,l.validation.manageElement(n),l.validation},t.prototype._unmanageCheckboxValidation=function(t,i){var e=this._checkboxValidations[t];e&&(e.elements--,e.validation.unmanageElement(i),0===e.elements&&(b.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){var l=this._radioValidations[t];if(!l){var d=new C(t,i,e,n,a,this,o,r,s);l={validation:d,elements:0},this._radioValidations[t]=l}return l.elements++,l.validation.manageElement(n),l.validation},t.prototype._unmanageRadioValidation=function(t,i){var e=this._radioValidations[t];e&&(e.elements--,e.validation.unmanageElement(i),0===e.elements&&(b.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){var l=this._validations[t]=new N(t,i,e,n,a,this,o,r,s);return l.manageElement(n),l},t.prototype._unmanageSelectValidation=function(t,i){var e=this._validations[t];e&&(e.unmanageElement(i),b.Vue["delete"](this._scope,t),this._validations[t]=null,delete this._validations[t])},t.prototype._fireEvent=function(t){for(var i=this._events[this._getEventName(t)],e=arguments.length,n=Array(e>1?e-1:0),a=1;e>a;a++)n[a-1]=arguments[a];i&&i.apply(null,n)},t.prototype._fireEvents=function(){var t=this._scope;t.touched&&this._fireEvent("touched"),t.dirty&&this._fireEvent("dirty"),this._modified!==t.modified&&(this._fireEvent("modified",t.modified),this._modified=t.modified);var i=t.valid;this._fireEvent(i?"valid":"invalid")},t.prototype._getEventName=function(t){return this.name+":"+t},t.prototype._defineProperties=function(t,i){var n=this,a=b.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=b.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=b.Vue.util.hasOwn,o=b.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},V.createClass(t,[{key:"validations",get:function(){var t=b.Vue.util.extend,i={};return t(i,this._validations),e(this._checkboxValidations,function(t,e){i[e]=t.validation}),e(this._radioValidations,function(t,e){i[e]=t.validation}),i}}]),t}();return y.version="2.0.2","undefined"!=typeof window&&window.Vue&&window.Vue.use(y),y}); \ No newline at end of file +!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define(i):t.VueValidator=i()}(this,function(){"use strict";function t(t,i){window.console&&(console.warn("[vue-validator] "+t),i&&console.warn(i.stack))}function i(t){if(null===t||void 0===t)return!0;if(Array.isArray(t)){if(t.length>0)return!1;if(0===t.length)return!0}else if(w.Vue.util.isPlainObject(t))for(var i in t)if(w.Vue.util.hasOwn(t,i))return!1;return!0}function e(t,i,e){if(Array.isArray(t))for(var n=0;na;a++)e(t,n[a])}function r(t){if(Array.isArray(t)){if(0!==t.length){for(var i=!0,e=0,n=t.length;n>e&&(i=r(t[e]),i);e++);return i}return!1}return"number"==typeof t||"function"==typeof t?!0:"boolean"==typeof t?t:"string"==typeof t?t.length>0:null!==t&&"object"===("undefined"==typeof t?"undefined":C["typeof"](t))?Object.keys(t).length>0:null===t||void 0===t?!1:void 0}function l(t,i){if("string"!=typeof i)return!1;var e=i.match(new RegExp("^/(.*?)/([gimy]*)$"));return e?new RegExp(e[1],e[2]).test(t):!1}function d(t,i){return"string"==typeof t?f(i,10)&&t.length>=parseInt(i,10):Array.isArray(t)?t.length>=parseInt(i,10):!1}function u(t,i){return"string"==typeof t?f(i,10)&&t.length<=parseInt(i,10):Array.isArray(t)?t.length<=parseInt(i,10):!1}function h(t,i){return!isNaN(+t)&&!isNaN(+i)&&+t>=+i}function c(t,i){return!isNaN(+t)&&!isNaN(+i)&&+i>=+t}function f(t){return/^(-?[1-9]\d*|0)$/.test(t)}function p(t){var i=t.util.extend,e=Object.create(null);i(e,k),t.options.validators=e;var n=t.config.optionMergeStrategies;n&&(n.validators=function(t,e){if(!e)return t;if(!t)return e;var n=Object.create(null);i(n,t);for(var a in e)n[a]=e[a];return n}),t.validator=function(i,e){return e?void(t.options.validators[i]=e):t.options.validators[i]}}function v(t){var i=t.prototype._init;t.prototype._init=function(t){this._validatorMaps||(this._validatorMaps=Object.create(null)),i.call(this,t)};var e=t.prototype._destroy;t.prototype._destroy=function(){e.apply(this,arguments),this._validatorMaps=null}}function _(t){var i=t.directive("if"),e=t.FragmentFactory,n=t.util,a=n.toArray,o=n.replace,s=n.createAnchor;t.directive("validate-class",{terminal:!0,priority:i.priority+N,bind:function(){var t=this,i=String(I++);this.setClassIds(this.el,i),this.vm.$on(E,this.cb=function(e,n,a){e.indexOf(i)>-1&&n.updateClasses(a,t.frag.node)}),this.setupFragment()},unbind:function(){this.vm.$off(E,this.cb),this.teardownFragment()},setClassIds:function(t,i){for(var e=a(t.childNodes),n=0,o=e.length;o>n;n++){var s=e[n];if(1===s.nodeType)for(var r=s.hasAttributes(),l=r&&a(s.attributes),d=0,u=l.length;u>d;d++){var h=l[d];if(h.name.match(x)){var c=s.getAttribute(E),f=c?c+","+i:i;s.setAttribute(E,f)}}s.hasChildNodes()&&this.setClassIds(s,i)}},setupFragment:function(){this.anchor=s("v-validate-class"),o(this.el,this.anchor),this.factory=new e(this.vm,this.el),this.frag=this.factory.create(this._host,this._scope,this._frag),this.frag.before(this.anchor)},teardownFragment:function(){this.frag&&(this.frag.remove(),this.frag=null,this.factory=null),o(this.anchor,this.el),this.anchor=null}})}function g(t){function i(){if(r){var t=document.createElement("textarea");return t.placeholder="t","t"===t.cloneNode(!0).value}return!1}var n=t.directive("if"),a=t.FragmentFactory,o=t.parsers.directive.parseDirective,s=t.util,r=s.inBrowser,l=s.bind,d=s.on,u=s.off,h=s.createAnchor,c=s.replace,f=s.camelize,p=s.isPlainObject,v=i();t.directive("validate",{terminal:!0,priority:n.priority+A,params:["group","field","detect-blur","detect-change","initial","classes"],paramWatchers:{detectBlur:function(t,i){this._invalid||(this.validation.detectBlur=this.isDetectBlur(t),this.validator.validate(this.field))},detectChange:function(t,i){this._invalid||(this.validation.detectChange=this.isDetectChange(t),this.validator.validate(this.field))}},bind:function(){var t=this.el,i=this.vm.$options._validator,e=t.getAttribute("v-model"),n=this.parseModelRaw(e),a=n.model,o=n.filters;this.model=a,this.setupFragment(),this.setupValidate(i,a,o),this.listen()},update:function(t,i){if(t&&!this._invalid){p(t)?this.handleObject(t):Array.isArray(t)&&this.handleArray(t);var e={field:this.field,noopable:this._initialNoopValidation};this.frag&&(e.el=this.frag.node),this.validator.validate(e),this._initialNoopValidation&&(this._initialNoopValidation=null)}},unbind:function(){this._invalid||(this.unlisten(),this.teardownValidate(),this.teardownFragment(),this.model=null)},parseModelRaw:function(t){if(S.test(t)){var i=o(t);return{model:i.expression,filters:i.filters}}return{model:t}},setupValidate:function(t,i,e){var n=this.params,a=this.validator=this.vm._validatorMaps[t];this.field=f(this.arg?this.arg:n.field),this.validation=a.manageValidation(this.field,i,this.vm,this.frag.node,this._scope,e,n.initial,this.isDetectBlur(n.detectBlur),this.isDetectChange(n.detectChange)),p(n.classes)&&this.validation.setValidationClasses(n.classes),n.group&&a.addGroupValidation(n.group,this.field),this._initialNoopValidation=this.isInitialNoopValidation(n.initial)},listen:function(){var t=this.model,i=this.validation,e=this.frag.node;this.onBlur=l(i.listener,i),d(e,"blur",this.onBlur),"radio"!==e.type&&"SELECT"!==e.tagName||t?"checkbox"===e.type?t?(this.onClick=l(i.listener,i),d(e,"click",this.onClick)):(this.onChange=l(i.listener,i),d(e,"change",this.onChange)):t||(this.onInput=l(i.listener,i),d(e,"input",this.onInput)):(this.onChange=l(i.listener,i),d(e,"change",this.onChange))},unlisten:function(){var t=this.frag.node;this.onInput&&(u(t,"input",this.onInput),this.onInput=null),this.onClick&&(u(t,"click",this.onClick),this.onClick=null),this.onChange&&(u(t,"change",this.onChange),this.onChange=null),this.onBlur&&(u(t,"blur",this.onBlur),this.onBlur=null)},teardownValidate:function(){if(this.validator&&this.validation){var t=this.frag.node;this.params.group&&this.validator.removeGroupValidation(this.params.group,this.field),this.validator.unmanageValidation(this.field,t),this.validator=null,this.validation=null,this.field=null}},setupFragment:function(){this.anchor=h("v-validate"),c(this.el,this.anchor),this.factory=new a(this.vm,this.shimNode(this.el)),this.frag=this.factory.create(this._host,this._scope,this._frag),this.frag.before(this.anchor)},teardownFragment:function(){this.frag&&(this.frag.remove(),this.frag=null,this.factory=null),c(this.anchor,this.el),this.anchor=null},handleArray:function(t){var i=this;e(t,function(t){i.validation.setValidation(t)})},handleObject:function(t){var i=this;e(t,function(t,e){if(p(t)){if("rule"in t){var n="message"in t?t.message:null,a="initial"in t?t.initial:null;i.validation.setValidation(e,t.rule,n,a)}}else i.validation.setValidation(e,t)})},isDetectBlur:function(t){return void 0===t||"on"===t||t===!0},isDetectChange:function(t){return void 0===t||"on"===t||t===!0},isInitialNoopValidation:function(t){return"off"===t||t===!1},shimNode:function(t){var i=t;if(v&&"TEXTAREA"===t.tagName){i=t.cloneNode(!0),i.value=t.value;for(var e=i.childNodes.length;e--;)i.removeChild(i.childNodes[e])}return i}})}function m(t){var i=t.FragmentFactory,e=t.directive("if"),n=t.util,a=n.isArray,o=n.isPlainObject,s=n.createAnchor,r=n.replace,l=n.extend,d=n.camelize;t.elementDirective("validator",{params:["name","groups","lazy","classes"],bind:function(){var t=this.params;if(this.validatorName="$"+d(t.name),!this.vm._validatorMaps)throw new Error("Invalid validator management error");var i={};o(this.params.classes)&&(i=this.params.classes),this.setupValidator(i),this.setupFragment(t.lazy)},unbind:function(){this.teardownFragment(),this.teardownValidator()},getGroups:function(){var t=this.params,i=[];return t.groups&&(a(t.groups)?i=t.groups:o(t.groups)||"string"!=typeof t.groups||i.push(t.groups)),i},setupValidator:function(t){var i=this.validator=new U(this.validatorName,this,this.getGroups(),t);i.enableReactive(),i.setupScope(),i.registerEvents()},teardownValidator:function(){this.validator.unregisterEvents(),this.validator.disableReactive(),this.validatorName&&(this.validatorName=null,this.validator=null)},setupFragment:function(t){var n=this,a=this.vm;this.validator.waitFor(function(){n.anchor=s("vue-validator"),r(n.el,n.anchor),l(a.$options,{_validator:n.validatorName}),n.factory=new i(a,n.el.innerHTML),e.insert.call(n)}),!t&&a.$activateValidator()},teardownFragment:function(){e.unbind.call(this)}})}function y(t){var i={name:"validator-error",props:{field:{type:String,required:!0},validator:{type:String},message:{type:String,required:!0},partial:{type:String,"default":"validator-error-default"}},template:'
',partials:{}};return i.partials["validator-error-default"]="

{{field}}: {{message}}

",i}function V(t){var i=t.util,e=y(t),n={name:"validator-errors",props:{validation:{type:Object,required:!0},group:{type:String,"default":null},field:{type:String,"default":null},component:{type:String,"default":"validator-error"}},computed:{errors:function(){var t=this;if(null!==this.group)return this.validation[this.group].errors;if(null!==this.field){var e=this.validation[this.field];if(!e.errors)return;return e.errors.map(function(e){var n={field:t.field};return i.isPlainObject(e)?(e.validator&&(n.validator=e.validator),n.message=e.message):"string"==typeof e&&(n.message=e),n})}return this.validation.errors}},template:'',components:{}};return n.props.partial=e.props.partial,n.components[e.name]=e,t.component(n.name,n),n}function b(i){arguments.length<=1||void 0===arguments[1]?{}:arguments[1];return b.installed?void t("already installed."):(w.Vue=i,p(i),V(i),v(i),m(i),_(i),void g(i))}var C={};C["typeof"]="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},C.classCallCheck=function(t,i){if(!(t instanceof i))throw new TypeError("Cannot call a class as a function")},C.createClass=function(){function t(t,i){for(var e=0;eh;h++)if(s=e[h],r=a(this._vm.$options,"filters",s.name),r&&(r=n?r.write:r.read||r,"function"==typeof r)){if(l=n?[t,i]:[t],u=n?2:1,s.args)for(f=0,p=s.args.length;p>f;f++)d=s.args[f],l[f+u]=d.dynamic?o.$get(d.value):d.value;t=r.apply(this._vm,l)}return t},t.prototype._runValidators=function(t,i){var n=this._validators,a=Object.keys(n).length,o=0;e(n,function(e,n){t(e,n,function(){++o,o>=a&&i()})})},t.prototype._invokeValidator=function(t,i,e,n,a){var s=i.call(this,e,n);"function"==typeof s?s.resolved?a(s.resolved):s.requested?s.pendingCallbacks.push(a):!function(){s.requested=!0;var t=s.pendingCallbacks=[a];s(function(){s.resolved=!0;for(var i=0,e=t.length;e>i;i++)t[i](!0)},function(t){a(!1,t)})}():o(s)?s.then(function(){a(!0)},function(t){a(!1,t)})["catch"](function(t){a(!1,t.message)}):a(s)},t.prototype._resolveValidator=function(t){var i=w.Vue.util.resolveAsset;return i(this._vm.$options,"validators",t)},C.createClass(t,[{key:"vm",get:function(){return this._vm}},{key:"el",get:function(){return this._el}},{key:"detectChange",get:function(){return this._detectChange},set:function(t){this._detectChange=t}},{key:"detectBlur",get:function(){return this._detectBlur},set:function(t){this._detectBlur=t}}]),t}(),O=function(t){function i(e,n,a,o,s,r,l,d,u){C.classCallCheck(this,i);var h=C.possibleConstructorReturn(this,t.call(this,e,n,a,o,s,r,l,d,u));return h._inits=[],h}return C.inherits(i,t),i.prototype.manageElement=function(t,i){var e=this,n=this._getScope(),a=this._addItem(t,i),o=a.model=this._model;if(o){var s=this._evalModel(o,this._filters);Array.isArray(s)?(this._setChecked(s,a.el),a.unwatch=n.$watch(o,function(t,i){if(t!==i){if(e.guardValidate(a.el,"change"))return;e.handleValidate(a.el,{noopable:a.initial}),a.initial&&(a.initial=null)}})):(t.checked=s||!1,this._init=t.checked,a.init=t.checked,a.value=t.value,a.unwatch=n.$watch(o,function(i,n){if(i!==n){if(e.guardValidate(t,"change"))return;e.handleValidate(t,{noopable:a.initial}),a.initial&&(a.initial=null)}}))}else{var r={field:this.field,noopable:i};this._checkClassIds(t)&&(r.el=t),this._validator.validate(r)}},i.prototype.unmanageElement=function(t){var i=-1;e(this._inits,function(e,n){e.el===t&&(i=n,e.unwatch&&e.model&&(e.unwatch(),e.unwatch=null,e.model=null))}),-1!==i&&(this._inits.splice(i,1),this._validator.validate({field:this.field}))},i.prototype.willUpdateFlags=function(){var t=this,i=arguments.length<=0||void 0===arguments[0]?!1:arguments[0];e(this._inits,function(e,n){i&&t.willUpdateTouched(e.el,"blur"),t.willUpdateDirty(e.el),t.willUpdateModified(e.el)})},i.prototype.reset=function(){this.resetFlags(),e(this._inits,function(t,i){t.init=t.el.checked,t.value=t.el.value})},i.prototype.updateClasses=function(t){var i=this,n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];n?this._updateClasses(n,t):e(this._inits,function(e,n){i._updateClasses(e.el,t)})},i.prototype._addItem=function(t,i){var e={el:t,init:t.checked,value:t.value,initial:i},n=t.getAttribute(E);return n&&(t.removeAttribute(E),e.classIds=n.split(",")),this._inits.push(e),e},i.prototype._setChecked=function(t,i){for(var e=0,n=t.length;n>e;e++){var a=t[e];i.disabled||i.value!==a||i.checked||(i.checked=!0)}},i.prototype._getValue=function(t){var i=this;if(!this._inits||0===this._inits.length)return t.checked;var n=function(){var t=[];return e(i._inits,function(i,e){i.el.checked&&t.push(i.el.value)}),{v:t}}();return"object"===("undefined"==typeof n?"undefined":C["typeof"](n))?n.v:void 0},i.prototype._getClassIds=function(t){var i=void 0;return e(this._inits,function(e,n){e.el===t&&(i=e.classIds)}),i},i.prototype._checkModified=function(t){var i=this;if(0===this._inits.length)return this._init!==t.checked;var n=function(){var t=!1;return e(i._inits,function(i,e){t||(t=i.init!==i.el.checked)}),{v:t}}();return"object"===("undefined"==typeof n?"undefined":C["typeof"](n))?n.v:void 0},i}(F),M=function(t){function i(e,n,a,o,s,r,l,d,u){C.classCallCheck(this,i);var h=C.possibleConstructorReturn(this,t.call(this,e,n,a,o,s,r,l,d,u));return h._inits=[],h}return C.inherits(i,t),i.prototype.manageElement=function(t,i){var e=this,n=this._getScope(),a=this._addItem(t,i),o=a.model=this._model;if(o){var s=this._evalModel(o,this._filters);this._setChecked(s,t,a),a.unwatch=n.$watch(o,function(i,n){if(i!==n){if(e.guardValidate(a.el,"change"))return;e.handleValidate(t,{noopable:a.initial}),a.initial&&(a.initial=null)}})}else{var r={field:this.field,noopable:i};this._checkClassIds(t)&&(r.el=t),this._validator.validate(r)}},i.prototype.unmanageElement=function(t){var i=-1;e(this._inits,function(e,n){e.el===t&&(i=n)}),-1!==i&&(this._inits.splice(i,1),this._validator.validate({field:this.field}))},i.prototype.willUpdateFlags=function(){var t=this,i=arguments.length<=0||void 0===arguments[0]?!1:arguments[0];e(this._inits,function(e,n){i&&t.willUpdateTouched(e.el,"blur"),t.willUpdateDirty(e.el),t.willUpdateModified(e.el)})},i.prototype.reset=function(){this.resetFlags(),e(this._inits,function(t,i){t.init=t.el.checked,t.value=t.el.value})},i.prototype.updateClasses=function(t){var i=this,n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];n?this._updateClasses(n,t):e(this._inits,function(e,n){i._updateClasses(e.el,t)})},i.prototype._addItem=function(t,i){var e={el:t,init:t.checked,value:t.value,initial:i},n=t.getAttribute(E);return n&&(t.removeAttribute(E),e.classIds=n.split(",")),this._inits.push(e),e},i.prototype._setChecked=function(t,i,e){i.value===t&&(i.checked=!0,this._init=i.checked,e.init=i.checked,e.value=t)},i.prototype._getValue=function(t){var i=this;if(!this._inits||0===this._inits.length)return t.checked;var n=function(){var t=[];return e(i._inits,function(i,e){i.el.checked&&t.push(i.el.value)}),{v:t}}();return"object"===("undefined"==typeof n?"undefined":C["typeof"](n))?n.v:void 0},i.prototype._getClassIds=function(t){var i=void 0;return e(this._inits,function(e,n){e.el===t&&(i=e.classIds)}),i},i.prototype._checkModified=function(t){var i=this;if(0===this._inits.length)return this._init!==t.checked;var n=function(){var t=!1;return e(i._inits,function(i,e){t||(t=i.init!==i.el.checked)}),{v:t}}();return"object"===("undefined"==typeof n?"undefined":C["typeof"](n))?n.v:void 0},i}(F),$=function(t){function i(e,n,a,o,s,r,l,d,u){C.classCallCheck(this,i);var h=C.possibleConstructorReturn(this,t.call(this,e,n,a,o,s,r,l,d,u));return h._multiple=h._el.hasAttribute("multiple"),h}return C.inherits(i,t),i.prototype.manageElement=function(t,i){var e=this,n=this._getScope(),a=this._model;this._initial=i;var o=t.getAttribute(E);if(o&&(t.removeAttribute(E),this._classIds=o.split(",")),a){var s=this._evalModel(a,this._filters),r=Array.isArray(s)?s:[s];this._setOption(r,t),this._unwatch=n.$watch(a,function(i,n){var a=Array.isArray(i)?i:[i],o=Array.isArray(n)?n:[n];if(a.slice().sort().toString()!==o.slice().sort().toString()){if(e.guardValidate(t,"change"))return;e.handleValidate(t,e._initial),e._initial&&(e._initial=null)}})}},i.prototype.unmanageElement=function(t){this._unwatch&&this._unwatch()},i.prototype.reset=function(){this.resetFlags()},i.prototype._getValue=function(t){for(var i=[],e=0,n=t.options.length;n>e;e++){var a=t.options[e];!a.disabled&&a.selected&&i.push(a.value)}return i},i.prototype._setOption=function(t,i){for(var e=0,n=t.length;n>e;e++)for(var a=t[e],o=0,s=i.options.length;s>o;o++){var r=i.options[o];r.disabled||r.value!==a||r.hasAttribute("selected")&&r.selected||(r.selected=!0)}},i.prototype._checkModified=function(t){var i=this._getValue(t).slice().sort();if(this._init.length!==i.length)return!0;var e=this._init.slice().sort();return e.toString()!==i.toString()},i}(F),j=/^v-on:|^@/,U=function(){function t(i,n,a,o){var s=this;C.classCallCheck(this,t),this.name=i,this._scope={},this._dir=n,this._validations={},this._checkboxValidations={},this._radioValidations={},this._groups=a,this._groupValidations={},this._events={},this._modified=!1,this._classes=o,e(a,function(t){s._groupValidations[t]=[]})}return t.prototype.enableReactive=function(){var t=this._dir.vm;w.Vue.util.defineReactive(t,this.name,this._scope),t._validatorMaps[this.name]=this,this._defineResetValidation(),this._defineValidate(),this._defineSetValidationErrors()},t.prototype.disableReactive=function(){var t=this._dir.vm;t.$setValidationErrors=void 0,t.$validate=void 0,t.$validatorReset=void 0,t._validatorMaps[this.name]=null,t[this.name]=null},t.prototype.registerEvents=function(){for(var t=this._dir.el.attributes,i=0,e=t.length;e>i;i++){var n=t[i].name;j.test(n)&&(n=n.replace(j,""),this._events[this._getEventName(n)]=this._dir.vm.$eval(t[i].value,!0))}},t.prototype.unregisterEvents=function(){var t=this;e(this._events,function(i,e){t._events[e]=null,delete t._events[e]})},t.prototype.manageValidation=function(t,i,e,n,a,o,s,r,l){var d=null;return d="SELECT"===n.tagName?this._manageSelectValidation(t,i,e,n,a,o,s,r,l):"checkbox"===n.type?this._manageCheckboxValidation(t,i,e,n,a,o,s,r,l):"radio"===n.type?this._manageRadioValidation(t,i,e,n,a,o,s,r,l):this._manageBaseValidation(t,i,e,n,a,o,s,r,l),d.setValidationClasses(this._classes),d},t.prototype.unmanageValidation=function(t,i){"checkbox"===i.type?this._unmanageCheckboxValidation(t,i):"radio"===i.type?this._unmanageRadioValidation(t,i):"SELECT"===i.tagName?this._unmanageSelectValidation(t,i):this._unmanageBaseValidation(t,i)},t.prototype.addGroupValidation=function(t,i){var e=w.Vue.util.indexOf,n=this._validations[i]||this._checkboxValidations[i].validation||this._radioValidations[i].validation,a=this._groupValidations[t];a&&!~e(a,n)&&a.push(n)},t.prototype.removeGroupValidation=function(t,i){var e=this._validations[i]||this._checkboxValidations[i].validation||this._radioValidations[i].validation,a=this._groupValidations[t];a&&n(a,e)},t.prototype.validate=function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],i=t.el,n=void 0===i?null:i,a=t.field,o=void 0===a?null:a,s=t.touched,r=void 0===s?!1:s,l=t.noopable,d=void 0===l?!1:l,u=t.cb,h=void 0===u?null:u;o?this._validate(o,r,d,n,h):(e(this.validations,function(t,i){t.willUpdateFlags(r)}),this._validates(h))},t.prototype.setupScope=function(){var t=this;this._defineProperties(function(){return t.validations},function(){return t._scope}),e(this._groups,function(i){var e=t._groupValidations[i],n={};w.Vue.set(t._scope,i,n),t._defineProperties(function(){return e},function(){return n})})},t.prototype.waitFor=function(t){var i="$activateValidator",e=this._dir.vm;e[i]=function(){t(),e[i]=null}},t.prototype._defineResetValidation=function(){var t=this;this._dir.vm.$resetValidation=function(i){t._resetValidation(i)}},t.prototype._defineValidate=function(){var t=this;this._dir.vm.$validate=function(){for(var i=arguments.length,n=Array(i),a=0;i>a;a++)n[a]=arguments[a];var o=null,s=!1,r=null;e(n,function(t,i){"string"==typeof t?o=t:"boolean"==typeof t?s=t:"function"==typeof t&&(r=t)}),t.validate({field:o,touched:s,cb:r})}},t.prototype._defineSetValidationErrors=function(){var t=this;this._dir.vm.$setValidationErrors=function(i){t._setValidationErrors(i)}},t.prototype._validate=function(t){var i=arguments.length<=1||void 0===arguments[1]?!1:arguments[1],e=arguments.length<=2||void 0===arguments[2]?!1:arguments[2],n=this,a=arguments.length<=3||void 0===arguments[3]?null:arguments[3],o=arguments.length<=4||void 0===arguments[4]?null:arguments[4],s=this._scope,r=this._getValidationFrom(t);r&&(r.willUpdateFlags(i),r.validate(function(i){w.Vue.set(s,t,i),n._fireEvents(),o&&o()},e,a))},t.prototype._validates=function(t){var i=this,e=this._scope;this._runValidates(function(t,i,n){t.validate(function(t){w.Vue.set(e,i,t),n()})},function(){i._fireEvents(),t&&t()})},t.prototype._getValidationFrom=function(t){var i=this._validations[t];return!i&&this._checkboxValidations[t]?i=this._checkboxValidations[t].validation:!i&&this._radioValidations[t]&&(i=this._radioValidations[t].validation),i},t.prototype._resetValidation=function(t){e(this.validations,function(t,i){t.reset()}),this._validates(t)},t.prototype._setValidationErrors=function(t){var i=this,n=w.Vue.util.extend,a={};e(t,function(t,i){a[t.field]||(a[t.field]=[]),a[t.field].push(t)}),e(a,function(t,a){var o=i._scope[a],s={};e(t,function(t){t.validator&&(o[t.validator]=t.message)}),o.valid=!1,o.invalid=!0,o.errors=t,n(s,o),w.Vue.set(i._scope,a,s)})},t.prototype._manageBaseValidation=function(t,i,e,n,a,o,s,r,l){var d=this._validations[t]=new F(t,i,e,n,a,this,o,r,l);return d.manageElement(n,s),d},t.prototype._unmanageBaseValidation=function(t,i){var e=this._validations[t];e&&(e.unmanageElement(i),w.Vue["delete"](this._scope,t),this._validations[t]=null,delete this._validations[t])},t.prototype._manageCheckboxValidation=function(t,i,e,n,a,o,s,r,l){var d=this._checkboxValidations[t];if(!d){var u=new O(t,i,e,n,a,this,o,r,l);d={validation:u,elements:0},this._checkboxValidations[t]=d}return d.elements++,d.validation.manageElement(n,s),d.validation},t.prototype._unmanageCheckboxValidation=function(t,i){var e=this._checkboxValidations[t];e&&(e.elements--,e.validation.unmanageElement(i),0===e.elements&&(w.Vue["delete"](this._scope,t),this._checkboxValidations[t]=null,delete this._checkboxValidations[t]))},t.prototype._manageRadioValidation=function(t,i,e,n,a,o,s,r,l){var d=this._radioValidations[t];if(!d){var u=new M(t,i,e,n,a,this,o,r,l);d={validation:u,elements:0},this._radioValidations[t]=d}return d.elements++,d.validation.manageElement(n,s),d.validation},t.prototype._unmanageRadioValidation=function(t,i){var e=this._radioValidations[t];e&&(e.elements--,e.validation.unmanageElement(i),0===e.elements&&(w.Vue["delete"](this._scope,t),this._radioValidations[t]=null,delete this._radioValidations[t]))},t.prototype._manageSelectValidation=function(t,i,e,n,a,o,s,r,l){var d=this._validations[t]=new $(t,i,e,n,a,this,o,r,l);return d.manageElement(n,s),d},t.prototype._unmanageSelectValidation=function(t,i){var e=this._validations[t];e&&(e.unmanageElement(i),w.Vue["delete"](this._scope,t),this._validations[t]=null,delete this._validations[t])},t.prototype._fireEvent=function(t){for(var i=this._events[this._getEventName(t)],e=arguments.length,n=Array(e>1?e-1:0),a=1;e>a;a++)n[a-1]=arguments[a];i&&i.apply(null,n)},t.prototype._fireEvents=function(){var t=this._scope;t.touched&&this._fireEvent("touched"),t.dirty&&this._fireEvent("dirty"),this._modified!==t.modified&&(this._fireEvent("modified",t.modified),this._modified=t.modified);var i=t.valid;this._fireEvent(i?"valid":"invalid")},t.prototype._getEventName=function(t){return this.name+":"+t},t.prototype._defineProperties=function(t,i){var n=this,a=w.Vue.util.bind;e({valid:{fn:this._defineValid,arg:t},invalid:{fn:this._defineInvalid,arg:i},touched:{fn:this._defineTouched,arg:t},untouched:{fn:this._defineUntouched, +arg:i},modified:{fn:this._defineModified,arg:t},dirty:{fn:this._defineDirty,arg:t},pristine:{fn:this._definePristine,arg:i},errors:{fn:this._defineErrors,arg:t}},function(t,e){Object.defineProperty(i(),e,{enumerable:!0,configurable:!0,get:function(){return a(t.fn,n)(t.arg)}})})},t.prototype._runValidates=function(t,i){var n=Object.keys(this.validations).length,a=0;e(this.validations,function(e,o){t(e,o,function(){++a,a>=n&&i()})})},t.prototype._walkValidations=function(t,i,n){var a=this,o=w.Vue.util.hasOwn,s=n;return e(t,function(t,e){if(s!==!n&&o(a._scope,t.field)){var r=a._scope[t.field];r&&r[i]===!n&&(s=!n)}}),s},t.prototype._defineValid=function(t){return this._walkValidations(t(),"valid",!0)},t.prototype._defineInvalid=function(t){return!t().valid},t.prototype._defineTouched=function(t){return this._walkValidations(t(),"touched",!1)},t.prototype._defineUntouched=function(t){return!t().touched},t.prototype._defineModified=function(t){return this._walkValidations(t(),"modified",!1)},t.prototype._defineDirty=function(t){return this._walkValidations(t(),"dirty",!1)},t.prototype._definePristine=function(t){return!t().dirty},t.prototype._defineErrors=function(t){var n=this,a=w.Vue.util.hasOwn,o=w.Vue.util.isPlainObject,s=[];return e(t(),function(t,r){if(a(n._scope,t.field)){var l=n._scope[t.field];l&&!i(l.errors)&&e(l.errors,function(i,e){var n={field:t.field};o(i)?(i.validator&&(n.validator=i.validator),n.message=i.message):"string"==typeof i&&(n.message=i),s.push(n)})}}),i(s)?void 0:s},C.createClass(t,[{key:"validations",get:function(){var t=w.Vue.util.extend,i={};return t(i,this._validations),e(this._checkboxValidations,function(t,e){i[e]=t.validation}),e(this._radioValidations,function(t,e){i[e]=t.validation}),i}}]),t}();return b.version="2.1.0","undefined"!=typeof window&&window.Vue&&window.Vue.use(b),b}); \ No newline at end of file diff --git a/docs/en/SUMMARY.md b/docs/en/SUMMARY.md index a89e2b1..a186da6 100644 --- a/docs/en/SUMMARY.md +++ b/docs/en/SUMMARY.md @@ -11,6 +11,7 @@ - [v-model integration](model.md) - [Reset validation results](reset.md) - [Form validatable elements](elements.md) +- [Validation classses](classes.md) - [Grouping](grouping.md) - [Error messages](errors.md) - [Events](events.md) diff --git a/docs/en/api.md b/docs/en/api.md index 33879ee..b828210 100644 --- a/docs/en/api.md +++ b/docs/en/api.md @@ -200,7 +200,7 @@ var resource = this.$resource('/user/:id') resource.save({ id: this.id }, { username: this.username, - passowrd: this.new + password: this.password.new }, function (data, stat, req) { // something handle success ... // ... @@ -274,6 +274,7 @@ - `detect-blur` - `detect-change` - `initial` + - `classes` (required with v-bind, object) - **Usage:** @@ -302,6 +303,9 @@ + + + ``` - **See also:** @@ -310,6 +314,28 @@ - [Events](events.html) - [v-model integration](model.html) - [Validation timing customization](timing.html) + - [Validation classes](classes.html) + +### v-validate-class + +> 2.1+ + +- **Does not expect expression** + +- **Limited to:** directive that expect `v-validate` used together + +- **Usage:** + + Indicate automatically validation class insertion. + +- **Example:** + + ```html +
+ + +
+ ``` ## Special Elements @@ -319,6 +345,7 @@ - `name` (required) - `groups` - `lazy` + - `classes` (required with v-bind, object) - **Usage:** @@ -356,6 +383,12 @@ Too long comment !!