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

Commit b355368

Browse files
committed
release 2.0.0-alpha.5
1 parent 3047b68 commit b355368

File tree

5 files changed

+92
-21
lines changed

5 files changed

+92
-21
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
<a name="2.0.0-alpha.5"></a>
2+
# [2.0.0-alpha.5](https://github.com/vuejs/vue-validator/compare/v2.0.0-alpha.4...v2.0.0-alpha.5) (2015-11-24)
3+
4+
5+
### Features
6+
7+
* **messages:** support messages validation property ([34564ec](https://github.com/vuejs/vue-validator/commit/34564ec))
8+
9+
10+
111
<a name="2.0.0-alpha.4"></a>
212
# 2.0.0-alpha.4 (2015-11-23)
313

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ You don't need to do this when using the standalone build because it installs it
4040
## CDN
4141
jsdelivr
4242
```html
43-
<script src="http://cdn.jsdelivr.net/vue.validator/2.0.0-alpha.4/vue-validator.min.js"></script>
43+
<script src="http://cdn.jsdelivr.net/vue.validator/2.0.0-alpha.5/vue-validator.min.js"></script>
4444
```
4545

4646

dist/vue-validator.js

+78-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* vue-validator v2.0.0-alpha.4
2+
* vue-validator v2.0.0-alpha.5
33
* (c) 2015 kazuya kawaguchi
44
* Released under the MIT License.
55
*/
@@ -131,6 +131,7 @@ return /******/ (function(modules) { // webpackBootstrap
131131
value: true
132132
});
133133
exports.warn = warn;
134+
exports.empty = empty;
134135
exports.each = each;
135136
exports.pull = pull;
136137
exports.attr = attr;
@@ -155,6 +156,36 @@ return /******/ (function(modules) { // webpackBootstrap
155156
}
156157
}
157158

159+
/**
160+
* empty
161+
*
162+
* @param {Array|Object} target
163+
* @return {Boolean}
164+
*/
165+
166+
function empty(target) {
167+
if (target === null) {
168+
return true;
169+
}
170+
171+
if (Array.isArray(target)) {
172+
if (target.length > 0) {
173+
return false;
174+
}
175+
if (target.length === 0) {
176+
return true;
177+
}
178+
} else if (_exports.Vue.util.isPlainObject(target)) {
179+
for (var key in target) {
180+
if (_exports.Vue.util.hasOwn(target, key)) {
181+
return false;
182+
}
183+
}
184+
}
185+
186+
return true;
187+
}
188+
158189
/**
159190
* each
160191
*
@@ -169,8 +200,9 @@ return /******/ (function(modules) { // webpackBootstrap
169200
iterator.call(context || target[i], target[i], i);
170201
}
171202
} else if (_exports.Vue.util.isPlainObject(target)) {
203+
var hasOwn = _exports.Vue.util.hasOwn;
172204
for (var key in target) {
173-
if (key in target) {
205+
if (hasOwn(target, key)) {
174206
iterator.call(context || target[key], target[key], key);
175207
}
176208
}
@@ -504,7 +536,7 @@ return /******/ (function(modules) { // webpackBootstrap
504536
(0, _util.each)(value, function (val, key) {
505537
if (_.isPlainObject(val)) {
506538
if ('rule' in val) {
507-
_this.validation.updateValidate(key, val.rule);
539+
_this.validation.updateValidate(key, val.rule, 'message' in val ? val.message : null);
508540
}
509541
} else {
510542
_this.validation.updateValidate(key, val);
@@ -587,9 +619,12 @@ return /******/ (function(modules) { // webpackBootstrap
587619
}
588620
}, {
589621
key: 'updateValidate',
590-
value: function updateValidate(name, arg, fn) {
622+
value: function updateValidate(name, arg, msg, fn) {
591623
if (this.validates[name]) {
592624
this.validates[name].arg = arg;
625+
if (msg) {
626+
this.validates[name].msg = msg;
627+
}
593628
if (fn) {
594629
this.validates[name].fn = fn;
595630
}
@@ -620,28 +655,37 @@ return /******/ (function(modules) { // webpackBootstrap
620655
var _this = this;
621656

622657
var extend = _util2['default'].Vue.util.extend;
623-
var ret = {};
658+
var ret = Object.create(null);
659+
var messages = Object.create(null);
624660
var valid = true;
625661

626662
(0, _util.each)(this.validates, function (descriptor, name) {
627663
var res = descriptor.fn(_this.el.value, descriptor.arg);
628664
if (!res) {
629665
valid = false;
666+
var msg = descriptor.msg;
667+
if (msg) {
668+
messages[name] = typeof msg === 'function' ? msg() : msg;
669+
}
630670
}
631671
ret[name] = !res;
632672
}, this);
633673

634674
(0, _util.trigger)(this.el, valid ? 'valid' : 'invalid');
635675

636-
extend(ret, {
676+
var props = {
637677
valid: valid,
638678
invalid: !valid,
639679
touched: this.touched,
640680
untouched: !this.touched,
641681
dirty: this.dirty,
642682
pristine: !this.dirty,
643683
modified: this.modified
644-
});
684+
};
685+
if (!(0, _util.empty)(messages)) {
686+
props.messages = messages;
687+
}
688+
extend(ret, props);
645689

646690
return ret;
647691
}
@@ -767,17 +811,12 @@ return /******/ (function(modules) { // webpackBootstrap
767811
_classCallCheck(this, Validator);
768812

769813
this.name = name;
770-
this.scope = {}; // TODO: change to Object.create(null)
771-
/*
772-
this.scope = Object.create(null)
773-
this.scope.a = 1
774-
*/
775-
814+
this.scope = Object.create(null);
776815
this._dir = dir;
777816
this._validations = [];
778817
this._groups = groups;
779-
780818
this._groupValidations = Object.create(null);
819+
781820
(0, _util.each)(groups, function (group) {
782821
_this._groupValidations[group] = [];
783822
}, this);
@@ -803,7 +842,7 @@ return /******/ (function(modules) { // webpackBootstrap
803842
}, {
804843
key: 'removeValidation',
805844
value: function removeValidation(validation) {
806-
_util2['default'].Vue.util['delete'](this.scope, validation.model);
845+
_util2['default'].Vue.util.del(this.scope, validation.model);
807846
(0, _util.pull)(this._validations, validation);
808847
}
809848
}, {
@@ -860,7 +899,8 @@ return /******/ (function(modules) { // webpackBootstrap
860899
untouched: { fn: this._defineUntouched, arg: target },
861900
modified: { fn: this._defineModified, arg: validations },
862901
dirty: { fn: this._defineDirty, arg: validations },
863-
pristine: { fn: this._definePristine, arg: target }
902+
pristine: { fn: this._definePristine, arg: target },
903+
messages: { fn: this._defineMessages, arg: validations }
864904
}, function (descriptor, name) {
865905
Object.defineProperty(target, name, {
866906
enumerable: true,
@@ -876,13 +916,14 @@ return /******/ (function(modules) { // webpackBootstrap
876916
value: function _walkValidations(validations, property, condition) {
877917
var _this5 = this;
878918

919+
var hasOwn = _util2['default'].Vue.util.hasOwn;
879920
var ret = condition;
880921

881922
(0, _util.each)(validations, function (validation, index) {
882923
if (ret === !condition) {
883924
return;
884925
}
885-
if (Object.prototype.hasOwnProperty.call(_this5.scope, validation.model)) {
926+
if (hasOwn(_this5.scope, validation.model)) {
886927
var target = _this5.scope[validation.model];
887928
if (target && target[property] === !condition) {
888929
ret = !condition;
@@ -927,6 +968,26 @@ return /******/ (function(modules) { // webpackBootstrap
927968
value: function _definePristine(scope) {
928969
return !scope.dirty;
929970
}
971+
}, {
972+
key: '_defineMessages',
973+
value: function _defineMessages(validations) {
974+
var _this6 = this;
975+
976+
var extend = _util2['default'].Vue.util.extend;
977+
var hasOwn = _util2['default'].Vue.util.hasOwn;
978+
var ret = Object.create(null);
979+
980+
(0, _util.each)(validations, function (validation, index) {
981+
if (hasOwn(_this6.scope, validation.model)) {
982+
var target = _this6.scope[validation.model];
983+
if (target && !(0, _util.empty)(target['messages'])) {
984+
ret[validation.model] = extend(Object.create(null), target['messages']);
985+
}
986+
}
987+
}, this);
988+
989+
return (0, _util.empty)(ret) ? undefined : ret;
990+
}
930991
}]);
931992

932993
return Validator;

0 commit comments

Comments
 (0)