forked from olton/metroui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidator.html
More file actions
562 lines (531 loc) · 27.2 KB
/
validator.html
File metadata and controls
562 lines (531 loc) · 27.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="description" content="Metro, a sleek, intuitive, and powerful framework for faster and easier web development for Windows Metro Style.">
<meta name="keywords" content="HTML, CSS, JS, JavaScript, framework, metro, front-end, frontend, web development">
<meta name="author" content="Sergey Pimenov and Metro UI CSS contributors">
<link rel='shortcut icon' type='image/x-icon' href='favicon.ico' />
<title>Form Validator :: Metro UI CSS - The front-end framework for developing projects on the web in Windows Metro Style</title>
<link href="css/metro.css" rel="stylesheet">
<link href="css/metro-icons.css" rel="stylesheet">
<link href="css/docs.css" rel="stylesheet">
<script src="js/jquery-2.1.3.min.js"></script>
<script src="js/metro.js"></script>
<script src="js/docs.js"></script>
<script src="js/prettify/run_prettify.js"></script>
<script src="js/ga.js"></script>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
function no_submit(){
return false;
}
function notifyOnErrorInput(input){
var message = input.data('validateHint');
$.Notify({
caption: 'Error',
content: message,
type: 'alert'
});
}
</script>
</head>
<body onload="init()">
<div class="container page-content">
<h1><a href="index.html" class="nav-button transform"><span></span></a> Form validator</h1>
@@adsense
<div class="margin20 no-margin-left no-margin-right sub-header text-light">
This widget makes simple clientside form validation easy, whilst still offering plenty of customization options.
The widget comes bundled with a useful set of validation methods, including URL, email, hex color, min and max values, length validation.
</div>
<div class="example" data-text="example">
<div class="grid">
<div class="row cells3">
<div class="cell">
<form data-role="validator" data-on-before-submit="no_submit">
<label class="block">Min length control (state)</label>
<div class="input-control text">
<input type="text" data-validate-func="minlength" data-validate-arg="6" data-show-error-hint="false">
<span class="input-state-error mif-warning"></span>
<span class="input-state-success mif-checkmark"></span>
</div>
<div>
<button class="button success">Send</button>
</div>
</form>
</div>
<div class="cell">
<form data-role="validator" data-on-before-submit="no_submit" data-hint-mode="hint" data-hint-easing="easeOutBounce">
<label class="block">Min length control (hint)</label>
<div class="input-control text">
<input type="text" data-validate-func="minlength" data-validate-arg="6" data-validate-hint="Min length 6 sym !" data-validate-hint-position="top">
<span class="input-state-error mif-warning"></span>
<span class="input-state-success mif-checkmark"></span>
</div>
<div>
<button class="button success">Send</button>
</div>
</form>
</div>
<div class="cell">
<form data-role="validator" data-on-before-submit="no_submit" data-on-error-input="notifyOnErrorInput" data-show-error-hint="false">
<label class="block">Combine with notify system</label>
<div class="input-control text">
<input type="text" data-validate-func="required" data-validate-arg="6" data-validate-hint="This field can not be empty!">
<span class="input-state-error mif-warning"></span>
<span class="input-state-success mif-checkmark"></span>
</div>
<div>
<button class="button success">Send</button>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="example" data-text="code">
<h5>Simple</h5>
<pre class="prettyprint linenums"><code>
<form data-role="validator">
<label class="block">Min length control</label>
<div class="input-control text">
<input
data-validate-func="minlength"
data-validate-arg="6"
data-validate-hint="This field must contains min 6 symbols!"
type="text">
<span class="input-state-error mif-warning"></span>
<span class="input-state-success mif-checkmark"></span>
</div>
<div>
<button class="button success">Send</button>
</div>
</form>
</code></pre>
<h5>Combine with notify system</h5>
<pre class="prettyprint linenums"><code>
<form
data-role="validator"
data-on-error-input="notifyOnErrorInput"
data-show-error-hint="false">
<label class="block">Combine with notify system</label>
<div class="input-control text">
<input type="text"
data-validate-func="required"
data-validate-hine="This field can not be empty!">
<span class="input-state-error mif-warning"></span>
<span class="input-state-success mif-checkmark"></span>
</div>
<div>
<button class="button success">Send</button>
</div>
</form>
<script>
function notifyOnErrorInput(input){
var message = input.data('validateHint');
$.Notify({
caption: 'Error',
content: message,
type: 'alert'
});
}
</script>
</code></pre>
</div>
<h3>Validating functions</h3>
<table class="table border bordered">
<thead>
<tr>
<th>Func name</th>
<th>Description</th>
<th>Params</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>required</strong></td>
<td>Field can not be empty</td>
<td>no</td>
</tr>
<tr>
<td><strong>minlength</strong></td>
<td>Control min length of value</td>
<td>integer</td>
</tr>
<tr>
<td><strong>maxlength</strong></td>
<td>Control max length of value</td>
<td>integer</td>
</tr>
<tr>
<td><strong>min</strong></td>
<td>Control min value for numeric</td>
<td>number</td>
</tr>
<tr>
<td><strong>max</strong></td>
<td>Control max value for numeric</td>
<td>number</td>
</tr>
<tr>
<td><strong>email</strong></td>
<td>Control valid email address</td>
<td>no</td>
</tr>
<tr>
<td><strong>url</strong></td>
<td>Control valid url address</td>
<td>no</td>
</tr>
<tr>
<td><strong>date</strong></td>
<td>Control valid date string</td>
<td>no</td>
</tr>
<tr>
<td><strong>number</strong></td>
<td>Control valid number value</td>
<td>no</td>
</tr>
<tr>
<td><strong>digits</strong></td>
<td>Control only digits in value</td>
<td>no</td>
</tr>
<tr>
<td><strong>hexcolor</strong></td>
<td>Control valid hex color value</td>
<td>no</td>
</tr>
<tr>
<td><strong>pattern</strong></td>
<td>Custom regexp pattern for control value</td>
<td>string pattern</td>
</tr>
</tbody>
</table>
<h3>Validator options</h3>
<table class="table bordered border">
<thead>
<tr>
<td>Parameter</td>
<td>Data-*</td>
<td>Type</td>
<td>Default value</td>
<td>Description</td>
</tr>
</thead>
<tbody>
<tr>
<td>showErrorState</td>
<td style="white-space: nowrap">data-show-error-state</td>
<td>boolean</td>
<td>true</td>
<td>If true input change color state</td>
</tr>
<tr>
<td>showErrorHint</td>
<td style="white-space: nowrap">data-show-error-hint</td>
<td>boolean</td>
<td>true</td>
<td>If true over input showing hint</td>
</tr>
<tr>
<td>showRequiredState</td>
<td style="white-space: nowrap">data-show-required-state</td>
<td>boolean</td>
<td>true</td>
<td>If true input with validate func showing with required color state</td>
</tr>
<tr>
<td>showSuccessState</td>
<td style="white-space: nowrap">data-show-success-state</td>
<td>boolean</td>
<td>true</td>
<td>If true valid input with func showing with success color state</td>
</tr>
<tr>
<td>hintSize</td>
<td style="white-space: nowrap">data-hint-size</td>
<td>int</td>
<td>200</td>
<td>Min width of hint size</td>
</tr>
<tr>
<td>hintBackground</td>
<td style="white-space: nowrap">data-hint-background</td>
<td>string</td>
<td>#FFFCC0</td>
<td>Hint background color, can be hex color or class name</td>
</tr>
<tr>
<td>hintColor</td>
<td style="white-space: nowrap">data-hint-color</td>
<td>string</td>
<td>#000000</td>
<td>Hint text color, can be hex color or class name</td>
</tr>
<tr>
<td>hideError</td>
<td style="white-space: nowrap">data-hide-error</td>
<td>int</td>
<td>2000</td>
<td>Time interval before error state disabled (msec)</td>
</tr>
<tr>
<td>hideHint</td>
<td style="white-space: nowrap">data-hide-hint</td>
<td>int</td>
<td>5000</td>
<td>Time interval before hint hided (msec)</td>
</tr>
<tr>
<td>hintEasing</td>
<td style="white-space: nowrap">data-hint-easing</td>
<td>string</td>
<td>easeInQuad</td>
<td>Easing func for animate showing hint</td>
</tr>
<tr>
<td>hintEasingTime</td>
<td style="white-space: nowrap">data-hint-easing-time</td>
<td>int</td>
<td>400</td>
<td>Easing animate time</td>
</tr>
<tr>
<td>hintMode</td>
<td style="white-space: nowrap">data-hint-mode</td>
<td>string</td>
<td>hint</td>
<td>Hint type, can be: hint or line</td>
</tr>
<tr>
<td>hintPosition</td>
<td style="white-space: nowrap">data-hint-position</td>
<td>string</td>
<td>right</td>
<td>Hint position, can be: right, left, top or bottom</td>
</tr>
</tbody>
</table>
<h3>Hint position <small>hint mode: <span class="tag">hint</span></small> </h3>
<div class="example" data-text="example">
<div class="grid">
<div class="row cells4">
<div class="cell">
<form data-role="validator" data-on-before-submit="no_submit" data-hint-mode="hint" data-hint-easing="easeOutBounce">
<label>Top</label>
<div class="input-control text full-size">
<input type="text"
data-validate-func="required"
data-validate-hint="This field can not be empty!"
data-validate-hint-position="top">
<span class="input-state-error mif-warning"></span>
<span class="input-state-success mif-checkmark"></span>
</div>
<div class="align-center">
<button class="button info">Submit</button>
</div>
</form>
</div>
<div class="cell">
<form data-role="validator" data-on-before-submit="no_submit" data-hint-mode="hint" data-hint-easing="easeOutBounce">
<label>Left</label>
<div class="input-control text full-size">
<input type="text"
data-validate-func="required"
data-validate-hint="This field can not be empty!"
data-validate-hint-position="left">
<span class="input-state-error mif-warning"></span>
<span class="input-state-success mif-checkmark"></span>
</div>
<div class="align-center">
<button class="button info">Submit</button>
</div>
</form>
</div>
<div class="cell">
<form data-role="validator" data-on-before-submit="no_submit" data-hint-mode="hint" data-hint-easing="easeOutBounce">
<label>Right</label>
<div class="input-control text full-size">
<input type="text"
data-validate-func="required"
data-validate-hint="This field can not be empty!"
data-validate-hint-position="right">
<span class="input-state-error mif-warning"></span>
<span class="input-state-success mif-checkmark"></span>
</div>
<div class="align-center">
<button class="button info">Submit</button>
</div>
</form>
</div>
<div class="cell">
<form data-role="validator" data-on-before-submit="no_submit" data-hint-mode="hint" data-hint-easing="easeOutBounce">
<label>Bottom</label>
<div class="input-control text full-size">
<input type="text"
data-validate-func="required"
data-validate-hint="This field can not be empty!"
data-validate-hint-position="bottom">
<span class="input-state-error mif-warning"></span>
<span class="input-state-success mif-checkmark"></span>
</div>
<div class="align-center">
<button class="button info">Submit</button>
</div>
</form>
</div>
</div>
</div>
</div>
<h3>Hint position <small>hint mode: <span class="tag">line</span></small></h3>
<div class="example" data-text="example">
<div class="grid">
<div class="row cells4">
<div class="cell">
<form data-role="validator" data-on-before-submit="no_submit" data-hint-mode="line">
<div class="input-control text full-size">
<input type="text"
data-validate-func="required"
data-validate-hint="This field can not be empty!"
data-validate-hint-position="top">
<span class="input-state-error mif-warning"></span>
<span class="input-state-success mif-checkmark"></span>
</div>
<div class="align-center">
<button class="button info">Submit</button>
</div>
</form>
</div>
<div class="cell colspan3">
<form data-role="validator" data-on-before-submit="no_submit" data-hint-mode="line">
<div class="input-control text full-size">
<input type="text"
data-validate-func="required"
data-validate-hint="This field can not be empty!"
data-validate-hint-position="top">
<span class="input-state-error mif-warning"></span>
<span class="input-state-success mif-checkmark"></span>
</div>
<div class="align-center">
<button class="button info">Submit</button>
</div>
</form>
</div>
</div>
</div>
</div>
<h3>Func examples</h3>
<form data-role="validator" data-show-required-state="false" data-hint-mode="line" data-hint-background="bg-red" data-hint-color="fg-white" data-hide-error="5000">
<div class="grid">
<div class="row">
<div class="cell">
<div class="input-control text full-size">
<input type="text" placeholder="default, no validate">
<button class="button helper-button clear"><span class="mif-cross"></span></button>
</div>
<div class="input-control text" data-role="input">
<input type="text" data-validate-func="required" placeholder="not empty" data-validate-hint="This field can not be empty">
<span class="input-state-error mif-warning"></span>
<span class="input-state-success mif-checkmark"></span>
</div>
<div class="input-control text " data-role="input">
<input type="text" data-validate-func="minlength" placeholder="min length 3" data-validate-arg="3" data-validate-hint="Min length 3 symbols">
<span class="input-state-error mif-warning"></span>
<span class="input-state-success mif-checkmark"></span>
</div>
<div class="input-control text " data-role="input">
<input type="text" data-validate-func="maxlength" placeholder="max length 6" data-validate-arg="6" data-validate-hint="Max length 6 symbols">
<span class="input-state-error mif-warning"></span>
<span class="input-state-success mif-checkmark"></span>
</div>
<div class="input-control text " data-role="input">
<input type="text" data-validate-func="min" placeholder="min value 10" data-validate-arg="10" data-validate-hint="Value >= 10">
<span class="input-state-error mif-warning"></span>
<span class="input-state-success mif-checkmark"></span>
</div>
<div class="input-control text " data-role="input">
<input type="text" data-validate-func="max" placeholder="max value 10" data-validate-arg="10" data-validate-hint="Value <= 10">
<span class="input-state-error mif-warning"></span>
<span class="input-state-success mif-checkmark"></span>
</div>
<div class="input-control text " data-role="input">
<input type="text" data-validate-func="email" placeholder="email" data-validate-hint="Not valid email address">
<span class="input-state-error mif-warning"></span>
<span class="input-state-success mif-checkmark"></span>
</div>
<div class="input-control text " data-role="input">
<input type="text" data-validate-func="url" placeholder="url" data-validate-hint="Value must be valid url">
<span class="input-state-error mif-warning"></span>
<span class="input-state-success mif-checkmark"></span>
</div>
<div class="input-control text " data-role="input">
<input type="text" data-validate-func="date" placeholder="date" data-validate-hint="Value must be valid date string">
<span class="input-state-error mif-warning"></span>
<span class="input-state-success mif-checkmark"></span>
</div>
<div class="input-control text " data-role="input">
<input type="text" data-validate-func="number" placeholder="number" data-validate-hint="Value must be a numeric">
<span class="input-state-error mif-warning"></span>
<span class="input-state-success mif-checkmark"></span>
</div>
<div class="input-control text " data-role="input">
<input type="text" data-validate-func="digits" placeholder="digits" data-validate-hint="Value must contains only digits">
<span class="input-state-error mif-warning"></span>
<span class="input-state-success mif-checkmark"></span>
</div>
<div class="input-control text " data-role="input">
<input type="text" data-validate-func="hexcolor" placeholder="hex color" data-validate-hint="Value must be a valid hex color">
<span class="input-state-error mif-warning"></span>
<span class="input-state-success mif-checkmark"></span>
</div>
<div class="input-control text " data-role="input">
<input type="text" data-validate-func="pattern" placeholder="custom pattern: ^\d+$" data-validate-arg="^\d+$" data-validate-hint="Value must be eq to pattern">
<span class="input-state-error mif-warning"></span>
<span class="input-state-success mif-checkmark"></span>
</div>
</div>
</div>
</div>
<hr class="thin">
<div class="form-actions padding10 no-padding-left">
<button class="button primary" type="submit">Submit</button>
<button class="button link" type="button">Cancel</button>
</div>
</form>
<h3>onSubmit</h3>
<form data-on-submit="submit" data-role="validator" action="javascript:void(0)">
<div class="input-control text" data-role="input">
<input type="text" data-validate-func="required" placeholder="not empty" data-validate-hint="This field can not be empty">
<span class="input-state-error mif-warning"></span>
<span class="input-state-success mif-checkmark"></span>
</div>
<label class="block">Категория</label>
<div class="input-control select full-size" data-role="input">
<select name="employee_category" data-validate-func="required" >
<option value="" selected>Выберите категорию</option>
<option value="1" >категория 1</option>
<option value="2" >категория 2</option>
<option value="3" >категория 3</option>
<option value="4" >категория 4</option>
</select>
</div>
<div class="form-actions padding10 no-padding-left">
<button class="button" type="submit">Submit</button>
<button class="button link" type="button">Cancel</button>
</div>
</form>
<script>
function submit(form){
console.log(form);
return true;
}
</script>
</div>
@@hit
</body>
</html>