forked from guillaumepotier/Parsley.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
documentation.html
1119 lines (1047 loc) · 52.5 KB
/
documentation.html
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
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Parsley.js Documentation & API</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<!-- Le styles -->
<link href="components/bootstrap/docs/assets/css/bootstrap.css" rel="stylesheet" />
<link href="http://yandex.st/highlightjs/7.3/styles/github.min.css" rel="stylesheet" />
<style type="text/css">
body {
padding-top: 20px;
padding-bottom: 40px;
}
h3.muted {
color: #08C;
}
/* Custom container */
.container-narrow {
margin: 0 auto;
max-width: 940px;
}
.container-narrow > hr {
margin: 30px 0;
}
/* Main marketing message and sign up button */
.jumbotron {
margin: 60px 0;
text-align: center;
}
.jumbotron h1 {
font-size: 72px;
line-height: 1;
}
.jumbotron .btn {
font-size: 21px;
padding: 14px 24px;
}
section {
margin-bottom: 45px;
}
form {
margin: 0;
}
input.parsley-success, textarea.parsley-success {
color: #468847 !important;
background-color: #DFF0D8 !important;
border: 1px solid #D6E9C6 !important;
}
input.parsley-error, textarea.parsley-error {
color: #B94A48 !important;
background-color: #F2DEDE !important;
border: 1px solid #EED3D7 !important;
}
input {
width: 150px;
margin: 0 2px !important;
}
ul.parsley-error-list {
font-size: 11px;
margin: 2px;
list-style-type:none;
}
ul.parsley-error-list li {
line-height: 11px;
}
.social-buttons {
padding: 5px 20px;
}
h3 {
color: #FB4006;
}
.container-narrow > hr {
margin:15px 0 0 0;
}
@media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
.not-for-mobile {
display: none;
}
}
</style>
<link href="components/bootstrap/docs/assets/css/bootstrap-responsive.css" rel="stylesheet">
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<a href="https://github.com/guillaumepotier/Parsley.js"><img style="position: fixed; top: 0; right: 0; border: 0; z-index:9999" src="https://s3.amazonaws.com/github/ribbons/forkme_right_orange_ff7600.png" alt="Fork me on GitHub"></a>
<div class="container-narrow">
<div class="masthead">
<ul class="nav nav-pills pull-right">
<li><a href="index.html">Home</a></li>
<li class="active"><a href="documentation.html">Documentation</a></li>
<li><a href="doc/api/index.html" target="_blank">API</a></li>
</ul>
<h3 class="muted">
Parsley.js
<span class="social-buttons inline-block">
<a href="https://twitter.com/share" class="twitter-share-button" data-related="garlicjs: auto persist form values to avoid data loss,guillaumepotier" data-url="http://parsleyjs.org" data-lang="en" data-text="Parsley.js: never write a single javascript line anymore to validate your forms FrontEnd. #ui #ux #javascript"></a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
<iframe src="http://ghbtns.com/github-btn.html?user=guillaumepotier&repo=parsley.js&type=watch&count=true"
allowtransparency="true" frameborder="0" scrolling="0" width="90" height="20"></iframe>
<!-- ><a style="height:30px;" href="http://news.ycombinator.com/submit" data-title="Show HN: Parsley.js - never write a single javascript line anymore to validate your forms FrontEnd" data-url="http://parsleyjs.org" class="hn-share-button"></a>-->
</span>
</h3>
</div>
<hr>
<div class="row-fluid marketing">
<h2>Demonstration</h2>
<a name="parsleydemoform"></a>
<table id="demonstration-form" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th width="27%">Classy demo</th>
<th width="73%" class="not-for-mobile">HTML Code (yes, no JS !)</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<form id="demo-form" data-validate="parsley">
<label for="fullname">Full Name * :</label>
<input type="text" id="fullname" name="fullname" data-required="true" />
<label for="email">Email * :</label>
<input type="text" id="email" name="email" data-trigger="change" data-required="true" data-type="email" />
<label for="website">Website :</label>
<input type="text" id="website" name="website" data-trigger="change" data-type="url" />
<label for="message">Message (20 chars min, 200 max) :</label>
<textarea id="message" name="message" data-trigger="keyup" data-rangelength="[20,200]"></textarea>
<input type="hidden" name="superhidden" id="superhidden">
<br/><span class="btn btn" id="demo-form-valid" onclick="javascript:$('#demo-form').parsley( 'validate' );"><i class="icon-ok"></i></span>
</form>
</td>
<td class="not-for-mobile">
<pre><code><form id="demo-form" data-validate="parsley">
<label for="fullname">Full Name * :</label>
<input type="text" id="fullname" name="fullname" data-required="true" />
<label for="email">Email * :</label>
<input type="text" id="email" name="email" data-trigger="change" data-required="true" data-type="email" />
<label for="website">Website :</label>
<input type="text" id="website" name="website" data-trigger="change" data-type="url" />
<label for="message">Message (20 chars min, 200 max) :</label>
<textarea id="message" name="message" data-trigger="keyup" data-rangelength="[20,200]"></textarea>
</form></code></pre>
</td>
</tr>
</table>
<div class="alert alert-block alert-info">
<span class="label label-important">Heads up!</span> <strong>Le #UX touch</strong>:
<ul>
<li>
<strong>Min char validation</strong>: Parsley by default <strong>do not proceed field validation under 3 char length</strong>. Do not assault your users with to soon error messages! <i>(this behavior is configurable)</i>.
</li>
<li>
<strong>Quick error removal</strong>: when a field is detected and shown as invalid, next checks are done on each keypress to try to <strong>quickly remove error(s) message(s) once field is ok</strong>.
</li>
<li>
<strong>Error focusing</strong>: on form submission, first error field is focused to <strong>allow user easily start its fixing process</strong>. <i>(this behavior configurable)</i>
</li>
</ul>
</div>
<hr>
<a name="top"></a>
<h2>Documentation</h2>
<ol>
<li><a href="#installation"><strong>Installation & usage</strong>: one or two inclusions !</a></li>
<li><a href="#parsleyform"><strong>Parsley Form</strong>: add some Parsley validation to your forms!</a></li>
<li><a href="#parsleyfield"><strong>Parsley Field</strong>: customize each validated field validation behavior </a></li>
<li>
<a href="#validators"><strong>Validators</strong>: learn the various validations you could do with Parsley</a>
<ol>
<li><a href="#basic-constraints">Basic constraints</a></li>
<li><a href="#type-constraints">Type constraints</a></li>
</ol>
</li>
<li>
<a href="#javascript"><strong>Javascript</strong>: yes, you still can do some javascript with Parsley. Intermediate level only!</a>
<ol>
<li><a href="#javascript-general">General</a></li>
<li><a href="#javascript-form">Form</a></li>
<li><a href="#javascript-fields">Fields</a></li>
</ol>
</li>
<li>
<a href="#parsleyclasses"><strong>Parsley CSS</strong>: last but not least, Parsley CSS used classes</a>
</li>
</ol>
<hr>
<!-- //////////////////////////////////////////////////////////////////////////////////////////////////// -->
<section>
<a name="installation"></a>
<h3>Parsley installation</h3>
<p>Just include <a href="https://github.com/guillaumepotier/Parsley.js/blob/master/dist/parsley.min.js">Parsley.js</a> file (with <a href="http://jquery.com/">jQuery</a> or <a href="http://zeptojs.com/">Zepto</a> loaded) or use <a href="https://github.com/guillaumepotier/Parsley.js/blob/master/dist/parsley-standalone.min.js">Parsley standalone</a> (with Zepto builded inside)</p>
<pre><code><script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="parsley.js"></script>
<form data-validate="parsley">
[...]
</form></code></pre>
</section>
<a href="#top" class="top pull-right">Top</a>
<!-- //////////////////////////////////////////////////////////////////////////////////////////////////// -->
<section>
<a name="parsleyform"></a>
<h3>Parsley Form</h3>
<p>This is the main Parsely form validation factory. Where you decide if a form is validated, and some extra options.</p>
<pre><code><form data-validate="parsley"></form></code></pre>
<h4>Properties</h4>
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>Property</th>
<th>Default</th>
<th>Description</th>
<th class="not-for-mobile">Demonstration</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>data-validate</code></td>
<td></td>
<td>Bind Parsley validation to the form and its items with validation constraints</td>
<td class="not-for-mobile"></td>
</tr>
<tr>
<td>
<code>data-focus</code>
</td>
<td>
first
</td>
<td>
Specify which error field would be focused first on form validation. <code>first</code>, <code>last</code> and <code>none</code> allowed
</td>
<td class="not-for-mobile">
<table>
<tr>
<td>
<form data-validate="parsley" id="focus-form" data-focus="last">
<p><input type="text" data-type="email" data-required="true" placeholder="won't have focus" /><p>
<p><input type="text" data-type="email" data-required="true" placeholder="will have focus" /></p>
</form>
</td>
<td>
<span class="btn btn-small" onclick="javascript:$('#focus-form').parsley('validate');">
<i class="icon-ok"></i>
</span>
</td>
</tr>
</table>
</td>
</tr>
</tbody>
</table>
</section>
<a href="#top" class="top pull-right">Top</a>
<!-- //////////////////////////////////////////////////////////////////////////////////////////////////// -->
<section>
<a name="parsleyfield"></a>
<h3>Parsley Field</h3>
<p>Once your form is validated by Parsley, add validation constraints and various other options.</p>
<pre><code><form data-validate="parsley">
<input type="text" name="email" data-type="email" />
</form></code></pre>
<h4>Properties</h4>
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>Property</th>
<th>Default</th>
<th>Description</th>
<th class="not-for-mobile">Demonstration</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>data-trigger</code>
</td>
<td>none</td>
<td>Specify one or many javascript events that will trigger item validation. eg: <code>data-trigger="change"</code>. To set multiple events, separate them by a space <code>data-trigger="focusin focusout"</code>.<br/>See <a href="http://api.jquery.com/category/events/">here</a> the various event supported by jQuery.</td>
<td class="not-for-mobile">
<form data-validate="parsley">
<p><input type="text" data-type="email" data-trigger="keyup" data-validation-minlength="0" placeholder="keyup validation trigger" /><p>
<p><input type="text" data-type="email" data-trigger="change" data-validation-minlength="0" placeholder="change validation trigger" /></p>
</form>
</td>
</tr>
<tr>
<td>
<code>data-validation-minlength</code>
</td>
<td>
3
</td>
<td>
Specify after how many characters entered validation process should fire. eg: <code>data-validation-minlength="4"</code>
</td>
<td class="not-for-mobile">
<form data-validate="parsley">
<p><input type="text" data-type="email" data-trigger="keyup" placeholder="default keyup validation" /><p>
<p><input type="text" data-type="email" data-trigger="keyup" data-validation-minlength="8" placeholder="8 chars keyup validation" /></p>
</form>
</td>
</tr>
</tbody>
</table>
</section>
<a href="#top" class="top pull-right">Top</a>
<!-- //////////////////////////////////////////////////////////////////////////////////////////////////// -->
<section>
<a name="validators"></a>
<div class="page-header">
<h3>Built-in Validators</h3>
</div>
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>Name</th>
<th>API</th>
<th>Description</th>
<th class="not-for-mobile">Demonstration</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="4">
<a name="basic-constraints"></a>
<h4>Basic constraints</h4>
</td>
</tr>
<!-- Required -->
<tr>
<td>Required</td>
<td>
<code>data-required="true"</code><br/><br/>
<code>class="required"</code><br/><br/>
<code>required="required"</code>
</td>
<td>Validate that a required field has been filled. </td>
<td class="not-for-mobile">
<table>
<tr>
<td>
<form data-validate="parsley">
<input type="text" id="data-required" data-required="true" placeholder="required field" />
</form>
</td>
<td>
<span class="btn btn-small" onclick="javascript:$('#data-required').parsley('validate');">
<i class="icon-ok"></i>
</span>
</td>
</tr>
</table>
</td>
</tr>
<!-- Notblank -->
<tr>
<td>Not Blank</td>
<td>
<code>data-notblank="true"</code>
</td>
<td>Validates that a value is not blank, defined as not equal to a blank string.</td>
<td class="not-for-mobile">
<table>
<tr>
<td>
<form data-validate="parsley">
<input type="text" id="data-notblank" data-notblank="true" placeholder="not blank field" />
</form>
</td>
<td>
<span class="btn btn-small" onclick="javascript:$('#data-notblank').parsley('validate');">
<i class="icon-ok"></i>
</span>
</td>
</tr>
</table>
</td>
</tr>
<!-- Minlength -->
<tr>
<td>Min Length</td>
<td>
<code>data-minlength="6"</code>
</td>
<td>Validates that the length of a string is at least as long as the given limit.</td>
<td class="not-for-mobile">
<table>
<tr>
<td>
<form data-validate="parsley">
<input type="text" id="data-minlength" data-minlength="6" placeholder="minlength = 6" />
</form>
</td>
<td>
<span class="btn btn-small" onclick="javascript:$('#data-minlength').parsley('validate');">
<i class="icon-ok"></i>
</span>
</td>
</tr>
</table>
</td>
</tr>
<!-- MaxLength -->
<tr>
<td>Max Length</td>
<td>
<code>data-maxlength="6"</code>
</td>
<td>Validates that the length of a string is not larger than the given limit.</td>
<td class="not-for-mobile">
<table>
<tr>
<td>
<form data-validate="parsley">
<input type="text" id="data-maxlength" data-maxlength="6" placeholder="maxlength = 6" />
</form>
</td>
<td>
<span class="btn btn-small" onclick="javascript:$('#data-maxlength').parsley('validate');">
<i class="icon-ok"></i>
</span>
</td>
</tr>
</table>
</td>
</tr>
<!-- RangeLength -->
<tr>
<td>Range Length</td>
<td>
<code>data-rangelength="[5,10]"</code>
</td>
<td>Validates that a given string length is between some minimum and maximum value.</td>
<td class="not-for-mobile">
<table>
<tr>
<td>
<form data-validate="parsley">
<input type="text" id="data-rangelength" data-rangelength="[5,10]" placeholder="rangelength = [5,10]" />
</form>
</td>
<td>
<span class="btn btn-small" onclick="javascript:$('#data-rangelength').parsley('validate');">
<i class="icon-ok"></i>
</span>
</td>
</tr>
</table>
</td>
</tr>
<!-- Min -->
<tr>
<td>Min</td>
<td>
<code>data-min="6"</code>
</td>
<td>Validates that a given number is greater than some minimum number.</td>
<td class="not-for-mobile">
<table>
<tr>
<td>
<form data-validate="parsley">
<input type="text" id="data-minimum" data-min="6" placeholder="min = 6" />
</form>
</td>
<td>
<span class="btn btn-small" onclick="javascript:$('#data-minimum').parsley('validate');">
<i class="icon-ok"></i>
</span>
</td>
</tr>
</table>
</td>
</tr>
<!-- Max -->
<tr>
<td>Max</td>
<td>
<code>data-max="100"</code>
</td>
<td>Validates that a given number is less than some maximum number.</td>
<td class="not-for-mobile">
<table>
<tr>
<td>
<form data-validate="parsley">
<input type="text" id="data-maximum" data-max="100" placeholder="max = 100" />
</form>
</td>
<td>
<span class="btn btn-small" onclick="javascript:$('#data-maximum').parsley('validate');">
<i class="icon-ok"></i>
</span>
</td>
</tr>
</table>
</td>
</tr>
<!-- Range -->
<tr>
<td>Range</td>
<td>
<code>data-range="[6, 100]"</code>
</td>
<td>Validates that a given number is between some minimum and maximum number.</td>
<td class="not-for-mobile">
<table>
<tr>
<td>
<form data-validate="parsley">
<input type="text" id="data-range" data-range="[6, 100]" placeholder="range = [6,100]" />
</form>
</td>
<td>
<span class="btn btn-small" onclick="javascript:$('#data-range').parsley('validate');">
<i class="icon-ok"></i>
</span>
</td>
</tr>
</table>
</td>
</tr>
<!-- RegExp -->
<tr>
<td>RegExp</td>
<td>
<code>data-regexp="<regexp>"</code>
</td>
<td>Validates that a value matches a specific regular expression. eg: validate a color hexadecimal code: <code>data-regexp="#[A-Fa-f0-9]{6}"</code>.</td>
<td class="not-for-mobile">
<table>
<tr>
<td>
<form data-validate="parsley">
<input type="text" id="data-regexp" data-regexp="#[A-Fa-f0-9]{6}" placeholder="hexa color code" />
</form>
</td>
<td>
<span class="btn btn-small" onclick="javascript:$('#data-regexp').parsley('validate');">
<i class="icon-ok"></i>
</span>
</td>
</tr>
</table>
</td>
</tr>
<!-- EqualTo -->
<tr>
<td>Equal To</td>
<td>
<code>data-equalTo="#elem"</code>
</td>
<td>Validates that a value is identical to #elem value. Useful for password repeat validation.</td>
<td class="not-for-mobile">
<table>
<tr>
<td>
<form data-validate="parsley">
<input type="text" id="eqalToModel" data-equalTo="#eqalToModel" disabled="disabled" value="foo" />
<input type="text" id="data-equalto" data-equalTo="#eqalToModel" placeholder="equal to foo" />
</form>
</td>
<td>
<span class="btn btn-small" onclick="javascript:$('#data-equalto').parsley('validate');">
<i class="icon-ok"></i>
</span>
</td>
</tr>
</table>
</td>
</tr>
<!-- minChecked -->
<tr>
<td>Min check</td>
<td>
<code>data-mincheck="2"</code>
</td>
<td>Validates that a certain checkboxes number is at least checked.</td>
<td class="not-for-mobile">
<table>
<tr>
<td>
<small>Check at least 2 checkboxes:</small>
<form data-validate="parsley">
<input type="checkbox" id="mincheck" name="mincheck[]" data-mincheck="2" value="foo" />
<input type="checkbox" name="mincheck[]" value="bar" />
<input type="checkbox" name="mincheck[]" value="baz" />
</form>
</td>
<td>
<span class="btn btn-small" onclick="javascript:$('#mincheck').parsley( 'validate' );">
<i class="icon-ok"></i>
</span>
</td>
</tr>
</table>
</td>
</tr>
<!-- maxChecked -->
<tr>
<td>Max check</td>
<td>
<code>data-maxcheck="2"</code>
</td>
<td>Validates that a certain checkboxes number is checked at maximum.</td>
<td class="not-for-mobile">
<table>
<tr>
<td>
<small>Check 2 checkboxes maximum:</small>
<form data-validate="parsley">
<input type="checkbox" id="maxcheck" name="maxcheck[]" data-maxcheck="2" value="foo" />
<input type="checkbox" name="maxcheck[]" value="bar" />
<input type="checkbox" name="maxcheck[]" value="baz" />
</form>
</td>
<td>
<span class="btn btn-small" onclick="javascript:$('#maxcheck').parsley( 'validate' );">
<i class="icon-ok"></i>
</span>
</td>
</tr>
</table>
</td>
</tr>
<!-- rangeChecked -->
<tr>
<td>Range check</td>
<td>
<code>data-rangecheck="[1,2]"</code>
</td>
<td>Validates that a certain checkboxes number is checked at maximum.</td>
<td class="not-for-mobile">
<table>
<tr>
<td>
<small>Check b/w 1&2 checkboxes:</small>
<form data-validate="parsley">
<span>
<input type="checkbox" id="rangecheck" name="rangecheck[]" data-rangecheck="[1,2]" value="foo" />
<input type="checkbox" name="rangecheck[]" value="bar" />
<input type="checkbox" name="rangecheck[]" value="baz" />
</span>
</form>
</td>
<td>
<span class="btn btn-small" onclick="javascript:$('#rangecheck').parsley( 'validate' );">
<i class="icon-ok"></i>
</span>
</td>
</tr>
</table>
</td>
</tr>
<!-- Remote -->
<tr>
<td>Remote (Ajax)</td>
<td>
<code>data-remote="http://yoururl.com"</code>
</td>
<td colspan="2"><strong>Custom ajax validation made simple.</strong><br/>
<code>data-remote-method="POST"</code> to change default <code>GET</code> call.<br/>
<code>data-remote-datatype="jsonp"</code> if you make cross domain ajax call and expect <code>jsonp</code><br/>
Parsley will accept these valid returns: <code>1</code>, <code>true</code>, <code>{ success: "" }</code> and consider false otherwise
</td>
</tr>
<tr>
<td colspan="4">
<a name="type-constraints"></a>
<h4>Type constraints</h4>
</td>
</tr>
<!-- Email -->
<tr>
<td>Email</td>
<td>
<code>data-type="email"</code>
</td>
<td>Validates that a value is a valid email address.</td>
<td class="not-for-mobile">
<table>
<tr>
<td>
<form data-validate="parsley">
<input type="text" id="data-email" data-type="email" placeholder="email" />
</form>
</td>
<td>
<span class="btn btn-small" onclick="javascript:$('#data-email').parsley('validate');">
<i class="icon-ok"></i>
</span>
</td>
</tr>
</table>
</td>
</tr>
<!-- Url -->
<tr>
<td>Url</td>
<td>
<code>data-type="url"</code>
</td>
<td>Validates that a value is a valid url.</td>
<td class="not-for-mobile">
<table>
<tr>
<td>
<form data-validate="parsley">
<input type="text" id="data-url" data-type="url" placeholder="url" />
</form>
</td>
<td>
<span class="btn btn-small" onclick="javascript:$('#data-url').parsley('validate');">
<i class="icon-ok"></i>
</span>
</td>
</tr>
</table>
</td>
</tr>
<!-- Digits -->
<tr>
<td>Digits</td>
<td>
<code>data-type="digits"</code>
</td>
<td>Validates that a value is only digits.</td>
<td class="not-for-mobile">
<table>
<tr>
<td>
<form data-validate="parsley">
<input type="text" id="data-digits" data-type="digits" placeholder="digits" />
</form>
</td>
<td>
<span class="btn btn-small" onclick="javascript:$('#data-digits').parsley('validate');">
<i class="icon-ok"></i>
</span>
</td>
</tr>
</table>
</td>
</tr>
<!-- Number -->
<tr>
<td>Number</td>
<td>
<code>data-type="number"</code>
</td>
<td>Validates that a value is a valid number.</td>
<td class="not-for-mobile">
<table>
<tr>
<td>
<form data-validate="parsley">
<input type="text" id="data-number" data-type="number" placeholder="number" />
</form>
</td>
<td>
<span class="btn btn-small" onclick="javascript:$('#data-number').parsley('validate');">
<i class="icon-ok"></i>
</span>
</td>
</tr>
</table>
</td>
</tr>
<!-- Alphanum -->
<tr>
<td>Alphanum</td>
<td>
<code>data-type="alphanum"</code>
</td>
<td>Validates that a value is a valid alphanumeric string.</td>
<td class="not-for-mobile">
<table>
<tr>
<td>
<form data-validate="parsley">
<input type="text" id="data-alphanum" data-type="alphanum" placeholder="alphanumeric string" />
</form>
</td>
<td>
<span class="btn btn-small" onclick="javascript:$('#data-alphanum').parsley('validate');">
<i class="icon-ok"></i>
</span>
</td>
</tr>
</table>
</td>
</tr>
<!-- DateIso -->
<tr>
<td>Date Iso</td>
<td>
<code>data-type="dateIso"</code>
</td>
<td>Validates that a value is a valid ISO date.</td>
<td class="not-for-mobile">
<table>
<tr>
<td>
<form data-validate="parsley">
<input type="text" id="data-dateIso" data-type="dateIso" placeholder="YYYY-MM-DD" />
</form>
</td>
<td>
<span class="btn btn-small" onclick="javascript:$('#data-dateIso').parsley('validate');">
<i class="icon-ok"></i>
</span>
</td>
</tr>
</table>
</td>
</tr>
</tbody>
</table>
</section>
<a href="#top" class="top pull-right">Top</a>
<!-- //////////////////////////////////////////////////////////////////////////////////////////////////// -->
<section>
<a name="javascript"></a>
<div class="page-header">
<h3>Javascript</h3>
<p>Parsley DOM-API is great. But not so great for complex forms, or dynamically generated forms. Learn here how to masterise Parsley javascript style!</p>
<p class="alert alert-block">
<span class="label">Warning</span> you must remove <code>data-validate="parsley"</code> auto-binding code in your forms DOM to allow you to use Parsley javascript-way and override default configuration.
</p>
</div>
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>Method</th>
<th>Returns</th>
<th width="40%">Description</th>
<th width="40%" class="not-for-mobile">Code</th>
</tr>
</thead>
<tbody>
<tr>
<a name="javascript-general"></a>
<td colspan="4"><h4>General</h4></td>
</tr>
<tr>
<td>Override default plugin configs</td>
<td></td>
<td >Parsley uses a set of default overridable configs that you can override passing an object as parameter when calling Parsley on a form or a field.<br/>Default is:
<pre><code>{
// basic data-api overridable properties here..
inputs: 'input, textarea, select'
, excluded: 'input[type=hidden]'
, trigger: false
, focus: 'first'
, validationMinlength: 3
, successClass: 'parsley-success'
, errorClass: 'parsley-error'
, validators: {}
, messages: {}
//some quite advanced configuration here..
, error: {
classHandler: function ( elem ) {}
, container: function ( elem, template, isRadioOrCheckbox ) {}
, errorsWrapper: '<ul></ul>'
, errorElem: '<li></li>'
}
, listeners: {
onFieldValidate: function ( elem ) { return false; }
, onFormSubmit: function ( isFormValid, event, focusedField ) {}
, onFieldError: function ( elem, constraint ) {}
}
}</code></pre>
</td>
<td class="not-for-mobile"><p>Add a custom validator that checks if number is a multiple of another:</p>
<pre><code>$( '#form' ).parsley( {
validators: {
multiple: function ( val, multiple ) {
return val % multiple === 0;
}
}
, messages: {
multiple: "This value should be a multiple of %s"
}
} );
<input type="text" data-multiple="3" /></code></pre>
<form id="parsley-multiple">
<input type="text" id="data-multiple" data-validation-minlength="0" data-trigger="keyup" data-multiple="3" placeholder="multiple of 3" />
</form>
</td>
</tr>
<tr>
<td>Add a listener</td>
<td></td>
<td>Allow you, even after Parsley initial form binding to add a custom listener. Available listeners curently are: <code>onFieldValidate</code>, <code>onFieldError</code> and <code>onFormSubmit</code> and their passed arguments are listed above in Default Plugin config.</td>
<td class="not-for-mobile">
<pre><code>$( '#form' ).parsley( 'addListener', {
onFieldValidate: function ( elem ) {
// if field is not visible, do not apply Parsley validation !
if ( !$( elem ).is( ':visible' ) ) {
return true;
}
return false;
}
} );</code></pre>
</td>
</tr>
<tr>
<a name="javascript-form"></a>
<td colspan="4"><h4>Form</h4></td>
</tr>
<tr>
<td>Bind Parsley to a form</td>
<td></td>
<td>Useful if your form is dynamically rendered.</td>
<td class="not-for-mobile">
<pre><code>$( '#form' ).parsley();</code></pre>
</td>
</tr>
<tr>
<td>Validate a form</td>
<td>Boolean</td>
<td>Useful if your want to integrate validation process inside custom functions.</td>
<td class="not-for-mobile">
<pre><code>$( '#form' ).parsley( 'validate' );</code></pre>
</td>
</tr>
<tr>
<a name="javascript-item"></a>
<td colspan="4"><h4>Item</h4></td>
</tr>
<tr>
<td>Validate a field</td>