Skip to content
This repository has been archived by the owner on Dec 25, 2017. It is now read-only.

Commit

Permalink
Merge branch '2.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon committed Jul 19, 2016
2 parents 4214870 + e59e3d1 commit 43d2069
Show file tree
Hide file tree
Showing 46 changed files with 1,092 additions and 236 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
<a name="2.1.4"></a>
## [2.1.4](https://github.com/vuejs/vue-validator/compare/v2.1.3...v2.1.4) (2016-07-19)


### :bug: Bug Fixes

* **validator:** fix dynamic custom validator error ([b5d5487](https://github.com/vuejs/vue-validator/commit/b5d5487)), closes [#274](https://github.com/vuejs/vue-validator/issues/274)



<a name="2.1.3"></a>
## [2.1.3](https://github.com/vuejs/vue-validator/compare/v2.1.2...v2.1.3) (2016-05-29)

Expand Down
4 changes: 2 additions & 2 deletions config/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ var main = fs
fs.writeFileSync('src/index.js', main)

// update installation.md
var langs = ['en', 'zh-cn']
var langs = ['en', 'ja', 'zh-cn']
langs.forEach(function (lang) {
var installationPath = './docs/' + lang + '/installation.md'
var installation = fs
.readFileSync(installationPath, 'utf-8')
.replace(
/\<script src=\"https\:\/\/cdn\.jsdelivr\.net\/vue\.validator\/[\d\.]+.[\d]+\/vue-validator\.min\.js\"\>\<\/script\>/,
/<script src="https:\/\/cdn\.jsdelivr\.net\/vue\.validator\/[\d\.]+.[\d]+\/vue-validator\.min\.js"><\/script>/,
'<script src="https://cdn.jsdelivr.net/vue.validator/' + pack.version + '/vue-validator.min.js"></script>'
)
fs.writeFileSync(installationPath, installation)
Expand Down
67 changes: 40 additions & 27 deletions dist/vue-validator.common.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* vue-validator v2.1.3
* vue-validator v2.1.4
* (c) 2016 kazuya kawaguchi
* Released under the MIT License.
*/
Expand Down Expand Up @@ -61,7 +61,6 @@ babelHelpers.possibleConstructorReturn = function (self, call) {
};

babelHelpers;

/**
* Utilties
*/
Expand Down Expand Up @@ -609,10 +608,10 @@ function Validate (Vue) {
return;
}

if (isPlainObject(value)) {
this.handleObject(value);
} else if (Array.isArray(value)) {
this.handleArray(value);
if (isPlainObject(value) || old && isPlainObject(old)) {
this.handleObject(value, old);
} else if (Array.isArray(value) || old && Array.isArray(old)) {
this.handleArray(value, old);
}

var options = { field: this.field, noopable: this._initialNoopValidation };
Expand Down Expand Up @@ -737,16 +736,20 @@ function Validate (Vue) {
replace(this.anchor, this.el);
this.anchor = null;
},
handleArray: function handleArray(value) {
handleArray: function handleArray(value, old) {
var _this = this;

old && this.validation.resetValidation();

each(value, function (val) {
_this.validation.setValidation(val);
});
},
handleObject: function handleObject(value) {
handleObject: function handleObject(value, old) {
var _this2 = this;

old && this.validation.resetValidation();

each(value, function (val, key) {
if (isPlainObject(val)) {
if ('rule' in val) {
Expand Down Expand Up @@ -850,6 +853,16 @@ var BaseValidation = function () {
this._unwatch && this._unwatch();
};

BaseValidation.prototype.resetValidation = function resetValidation() {
var _this2 = this;

var keys = Object.keys(this._validators);
each(keys, function (key, index) {
_this2._validators[key] = null;
delete _this2._validators[key];
});
};

BaseValidation.prototype.setValidation = function setValidation(name, arg, msg, initial) {
var validator = this._validators[name];
if (!validator) {
Expand All @@ -869,10 +882,10 @@ var BaseValidation = function () {
};

BaseValidation.prototype.setValidationClasses = function setValidationClasses(classes) {
var _this2 = this;
var _this3 = this;

each(classes, function (value, key) {
_this2._classes[key] = value;
_this3._classes[key] = value;
});
};

Expand Down Expand Up @@ -930,7 +943,7 @@ var BaseValidation = function () {
};

BaseValidation.prototype.validate = function validate(cb) {
var _this3 = this;
var _this4 = this;

var noopable = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1];
var el = arguments.length <= 2 || arguments[2] === undefined ? null : arguments[2];
Expand All @@ -942,7 +955,7 @@ var BaseValidation = function () {
var valid = true;

this._runValidators(function (descriptor, name, done) {
var asset = _this3._resolveValidator(name);
var asset = _this4._resolveValidator(name);
var validator = null;
var msg = null;

Expand Down Expand Up @@ -973,8 +986,8 @@ var BaseValidation = function () {
}

if (validator) {
var value = _this3._getValue(_this3._el);
_this3._invokeValidator(_this3._vm, validator, value, descriptor.arg, function (ret, err) {
var value = _this4._getValue(_this4._el);
_this4._invokeValidator(_this4._vm, validator, value, descriptor.arg, function (ret, err) {
if (!ret) {
valid = false;
if (err) {
Expand All @@ -983,7 +996,7 @@ var BaseValidation = function () {
results[name] = err;
} else if (msg) {
var error = { validator: name };
error.message = typeof msg === 'function' ? msg.call(_this3._vm, _this3.field, descriptor.arg) : msg;
error.message = typeof msg === 'function' ? msg.call(_this4._vm, _this4.field, descriptor.arg) : msg;
errors.push(error);
results[name] = error.message;
} else {
Expand All @@ -1000,23 +1013,23 @@ var BaseValidation = function () {
}
}, function () {
// finished
_this3._fireEvent(_this3._el, valid ? 'valid' : 'invalid');
_this4._fireEvent(_this4._el, valid ? 'valid' : 'invalid');

var props = {
valid: valid,
invalid: !valid,
touched: _this3.touched,
untouched: !_this3.touched,
dirty: _this3.dirty,
pristine: !_this3.dirty,
modified: _this3.modified
touched: _this4.touched,
untouched: !_this4.touched,
dirty: _this4.dirty,
pristine: !_this4.dirty,
modified: _this4.modified
};
if (!empty(errors)) {
props.errors = errors;
}
_.extend(results, props);

_this3.willUpdateClasses(results, el);
_this4.willUpdateClasses(results, el);

cb(results);
});
Expand All @@ -1040,15 +1053,15 @@ var BaseValidation = function () {
};

BaseValidation.prototype.willUpdateClasses = function willUpdateClasses(results) {
var _this4 = this;
var _this5 = 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);
var classIds = _this5._getClassIds(el);
_this5.vm.$nextTick(function () {
_this5.vm.$emit(VALIDATE_UPDATE, classIds, _this5, results);
});
})();
} else {
Expand Down Expand Up @@ -2590,7 +2603,7 @@ function plugin(Vue) {
Validate(Vue);
}

plugin.version = '2.1.3';
plugin.version = '2.1.4';

if (typeof window !== 'undefined' && window.Vue) {
window.Vue.use(plugin);
Expand Down
67 changes: 40 additions & 27 deletions dist/vue-validator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* vue-validator v2.1.3
* vue-validator v2.1.4
* (c) 2016 kazuya kawaguchi
* Released under the MIT License.
*/
Expand Down Expand Up @@ -65,7 +65,6 @@
};

babelHelpers;

/**
* Utilties
*/
Expand Down Expand Up @@ -613,10 +612,10 @@ var validators = Object.freeze({
return;
}

if (isPlainObject(value)) {
this.handleObject(value);
} else if (Array.isArray(value)) {
this.handleArray(value);
if (isPlainObject(value) || old && isPlainObject(old)) {
this.handleObject(value, old);
} else if (Array.isArray(value) || old && Array.isArray(old)) {
this.handleArray(value, old);
}

var options = { field: this.field, noopable: this._initialNoopValidation };
Expand Down Expand Up @@ -741,16 +740,20 @@ var validators = Object.freeze({
replace(this.anchor, this.el);
this.anchor = null;
},
handleArray: function handleArray(value) {
handleArray: function handleArray(value, old) {
var _this = this;

old && this.validation.resetValidation();

each(value, function (val) {
_this.validation.setValidation(val);
});
},
handleObject: function handleObject(value) {
handleObject: function handleObject(value, old) {
var _this2 = this;

old && this.validation.resetValidation();

each(value, function (val, key) {
if (isPlainObject(val)) {
if ('rule' in val) {
Expand Down Expand Up @@ -854,6 +857,16 @@ var validators = Object.freeze({
this._unwatch && this._unwatch();
};

BaseValidation.prototype.resetValidation = function resetValidation() {
var _this2 = this;

var keys = Object.keys(this._validators);
each(keys, function (key, index) {
_this2._validators[key] = null;
delete _this2._validators[key];
});
};

BaseValidation.prototype.setValidation = function setValidation(name, arg, msg, initial) {
var validator = this._validators[name];
if (!validator) {
Expand All @@ -873,10 +886,10 @@ var validators = Object.freeze({
};

BaseValidation.prototype.setValidationClasses = function setValidationClasses(classes) {
var _this2 = this;
var _this3 = this;

each(classes, function (value, key) {
_this2._classes[key] = value;
_this3._classes[key] = value;
});
};

Expand Down Expand Up @@ -934,7 +947,7 @@ var validators = Object.freeze({
};

BaseValidation.prototype.validate = function validate(cb) {
var _this3 = this;
var _this4 = this;

var noopable = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1];
var el = arguments.length <= 2 || arguments[2] === undefined ? null : arguments[2];
Expand All @@ -946,7 +959,7 @@ var validators = Object.freeze({
var valid = true;

this._runValidators(function (descriptor, name, done) {
var asset = _this3._resolveValidator(name);
var asset = _this4._resolveValidator(name);
var validator = null;
var msg = null;

Expand Down Expand Up @@ -977,8 +990,8 @@ var validators = Object.freeze({
}

if (validator) {
var value = _this3._getValue(_this3._el);
_this3._invokeValidator(_this3._vm, validator, value, descriptor.arg, function (ret, err) {
var value = _this4._getValue(_this4._el);
_this4._invokeValidator(_this4._vm, validator, value, descriptor.arg, function (ret, err) {
if (!ret) {
valid = false;
if (err) {
Expand All @@ -987,7 +1000,7 @@ var validators = Object.freeze({
results[name] = err;
} else if (msg) {
var error = { validator: name };
error.message = typeof msg === 'function' ? msg.call(_this3._vm, _this3.field, descriptor.arg) : msg;
error.message = typeof msg === 'function' ? msg.call(_this4._vm, _this4.field, descriptor.arg) : msg;
errors.push(error);
results[name] = error.message;
} else {
Expand All @@ -1004,23 +1017,23 @@ var validators = Object.freeze({
}
}, function () {
// finished
_this3._fireEvent(_this3._el, valid ? 'valid' : 'invalid');
_this4._fireEvent(_this4._el, valid ? 'valid' : 'invalid');

var props = {
valid: valid,
invalid: !valid,
touched: _this3.touched,
untouched: !_this3.touched,
dirty: _this3.dirty,
pristine: !_this3.dirty,
modified: _this3.modified
touched: _this4.touched,
untouched: !_this4.touched,
dirty: _this4.dirty,
pristine: !_this4.dirty,
modified: _this4.modified
};
if (!empty(errors)) {
props.errors = errors;
}
_.extend(results, props);

_this3.willUpdateClasses(results, el);
_this4.willUpdateClasses(results, el);

cb(results);
});
Expand All @@ -1044,15 +1057,15 @@ var validators = Object.freeze({
};

BaseValidation.prototype.willUpdateClasses = function willUpdateClasses(results) {
var _this4 = this;
var _this5 = 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);
var classIds = _this5._getClassIds(el);
_this5.vm.$nextTick(function () {
_this5.vm.$emit(VALIDATE_UPDATE, classIds, _this5, results);
});
})();
} else {
Expand Down Expand Up @@ -2594,7 +2607,7 @@ var validators = Object.freeze({
Validate(Vue);
}

plugin.version = '2.1.3';
plugin.version = '2.1.4';

if (typeof window !== 'undefined' && window.Vue) {
window.Vue.use(plugin);
Expand Down
6 changes: 3 additions & 3 deletions dist/vue-validator.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/en/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- [Getting started](started.md)
- [Validation result structure](structure.md)
- [Validator syntax](syntax.md)
- [Built-in validators](validators.md)
- [v-model integration](model.md)
- [Reset validation results](reset.md)
- [Form validatable elements](elements.md)
Expand Down
Loading

0 comments on commit 43d2069

Please sign in to comment.