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

Commit 009b4c7

Browse files
committed
release v2.0.0-alpha.7
2 parents c0eb6f4 + 8037585 commit 009b4c7

33 files changed

+516
-499
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ coverage
33
node_modules
44
.DS_Store
55
*.log
6+
*.gz
67
*.swp
78
*~

CHANGELOG.md

+28
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
1+
<a name="2.0.0-alpha.7"></a>
2+
# [2.0.0-alpha.7](https://github.com/vuejs/vue-validator/compare/v2.0.0-alpha.6...v2.0.0-alpha.7) (2015-12-10)
3+
4+
5+
### Features
6+
7+
* **syntax:** support array syntax on v-validate expression ([bf33bb4](https://github.com/vuejs/vue-validator/commit/bf33bb4))
8+
9+
10+
11+
<a name="2.0.0-alpha.6"></a>
12+
# [2.0.0-alpha.6](https://github.com/vuejs/vue-validator/compare/v2.0.0-alpha.6...v2.0.0-alpha.6) (2015-12-07)
13+
14+
15+
### Performances
16+
17+
* **bundle**: more compact the vue-validator
18+
about 20% smaller build with rollupjs.
19+
20+
- before
21+
- vue-validator.min.js 11701
22+
- vue-validator.js 26180
23+
- after
24+
- vue-validator.min.js 9309
25+
- vue-validator.js 20713
26+
27+
28+
129
<a name="2.0.0-alpha.5"></a>
230
# [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)
331

README.md

+36-18
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ We can use `validator` element directive and `v-validate` directive. The followi
5858
<div id="app">
5959
<validator name="validation1">
6060
<form novalidate>
61-
<input type="text" v-validate:username.required>
62-
<input type="text" v-validate:comment.maxlength="256">
61+
<input type="text" v-validate:username="['required']">
62+
<input type="text" v-validate:comment="{ maxlength: 256 }">
6363
<div>
6464
<span v-show="$validation1.username.required">Required your name.</span>
6565
<span v-show="$validation1.comment.maxlength">Your comment is too long.</span>
@@ -139,47 +139,66 @@ The various top-level properties has been defined in the validation scope, and t
139139
- `modified`: if modified field exist even **one** in validate fields, return `true`, else `false`.
140140
- `dirty`: if dirty field exist even **one** in validate fields, return `true`, else `false`.
141141
- `pristine`: whether **all** fields is pristine, if so, return `true`, else `false`.
142-
- `errors`: if invalid even one exist, return all field error message wrapped with object, else `undefined`.
142+
- `messages`: if invalid even one exist, return all field error message wrapped with object, else `undefined`.
143143

144144

145145
# Validator syntax
146146
`v-validate` directive syntax the below:
147147

148148
```
149-
v-validate:field.[validator]+[="primitive literal | object literal | binding"]
149+
v-validate:field="array literal | object literal | binding"
150150
```
151151

152152
## Literal
153153

154-
### Primitive
155-
The below is example that using literal of string value:
154+
### Array
155+
The below is example that using array literal:
156156

157157
```html
158158
<validator name="validation">
159159
<form novalidate>
160-
Zip: <input type="text" v-validate:zip.pattern="'/^[0-9]{3}-[0-9]{4}$/'"><br />
160+
Zip: <input type="text" v-validate:zip="['required']"><br />
161161
<div>
162-
<span v-if="$validation.zip.pattern">Invalid format of your zip code.</span>
162+
<span v-if="$validation.zip.required">Required zip code.</span>
163163
</div>
164164
</form>
165165
</validator>
166166
```
167167

168+
Like the `required`, if you don't need to specify the rule, you should use it.
169+
170+
168171
### Object
169172
The below is example that using object literal:
170173

171174
```html
172175
<validator name="validation">
173176
<form novalidate>
174-
ID: <input type="text" v-validate:id.minlength.maxlength="{ minlength: 3, maxlength: 16 }"><br />
177+
ID: <input type="text" v-validate:id="{ required: true, minlength: 3, maxlength: 16 }"><br />
175178
<div>
179+
<span v-if="$validation.id.required">Required Your ID.</span>
176180
<span v-if="$validation.id.minlength">Your ID is too short.</span>
177181
<span v-if="$validation.id.maxlength">Your ID is too long.</span>
178182
</div>
179183
</form>
180184
</validator>
181185
```
182186

187+
You can specify the rule value on the object literal. Like the `required`, you can specify the **dummy rule** value on the literal object.
188+
189+
And also, you can specify strict object as the below:
190+
191+
```html
192+
<validator name="validation">
193+
<form novalidate>
194+
ID: <input type="text" v-validate:id="{ minlength: { rule: 3 }, maxlength: { rule: 16 } }"><br />
195+
<div>
196+
<span v-if="$validation.id.minlength">Your ID is too short.</span>
197+
<span v-if="$validation.id.maxlength">Your ID is too long.</span>
198+
</div>
199+
</form>
200+
```
201+
183202
## Binding
184203
The below is example that using binding:
185204

@@ -198,7 +217,7 @@ new Vue({
198217
<div id="app">
199218
<validator name="validation">
200219
<form novalidate>
201-
ID: <input type="text" v-validate:id.minlength.maxlength="rules"><br />
220+
ID: <input type="text" v-validate:id="rules"><br />
202221
<div>
203222
<span v-if="$validation.id.minlength">Your ID is too short.</span>
204223
<span v-if="$validation.id.maxlength">Your ID is too long.</span>
@@ -215,9 +234,9 @@ You can grouping validation results. the below example:
215234

216235
```html
217236
<validator name="validation1" :groups="['user', 'password']">
218-
username: <input type="text" group="user" v-validate:username.required><br />
219-
password: <input type="text" group="password" v-validate:password1.required.minlength="{ minlength: 8 }"/><br />
220-
password (confirm): <input type="text" group="password" v-validate:password2.required.minlength="{ minlength: 8 }"/>
237+
username: <input type="text" group="user" v-validate:username="['required']"><br />
238+
password: <input type="text" group="password" v-validate:password1="{ minlength: 8, required: true }"/><br />
239+
password (confirm): <input type="text" group="password" v-validate:password2="{ minlength: 8, required: true }"/>
221240
<div class="user">
222241
<span v-if="$validation1.username.required">Required your name.</span>
223242
</div>
@@ -232,10 +251,10 @@ You can specify error message that can get the validation scope.
232251

233252
```html
234253
<validator name="validation1">
235-
username: <input type="text" v-validate:username.required="{
254+
username: <input type="text" v-validate:username="{
236255
required: { rule: true, message: 'required you name !!' }
237256
}"><br />
238-
password: <input type="text" v-validate:password.required.minlength="{
257+
password: <input type="text" v-validate:password="{
239258
required: { rule: true, message: 'required you password !!' },
240259
minlength: { rule: 8, messsage: 'your password short too !!' }
241260
}"/><br />
@@ -270,7 +289,7 @@ new Vue({
270289
```html
271290
<div id="app">
272291
<validator name="validation1">
273-
comment: <input type="text" @valid="onValid" @invalid="onInvalid" v-validate:comment.required/>
292+
comment: <input type="text" @valid="onValid" @invalid="onInvalid" v-validate:comment="[required]"/>
274293
</validator>
275294
</div>
276295
```
@@ -295,7 +314,7 @@ new Vue({
295314
```html
296315
<div id="app">
297316
<validator name="validation1">
298-
address: <input type="text" v-validate:address.email><br />
317+
address: <input type="text" v-validate:address=['email']><br />
299318
<div>
300319
<span v-if="$validation1.address.email">invalid your email address format.</span>
301320
</div>
@@ -308,7 +327,6 @@ new Vue({
308327

309328
# TODO
310329
- async validation
311-
- errors properties
312330
- validate timing customize with options
313331
- local asset registration (`compontents` asset-like)
314332
- server-side validation error applying

config/karma.conf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module.exports = function (config) {
2929
devtool: 'source-map',
3030
module: {
3131
noParse: [
32-
/node_modules\/sinon\//,
32+
/node_modules\/sinon\//
3333
],
3434
loaders: [{
3535
test: /\.js$/,

config/webpack.e2e.conf.js

+19-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
1+
var webpack = require('webpack')
2+
13
module.exports = {
2-
entry: {
3-
app: ['webpack/hot/dev-server', './test/e2e/index.js']
4-
},
4+
entry: './test/e2e/index.js',
55
output: {
66
path: './test/e2e',
7-
filename: 'index.build.js'
7+
filename: 'e2e.js'
88
},
99
module: {
1010
loaders: [{
1111
test: /\.js$/,
12-
exclude: /node_modules/,
13-
loader: 'babel'
12+
exclude: /node_modules|vue\/dist/,
13+
loader: 'babel',
14+
query: {
15+
presets: ['es2015']
16+
}
1417
}]
1518
},
16-
devtool: 'inline-source-map'
19+
devtool: 'source-map',
20+
devServer: {
21+
contentBase: './test/e2e',
22+
port: 8080,
23+
hot: true,
24+
inline: true
25+
},
26+
plugins: [
27+
new webpack.HotModuleReplacementPlugin()
28+
]
1729
}

config/webpack.test.conf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = {
1010
devtool: 'source-map',
1111
module: {
1212
noParse: [
13-
/node_modules\/sinon\//,
13+
/node_modules\/sinon\//
1414
],
1515
preLoaders: [{
1616
test: /\.js$/,

dist/vue-validator.common.js

+29-38
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* vue-validator v2.0.0-alpha.6
2+
* vue-validator v2.0.0-alpha.7
33
* (c) 2015 kazuya kawaguchi
44
* Released under the MIT License.
55
*/
@@ -334,40 +334,27 @@ var Validation = (function () {
334334
this.touched = false;
335335
this.dirty = false;
336336
this.modified = false;
337-
this.validates = this._buildValidates(dir);
337+
this.validators = Object.create(null);
338338
}
339339

340340
babelHelpers.createClass(Validation, [{
341-
key: '_buildValidates',
342-
value: function _buildValidates(dir) {
343-
var arg = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1];
344-
341+
key: 'setValidation',
342+
value: function setValidation(name, arg, msg, fn) {
345343
var resolveAsset = exports$1.Vue.util.resolveAsset;
346-
var camelize = exports$1.Vue.util.camelize;
347344

348-
var ret = Object.create(null);
349-
var validates = dir.modifiers;
345+
var validator = this.validators[name];
346+
if (!validator) {
347+
validator = this.validators[name] = {};
348+
validator.fn = resolveAsset(this.dir.vm.$options, 'validators', name);
349+
}
350350

351-
for (var validate in validates) {
352-
var fn = resolveAsset(dir.vm.$options, 'validators', camelize(validate));
353-
if (fn) {
354-
ret[validate] = { arg: arg, fn: fn };
355-
}
351+
validator.arg = arg;
352+
if (msg) {
353+
validator.msg = msg;
356354
}
357355

358-
return ret;
359-
}
360-
}, {
361-
key: 'updateValidate',
362-
value: function updateValidate(name, arg, msg, fn) {
363-
if (this.validates[name]) {
364-
this.validates[name].arg = arg;
365-
if (msg) {
366-
this.validates[name].msg = msg;
367-
}
368-
if (fn) {
369-
this.validates[name].fn = fn;
370-
}
356+
if (fn) {
357+
validator.fn = fn;
371358
}
372359
}
373360
}, {
@@ -399,8 +386,8 @@ var Validation = (function () {
399386
var messages = Object.create(null);
400387
var valid = true;
401388

402-
each(this.validates, function (descriptor, name) {
403-
var res = descriptor.fn(_this.el.value, descriptor.arg);
389+
each(this.validators, function (descriptor, name) {
390+
var res = descriptor.fn.call(_this.dir.vm, _this.el.value, descriptor.arg);
404391
if (!res) {
405392
valid = false;
406393
var msg = descriptor.msg;
@@ -467,26 +454,30 @@ function Validate (Vue) {
467454

468455
if (_.isPlainObject(value)) {
469456
this.handleObject(value);
470-
} else {
471-
this.handleSingle(value);
457+
} else if (Array.isArray(value)) {
458+
this.handleArray(value);
472459
}
473460

474461
this.validator.validate(this.validation);
475462
},
476-
handleSingle: function handleSingle(value) {
477-
var validateKey = Object.keys(this.validation.validates)[0];
478-
this.validation.updateValidate(validateKey, value);
463+
handleArray: function handleArray(value) {
464+
var _this = this;
465+
466+
each(value, function (val) {
467+
_this.validation.setValidation(val);
468+
}, this);
479469
},
480470
handleObject: function handleObject(value) {
481-
var _this = this;
471+
var _this2 = this;
482472

483473
each(value, function (val, key) {
484474
if (_.isPlainObject(val)) {
485475
if ('rule' in val) {
486-
_this.validation.updateValidate(key, val.rule, 'message' in val ? val.message : null);
476+
var msg = 'message' in val ? val.message : null;
477+
_this2.validation.setValidation(key, val.rule, msg);
487478
}
488479
} else {
489-
_this.validation.updateValidate(key, val);
480+
_this2.validation.setValidation(key, val);
490481
}
491482
}, this);
492483
},
@@ -779,7 +770,7 @@ function plugin(Vue) {
779770
Validate(Vue);
780771
}
781772

782-
plugin.version = '2.0.0-alpha.5';
773+
plugin.version = '2.0.0-alpha.7';
783774

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

0 commit comments

Comments
 (0)