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

Commit 43d2069

Browse files
committed
Merge branch '2.x'
2 parents 4214870 + e59e3d1 commit 43d2069

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1092
-236
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
<a name="2.1.4"></a>
2+
## [2.1.4](https://github.com/vuejs/vue-validator/compare/v2.1.3...v2.1.4) (2016-07-19)
3+
4+
5+
### :bug: Bug Fixes
6+
7+
* **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)
8+
9+
10+
111
<a name="2.1.3"></a>
212
## [2.1.3](https://github.com/vuejs/vue-validator/compare/v2.1.2...v2.1.3) (2016-05-29)
313

config/build.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ var main = fs
1414
fs.writeFileSync('src/index.js', main)
1515

1616
// update installation.md
17-
var langs = ['en', 'zh-cn']
17+
var langs = ['en', 'ja', 'zh-cn']
1818
langs.forEach(function (lang) {
1919
var installationPath = './docs/' + lang + '/installation.md'
2020
var installation = fs
2121
.readFileSync(installationPath, 'utf-8')
2222
.replace(
23-
/\<script src=\"https\:\/\/cdn\.jsdelivr\.net\/vue\.validator\/[\d\.]+.[\d]+\/vue-validator\.min\.js\"\>\<\/script\>/,
23+
/<script src="https:\/\/cdn\.jsdelivr\.net\/vue\.validator\/[\d\.]+.[\d]+\/vue-validator\.min\.js"><\/script>/,
2424
'<script src="https://cdn.jsdelivr.net/vue.validator/' + pack.version + '/vue-validator.min.js"></script>'
2525
)
2626
fs.writeFileSync(installationPath, installation)

dist/vue-validator.common.js

+40-27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* vue-validator v2.1.3
2+
* vue-validator v2.1.4
33
* (c) 2016 kazuya kawaguchi
44
* Released under the MIT License.
55
*/
@@ -61,7 +61,6 @@ babelHelpers.possibleConstructorReturn = function (self, call) {
6161
};
6262

6363
babelHelpers;
64-
6564
/**
6665
* Utilties
6766
*/
@@ -609,10 +608,10 @@ function Validate (Vue) {
609608
return;
610609
}
611610

612-
if (isPlainObject(value)) {
613-
this.handleObject(value);
614-
} else if (Array.isArray(value)) {
615-
this.handleArray(value);
611+
if (isPlainObject(value) || old && isPlainObject(old)) {
612+
this.handleObject(value, old);
613+
} else if (Array.isArray(value) || old && Array.isArray(old)) {
614+
this.handleArray(value, old);
616615
}
617616

618617
var options = { field: this.field, noopable: this._initialNoopValidation };
@@ -737,16 +736,20 @@ function Validate (Vue) {
737736
replace(this.anchor, this.el);
738737
this.anchor = null;
739738
},
740-
handleArray: function handleArray(value) {
739+
handleArray: function handleArray(value, old) {
741740
var _this = this;
742741

742+
old && this.validation.resetValidation();
743+
743744
each(value, function (val) {
744745
_this.validation.setValidation(val);
745746
});
746747
},
747-
handleObject: function handleObject(value) {
748+
handleObject: function handleObject(value, old) {
748749
var _this2 = this;
749750

751+
old && this.validation.resetValidation();
752+
750753
each(value, function (val, key) {
751754
if (isPlainObject(val)) {
752755
if ('rule' in val) {
@@ -850,6 +853,16 @@ var BaseValidation = function () {
850853
this._unwatch && this._unwatch();
851854
};
852855

856+
BaseValidation.prototype.resetValidation = function resetValidation() {
857+
var _this2 = this;
858+
859+
var keys = Object.keys(this._validators);
860+
each(keys, function (key, index) {
861+
_this2._validators[key] = null;
862+
delete _this2._validators[key];
863+
});
864+
};
865+
853866
BaseValidation.prototype.setValidation = function setValidation(name, arg, msg, initial) {
854867
var validator = this._validators[name];
855868
if (!validator) {
@@ -869,10 +882,10 @@ var BaseValidation = function () {
869882
};
870883

871884
BaseValidation.prototype.setValidationClasses = function setValidationClasses(classes) {
872-
var _this2 = this;
885+
var _this3 = this;
873886

874887
each(classes, function (value, key) {
875-
_this2._classes[key] = value;
888+
_this3._classes[key] = value;
876889
});
877890
};
878891

@@ -930,7 +943,7 @@ var BaseValidation = function () {
930943
};
931944

932945
BaseValidation.prototype.validate = function validate(cb) {
933-
var _this3 = this;
946+
var _this4 = this;
934947

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

944957
this._runValidators(function (descriptor, name, done) {
945-
var asset = _this3._resolveValidator(name);
958+
var asset = _this4._resolveValidator(name);
946959
var validator = null;
947960
var msg = null;
948961

@@ -973,8 +986,8 @@ var BaseValidation = function () {
973986
}
974987

975988
if (validator) {
976-
var value = _this3._getValue(_this3._el);
977-
_this3._invokeValidator(_this3._vm, validator, value, descriptor.arg, function (ret, err) {
989+
var value = _this4._getValue(_this4._el);
990+
_this4._invokeValidator(_this4._vm, validator, value, descriptor.arg, function (ret, err) {
978991
if (!ret) {
979992
valid = false;
980993
if (err) {
@@ -983,7 +996,7 @@ var BaseValidation = function () {
983996
results[name] = err;
984997
} else if (msg) {
985998
var error = { validator: name };
986-
error.message = typeof msg === 'function' ? msg.call(_this3._vm, _this3.field, descriptor.arg) : msg;
999+
error.message = typeof msg === 'function' ? msg.call(_this4._vm, _this4.field, descriptor.arg) : msg;
9871000
errors.push(error);
9881001
results[name] = error.message;
9891002
} else {
@@ -1000,23 +1013,23 @@ var BaseValidation = function () {
10001013
}
10011014
}, function () {
10021015
// finished
1003-
_this3._fireEvent(_this3._el, valid ? 'valid' : 'invalid');
1016+
_this4._fireEvent(_this4._el, valid ? 'valid' : 'invalid');
10041017

10051018
var props = {
10061019
valid: valid,
10071020
invalid: !valid,
1008-
touched: _this3.touched,
1009-
untouched: !_this3.touched,
1010-
dirty: _this3.dirty,
1011-
pristine: !_this3.dirty,
1012-
modified: _this3.modified
1021+
touched: _this4.touched,
1022+
untouched: !_this4.touched,
1023+
dirty: _this4.dirty,
1024+
pristine: !_this4.dirty,
1025+
modified: _this4.modified
10131026
};
10141027
if (!empty(errors)) {
10151028
props.errors = errors;
10161029
}
10171030
_.extend(results, props);
10181031

1019-
_this3.willUpdateClasses(results, el);
1032+
_this4.willUpdateClasses(results, el);
10201033

10211034
cb(results);
10221035
});
@@ -1040,15 +1053,15 @@ var BaseValidation = function () {
10401053
};
10411054

10421055
BaseValidation.prototype.willUpdateClasses = function willUpdateClasses(results) {
1043-
var _this4 = this;
1056+
var _this5 = this;
10441057

10451058
var el = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1];
10461059

10471060
if (this._checkClassIds(el)) {
10481061
(function () {
1049-
var classIds = _this4._getClassIds(el);
1050-
_this4.vm.$nextTick(function () {
1051-
_this4.vm.$emit(VALIDATE_UPDATE, classIds, _this4, results);
1062+
var classIds = _this5._getClassIds(el);
1063+
_this5.vm.$nextTick(function () {
1064+
_this5.vm.$emit(VALIDATE_UPDATE, classIds, _this5, results);
10521065
});
10531066
})();
10541067
} else {
@@ -2590,7 +2603,7 @@ function plugin(Vue) {
25902603
Validate(Vue);
25912604
}
25922605

2593-
plugin.version = '2.1.3';
2606+
plugin.version = '2.1.4';
25942607

25952608
if (typeof window !== 'undefined' && window.Vue) {
25962609
window.Vue.use(plugin);

dist/vue-validator.js

+40-27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* vue-validator v2.1.3
2+
* vue-validator v2.1.4
33
* (c) 2016 kazuya kawaguchi
44
* Released under the MIT License.
55
*/
@@ -65,7 +65,6 @@
6565
};
6666

6767
babelHelpers;
68-
6968
/**
7069
* Utilties
7170
*/
@@ -613,10 +612,10 @@ var validators = Object.freeze({
613612
return;
614613
}
615614

616-
if (isPlainObject(value)) {
617-
this.handleObject(value);
618-
} else if (Array.isArray(value)) {
619-
this.handleArray(value);
615+
if (isPlainObject(value) || old && isPlainObject(old)) {
616+
this.handleObject(value, old);
617+
} else if (Array.isArray(value) || old && Array.isArray(old)) {
618+
this.handleArray(value, old);
620619
}
621620

622621
var options = { field: this.field, noopable: this._initialNoopValidation };
@@ -741,16 +740,20 @@ var validators = Object.freeze({
741740
replace(this.anchor, this.el);
742741
this.anchor = null;
743742
},
744-
handleArray: function handleArray(value) {
743+
handleArray: function handleArray(value, old) {
745744
var _this = this;
746745

746+
old && this.validation.resetValidation();
747+
747748
each(value, function (val) {
748749
_this.validation.setValidation(val);
749750
});
750751
},
751-
handleObject: function handleObject(value) {
752+
handleObject: function handleObject(value, old) {
752753
var _this2 = this;
753754

755+
old && this.validation.resetValidation();
756+
754757
each(value, function (val, key) {
755758
if (isPlainObject(val)) {
756759
if ('rule' in val) {
@@ -854,6 +857,16 @@ var validators = Object.freeze({
854857
this._unwatch && this._unwatch();
855858
};
856859

860+
BaseValidation.prototype.resetValidation = function resetValidation() {
861+
var _this2 = this;
862+
863+
var keys = Object.keys(this._validators);
864+
each(keys, function (key, index) {
865+
_this2._validators[key] = null;
866+
delete _this2._validators[key];
867+
});
868+
};
869+
857870
BaseValidation.prototype.setValidation = function setValidation(name, arg, msg, initial) {
858871
var validator = this._validators[name];
859872
if (!validator) {
@@ -873,10 +886,10 @@ var validators = Object.freeze({
873886
};
874887

875888
BaseValidation.prototype.setValidationClasses = function setValidationClasses(classes) {
876-
var _this2 = this;
889+
var _this3 = this;
877890

878891
each(classes, function (value, key) {
879-
_this2._classes[key] = value;
892+
_this3._classes[key] = value;
880893
});
881894
};
882895

@@ -934,7 +947,7 @@ var validators = Object.freeze({
934947
};
935948

936949
BaseValidation.prototype.validate = function validate(cb) {
937-
var _this3 = this;
950+
var _this4 = this;
938951

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

948961
this._runValidators(function (descriptor, name, done) {
949-
var asset = _this3._resolveValidator(name);
962+
var asset = _this4._resolveValidator(name);
950963
var validator = null;
951964
var msg = null;
952965

@@ -977,8 +990,8 @@ var validators = Object.freeze({
977990
}
978991

979992
if (validator) {
980-
var value = _this3._getValue(_this3._el);
981-
_this3._invokeValidator(_this3._vm, validator, value, descriptor.arg, function (ret, err) {
993+
var value = _this4._getValue(_this4._el);
994+
_this4._invokeValidator(_this4._vm, validator, value, descriptor.arg, function (ret, err) {
982995
if (!ret) {
983996
valid = false;
984997
if (err) {
@@ -987,7 +1000,7 @@ var validators = Object.freeze({
9871000
results[name] = err;
9881001
} else if (msg) {
9891002
var error = { validator: name };
990-
error.message = typeof msg === 'function' ? msg.call(_this3._vm, _this3.field, descriptor.arg) : msg;
1003+
error.message = typeof msg === 'function' ? msg.call(_this4._vm, _this4.field, descriptor.arg) : msg;
9911004
errors.push(error);
9921005
results[name] = error.message;
9931006
} else {
@@ -1004,23 +1017,23 @@ var validators = Object.freeze({
10041017
}
10051018
}, function () {
10061019
// finished
1007-
_this3._fireEvent(_this3._el, valid ? 'valid' : 'invalid');
1020+
_this4._fireEvent(_this4._el, valid ? 'valid' : 'invalid');
10081021

10091022
var props = {
10101023
valid: valid,
10111024
invalid: !valid,
1012-
touched: _this3.touched,
1013-
untouched: !_this3.touched,
1014-
dirty: _this3.dirty,
1015-
pristine: !_this3.dirty,
1016-
modified: _this3.modified
1025+
touched: _this4.touched,
1026+
untouched: !_this4.touched,
1027+
dirty: _this4.dirty,
1028+
pristine: !_this4.dirty,
1029+
modified: _this4.modified
10171030
};
10181031
if (!empty(errors)) {
10191032
props.errors = errors;
10201033
}
10211034
_.extend(results, props);
10221035

1023-
_this3.willUpdateClasses(results, el);
1036+
_this4.willUpdateClasses(results, el);
10241037

10251038
cb(results);
10261039
});
@@ -1044,15 +1057,15 @@ var validators = Object.freeze({
10441057
};
10451058

10461059
BaseValidation.prototype.willUpdateClasses = function willUpdateClasses(results) {
1047-
var _this4 = this;
1060+
var _this5 = this;
10481061

10491062
var el = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1];
10501063

10511064
if (this._checkClassIds(el)) {
10521065
(function () {
1053-
var classIds = _this4._getClassIds(el);
1054-
_this4.vm.$nextTick(function () {
1055-
_this4.vm.$emit(VALIDATE_UPDATE, classIds, _this4, results);
1066+
var classIds = _this5._getClassIds(el);
1067+
_this5.vm.$nextTick(function () {
1068+
_this5.vm.$emit(VALIDATE_UPDATE, classIds, _this5, results);
10561069
});
10571070
})();
10581071
} else {
@@ -2594,7 +2607,7 @@ var validators = Object.freeze({
25942607
Validate(Vue);
25952608
}
25962609

2597-
plugin.version = '2.1.3';
2610+
plugin.version = '2.1.4';
25982611

25992612
if (typeof window !== 'undefined' && window.Vue) {
26002613
window.Vue.use(plugin);

dist/vue-validator.min.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/en/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- [Getting started](started.md)
99
- [Validation result structure](structure.md)
1010
- [Validator syntax](syntax.md)
11+
- [Built-in validators](validators.md)
1112
- [v-model integration](model.md)
1213
- [Reset validation results](reset.md)
1314
- [Form validatable elements](elements.md)

0 commit comments

Comments
 (0)