@@ -58,8 +58,8 @@ We can use `validator` element directive and `v-validate` directive. The followi
58
58
<div id =" app" >
59
59
<validator name =" validation1" >
60
60
<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 } " >
63
63
<div >
64
64
<span v-show =" $validation1.username.required" >Required your name.</span >
65
65
<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
139
139
- ` modified ` : if modified field exist even ** one** in validate fields, return ` true ` , else ` false ` .
140
140
- ` dirty ` : if dirty field exist even ** one** in validate fields, return ` true ` , else ` false ` .
141
141
- ` 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 ` .
143
143
144
144
145
145
# Validator syntax
146
146
` v-validate ` directive syntax the below:
147
147
148
148
```
149
- v-validate:field.[validator]+[="primitive literal | object literal | binding"]
149
+ v-validate:field="array literal | object literal | binding"
150
150
```
151
151
152
152
## Literal
153
153
154
- ### Primitive
155
- The below is example that using literal of string value :
154
+ ### Array
155
+ The below is example that using array literal :
156
156
157
157
``` html
158
158
<validator name =" validation" >
159
159
<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 />
161
161
<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 >
163
163
</div >
164
164
</form >
165
165
</validator >
166
166
```
167
167
168
+ Like the ` required ` , if you don't need to specify the rule, you should use it.
169
+
170
+
168
171
### Object
169
172
The below is example that using object literal:
170
173
171
174
``` html
172
175
<validator name =" validation" >
173
176
<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 />
175
178
<div >
179
+ <span v-if =" $validation.id.required" >Required Your ID.</span >
176
180
<span v-if =" $validation.id.minlength" >Your ID is too short.</span >
177
181
<span v-if =" $validation.id.maxlength" >Your ID is too long.</span >
178
182
</div >
179
183
</form >
180
184
</validator >
181
185
```
182
186
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
+
183
202
## Binding
184
203
The below is example that using binding:
185
204
@@ -198,7 +217,7 @@ new Vue({
198
217
<div id =" app" >
199
218
<validator name =" validation" >
200
219
<form novalidate >
201
- ID: <input type =" text" v-validate:id.minlength.maxlength =" rules" ><br />
220
+ ID: <input type =" text" v-validate:id =" rules" ><br />
202
221
<div >
203
222
<span v-if =" $validation.id.minlength" >Your ID is too short.</span >
204
223
<span v-if =" $validation.id.maxlength" >Your ID is too long.</span >
@@ -215,9 +234,9 @@ You can grouping validation results. the below example:
215
234
216
235
``` html
217
236
<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 }" />
221
240
<div class =" user" >
222
241
<span v-if =" $validation1.username.required" >Required your name.</span >
223
242
</div >
@@ -232,10 +251,10 @@ You can specify error message that can get the validation scope.
232
251
233
252
``` html
234
253
<validator name =" validation1" >
235
- username: <input type =" text" v-validate:username.required =" {
254
+ username: <input type =" text" v-validate:username =" {
236
255
required: { rule: true, message: 'required you name !!' }
237
256
}" ><br />
238
- password: <input type =" text" v-validate:password.required.minlength =" {
257
+ password: <input type =" text" v-validate:password =" {
239
258
required: { rule: true, message: 'required you password !!' },
240
259
minlength: { rule: 8, messsage: 'your password short too !!' }
241
260
}" /><br />
@@ -270,7 +289,7 @@ new Vue({
270
289
``` html
271
290
<div id =" app" >
272
291
<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] " />
274
293
</validator >
275
294
</div >
276
295
```
@@ -295,7 +314,7 @@ new Vue({
295
314
``` html
296
315
<div id =" app" >
297
316
<validator name =" validation1" >
298
- address: <input type =" text" v-validate:address. email ><br />
317
+ address: <input type =" text" v-validate:address = [ ' email' ] ><br />
299
318
<div >
300
319
<span v-if =" $validation1.address.email" >invalid your email address format.</span >
301
320
</div >
@@ -308,7 +327,6 @@ new Vue({
308
327
309
328
# TODO
310
329
- async validation
311
- - errors properties
312
330
- validate timing customize with options
313
331
- local asset registration (` compontents ` asset-like)
314
332
- server-side validation error applying
0 commit comments