-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi.html
executable file
·2660 lines (2628 loc) · 149 KB
/
api.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>
<head>
<meta charset="utf-8">
<title>API | formJS - JavaScript Form Validation. Made Easy</title>
<meta name="description" content="JavaScript Form Validation. Made Easy">
<meta name="keywords" content="form, validation, javascript, plugin">
<meta name="author" content="Valerio Di Punzio">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="https://fonts.googleapis.com/css?family=Expletus+Sans:500|Raleway:200&display=swap" rel="stylesheet">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/doc.css">
<link rel="stylesheet" href="css/prism.css">
<script defer src="js/prism.js"></script>
<script defer src="js/include.js"></script>
</head>
<body>
<div id="top" class="container-fluid d-flex flex-column">
<div id="menu" class="position-sticky text-right d-flex">
<div class="position-raltive w-100">
<a href="index.html" class="logo">f</a>
<nav class="position-absolute nav-desktop d-none d-md-flex align-items-center">
<a href="index.html" class="p-2 m-2">Home</a>
<a href="get-started.html" class="p-2 m-2">Get Started</a>
<a href="api.html" class="p-2 m-2">API</a>
<a href="demos.html" class="p-2 m-2">Demos</a>
<a href="https://github.com/SimplySayHi/formJS" target="_blank" class="github-logo ml-2">
<svg version="1.1" id="Livello_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="28px" height="28px" viewBox="0 0 32 32" enable-background="new 0 0 32 32" xml:space="preserve">
<path fill-rule="evenodd" clip-rule="evenodd" fill="#FFFFFF" d="M16,0.112c-8.836,0-16,7.294-16,16.291 C0,23.6,4.584,29.706,10.942,31.86c0.801,0.148 1.093-0.354,1.093-0.785c0-0.387-0.015-1.412-0.021-2.771 c-4.451,0.984-5.39-2.184-5.39-2.184c-0.729-1.881-1.777-2.383-1.777-2.383c-1.452-1.01,0.11-0.99,0.11-0.99 .605,0.115,2.45,1.68,2.45,1.68c1.428,2.488,3.745,1.77,4.657,1.354c0.145-1.053,0.559-1.771,1.016-2.178 c-3.553-0.412-7.288-1.809-7.288-8.051c0-1.778,0.623-3.232,1.646-4.371c-0.164-0.412-0.713-2.068,0.157-4.311 c0,0,1.344-0.438,4.399,1.67c1.276-0.361,2.646-0.543,4.006-0.549c1.359,0.006,2.728,0.188,4.006,0.549 c3.056-2.108,4.396-1.67,4.396-1.67c0.873,2.242,0.323,3.898,0.159,4.311c1.024,1.139,1.644,2.593,1.644,4.371 c0,6.258-3.74,7.635-7.305,8.038c0.574,0.504,1.086,1.498,1.086,3.018c0,2.178-0.02,3.934-0.02,4.469 c0,0.436,0.288,0.941,1.101,0.783C27.421,29.7,32,23.598,32,16.403C32,7.406,24.837,0.112,16,0.112z" />
</svg>
</a>
</nav>
<div class="position-absolute dropdown d-inline-block d-md-none">
<button class="btn dropdown-toggle dropdown-red-outline py-0 px-2" data-toggle="dropdown" type="button">
menu
</button>
<span class="dropdown-menu">
<a class="dropdown-item" href="index.html">Home</a>
<a class="dropdown-item" href="get-started.html">Get Started</a>
<a class="dropdown-item" href="api.html">API</a>
<a class="dropdown-item" href="demos.html">Demos</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="https://github.com/SimplySayHi/formJS" target="_blank">View on Github</a>
<a class="dropdown-item" href="https://github.com/SimplySayHi/formJS/issues" target="_blank">Report a Bug</a>
</span>
</div>
</div>
</div>
<div class="page-content mt-5 pt-5">
<h4 class="m-0 px-2">formJS</h4>
<h1 class="border-0 m-0">API</h1>
<div class="sticky-nav-2 position-sticky d-flex align-items-center overflow-auto">
<a href="#field-options">Field Options</a> |
<a href="#form-options">Form Options</a> |
<a href="#methods">Methods</a> |
<a href="#static-methods">Static</a> |
<a href="#builtin-events">Events</a> |
<a href="#builtin-validations">Validations</a> |
<a href="#utils">Utils</a>
</div>
<!-- Lite Version Options -->
<div class="mt-5">
<hr />
<p class="m-0">
Features included in Lite version have this badge: <span class="badge badge-pill badge-yellow">Lite</span>
</p>
<div class="toggable-content-outer">
Get a quick peek of features included in Lite version:
<input type="checkbox" class="fake-checkbox btn-toggable-content" id="lite-show-more" />
<label class="toggable-label text-red" for="lite-show-more">
<span>show more</span>
<span>close</span>
</label>
<div class="toggable-content">
<div class="d-flex flex-wrap">
<div class="col-sm-6 col-md-3">
<h3 class="small-title mt-3">Field Options</h3>
<ul>
<li>
beforeValidation
</li>
<li>
focusOnRelated
</li>
<li>
maxFileSize
</li>
</ul>
</div>
<div class="col-sm-6 col-md-3">
<h3 class="small-title mt-3">Methods</h3>
<ul>
<li>
destroy
</li>
<li>
validateField
</li>
<li>
validateForm
</li>
</ul>
</div>
<div class="col-sm-6 col-md-3">
<h3 class="small-title mt-3">Static</h3>
<ul>
<li>
as full version
</li>
</ul>
</div>
<div class="col-sm-6 col-md-3">
<h3 class="small-title mt-3">Events</h3>
<ul>
<li>
fjs.field:validation
</li>
<li>
fjs.form:destroy
</li>
<li>
fjs.form:init
</li>
<li>
fjs.form:validation
</li>
</ul>
</div>
<div class="col-sm-6 col-md-3">
<h3 class="small-title mt-3">Validations</h3>
<ul>
<li>
as full version
</li>
</ul>
</div>
</div>
</div>
</div>
<hr />
</div>
<!-- Instance -->
<div id="instance">
<h3 class="sticky-title">Instance<span class="small">:</span></h3>
<div>
<p>
Once the instance is created, you can access to it from the DOM node of the form:
</p>
<pre><code class="language-js">const formInstance = document.querySelector('form').formjs</code></pre>
<p>
and you can access these properties directly from the form instance:
</p>
<ul>
<li>
<span class="text-green">Current group</span>: <code>formInstance.currentGroup</code> ( default value is <code>options.formOptions.groups[0]</code> )
</li>
<li>
<span class="text-green">Form element</span>: <code>formInstance.$form</code>
</li>
<li>
<span class="text-green">Options</span>: <code>formInstance.options</code>
</li>
<li>
<span class="text-green">Version</span>: <code>formInstance.version</code>
</li>
</ul>
</div>
</div>
<!-- Options -->
<div id="options-list">
<h3 class="sticky-title">Options<span class="small">:</span></h3>
<div>
<p>
formJS takes an object as second parameter, <code>options</code>, as follow:
</p>
<pre>
<code class="language-js">{
fieldOptions: {...},
formOptions: {...}
}</code></pre>
<br />
</div>
<!-- Field Options -->
<div id="field-options">
<h3 class="sticky-title mt-0 ml-4em bg-transparent"><span class="small">Field Options</span></h3>
<p class="mt-5 mb-0">
Field options that will be used for every field of the form.
<br /><br />
You can also set specific field options for a specific field or group of checkboxes/radios via HTML attribute <code class="text-green">data-field-options</code> as JSON string ( <a href="./demos/demo-data-field-options.html">see demo</a> ).
<br />
This is the list of field options you can set:
</p>
<ul>
<li><code>cssClasses</code></li>
<li><code>focusOnRelated</code></li>
<li><code>maxFileSize</code></li>
<li><code>questionContainer</code></li>
<li><code>skipUIfeedback</code></li>
<li><code>trimValue</code></li>
</ul>
<div class="panel panel-default panel-transparent no-bg">
<div class="sticky-header card-header bg-white text-dark clearfix d-none d-lg-block">
<div class="d-flex">
<div class="col-xl-4 d-none d-xl-block">
name
</div>
<div class="col-lg-4 col-xl-3">
<span class="d-inline d-xl-none">name, </span>
type
</div>
<div class="col-lg-8 col-xl-5">
description
</div>
</div>
</div>
<div class="card-body">
<div class="clearfix padding-tb-md row-list-separator d-flex flex-wrap">
<div class="col-lg-auto col-xl-4">
<pre class="text-green">beforeValidation</pre>
<span class="badge badge-pill badge-yellow">Lite</span>
<div class="mt-1">
<a href="./demos/demo-callback-before-validation.html">see demo</a>
</div>
</div>
<div class="w-100 d-xl-none"></div>
<div class="col-lg-4 col-xl-3">
function / array of functions
<br /><br />
</div>
<div class="col-lg-8 col-xl-5">
<p>
Each function:<br /><br />
Fires just before a field is being validated and it is executed as Promise ( or chain/sequence of Promises if as array ).
</p>
<p>
Additionally, the keyword <code>this</code> is bound to the Form instance.
</p>
<div class="card-footer bg-transparent pb-0 px-0">
<p class="text-green">
Parameters
</p>
<ul>
<li>
<span class="text-green">data</span>: ( Object )
<pre>
<code class="language-js">{
$field: $field,
fieldOptions: {...}
}
</code></pre>
<ul>
<li>
<span class="text-green">$field</span>: JS node element ( the field that will be validated )
</li>
<li>
<span class="text-green">fieldOptions</span>: JS object ( field options from the form instance merged with field specific options from <code>data-field-options</code> if present )
</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
<div class="clearfix padding-tb-md row-list-separator d-flex flex-wrap">
<div class="col-lg-auto col-xl-4">
<pre class="text-green">cssClasses</pre>
</div>
<div class="w-100 d-xl-none"></div>
<div class="col-lg-4 col-xl-3">
object
<br /><br />
</div>
<div class="col-lg-8 col-xl-5">
<p>
JS object with keys:
</p>
<ul>
<li>
<span class="text-green">dirty</span>: ( string ) CSS class(es) to be applied if the field "dirty" ( has some value )
</li>
<li>
<span class="text-green">error</span>: ( string ) CSS class(es) to be applied if the field is not valid ( in any error case )
</li>
<li>
<span class="text-green">errorEmpty</span>: ( string ) additional CSS class(es) to be applied if the field value is empty
</li>
<li>
<span class="text-green">errorRule</span>: ( string ) additional CSS class(es) to be applied if the field value does not comply the validation rule
</li>
<li>
<span class="text-green">modified</span>: ( string ) CSS class(es) to be applied if the field has a different value than page load
</li>
<li>
<span class="text-green">pending</span>: ( string ) CSS class(es) to be applied when the field validation starts and removed when it finishes ( useful for async validations )
</li>
<li>
<span class="text-green">touched</span>: ( string ) CSS class(es) to be applied if the user blurred the field or group/form has been validated
</li>
<li>
<span class="text-green">valid</span>: ( string ) CSS class(es) to be applied if the field is valid
</li>
</ul>
<p>
These classes are useful to show different error messages based on the error type and / or change the UI.
</p>
</div>
</div>
<div class="clearfix padding-tb-md row-list-separator d-flex flex-wrap">
<div class="col-lg-auto col-xl-4">
<pre class="text-green">focusOnRelated</pre>
<span class="badge badge-pill badge-yellow">Lite</span>
</div>
<div class="w-100 d-xl-none"></div>
<div class="col-lg-4 col-xl-3">
boolean
<br /><br />
</div>
<div class="col-lg-8 col-xl-5">
<p>
Whether or not to focus on the related ( input / select ) field when selecting its radio answer
</p>
</div>
</div>
<div class="clearfix padding-tb-md row-list-separator d-flex flex-wrap">
<div class="col-lg-auto col-xl-4">
<pre class="text-green">maxFileSize</pre>
<span class="badge badge-pill badge-yellow">Lite</span>
</div>
<div class="w-100 d-xl-none"></div>
<div class="col-lg-4 col-xl-3">
number
<br /><br />
</div>
<div class="col-lg-8 col-xl-5">
<p>
Size limit ( in MB ) for each file to upload.<br />
Set to 0 ( zero ) if you want to disable the size check.<br />
Can also be set on the specific field via attribute <code>data-max-file-size</code> to set a custom limit.
</p>
<p>
HTML attribute <code>data-max-file-size</code> is now <span class="text-red">DEPRECATED</span> and will be removed soon.
</p>
</div>
</div>
<div class="clearfix padding-tb-md row-list-separator d-flex flex-wrap">
<div class="col-lg-auto col-xl-4">
<pre class="text-green">onValidationCheckAll</pre>
</div>
<div class="w-100 d-xl-none"></div>
<div class="col-lg-4 col-xl-3">
boolean
<br /><br />
</div>
<div class="col-lg-8 col-xl-5">
<p>
If set to <code>true</code>, when a field is valid, this will fire the whole form validation without feedback on the UI and will emit ONLY built-in event <code>fjs.form:validation</code>.<br />
If option <code>groups</code> is set, ONLY fields of <code>this.currentGroup</code> will be validated ( not the whole form ) and event emitted is <code>fjs.group:validation</code>.<br />
This is useful to check if the whole form/group is valid on each field validation.
</p>
</div>
</div>
<div class="clearfix padding-tb-md row-list-separator d-flex flex-wrap">
<div class="col-lg-auto col-xl-4">
<pre class="text-green">preventPasteFields</pre>
</div>
<div class="w-100 d-xl-none"></div>
<div class="col-lg-4 col-xl-3">
string
<br /><br />
</div>
<div class="col-lg-8 col-xl-5">
<p>
CSS string selector for which the paste command will be disabled
</p>
</div>
</div>
<div class="clearfix padding-tb-md row-list-separator d-flex flex-wrap">
<div class="col-lg-auto col-xl-4">
<pre class="text-green">questionContainer</pre>
</div>
<div class="w-100 d-xl-none"></div>
<div class="col-lg-4 col-xl-3">
string
<br /><br />
</div>
<div class="col-lg-8 col-xl-5">
<p>
CSS string selector used internally to find the container to add/remove CSS classes useful for feedback on UI.
</p>
</div>
</div>
<div class="clearfix padding-tb-md row-list-separator d-flex flex-wrap">
<div class="col-lg-auto col-xl-4">
<pre class="text-green">skipUIfeedback</pre>
</div>
<div class="w-100 d-xl-none"></div>
<div class="col-lg-4 col-xl-3">
boolean
<br /><br />
</div>
<div class="col-lg-8 col-xl-5">
<p>
If true, the css classes for 'error' ( any type ), 'valid' and 'pending' fields and form will not be added
</p>
</div>
</div>
<div class="clearfix padding-tb-md row-list-separator d-flex flex-wrap">
<div class="col-lg-auto col-xl-4">
<pre class="text-green">strictHtmlValidation</pre>
</div>
<div class="w-100 d-xl-none"></div>
<div class="col-lg-4 col-xl-3">
boolean
<br /><br />
</div>
<div class="col-lg-8 col-xl-5">
<p>
Activate JS controls for strict JS validation ( as for HTML5 attributes or emulation )
</p>
</div>
<div class="col-12 px-md-4 py-md-3 d-flex flex-wrap">
<div class="card-footer no-bg col-12 col-md-6 py-3">
<div><code>maxlength</code></div>
<div>
<div class="text-red">problem:</div>
it does not work on Android Chrome/stock borwsers
</div>
<div>
<div class="text-green">solution:</div>
emulation of working maxlength attribute: avoid to write more than specified length.
</div>
</div>
<div class="card-footer no-bg col-12 col-md-6 py-3">
<div><code>data-type="number"</code></div>
<div>
<div class="text-red">problem:</div>
in some browsers, inputs with type="number" allow the user to insert non-numeric chars.
</div>
<div>
<div class="text-green">solution:</div>
emulation of working type="number" attribute thanks to data-type="number" attribute: allow to write only numeric values with/without "+", "-", ".", ",".
</div>
</div>
</div>
</div>
<div class="clearfix padding-tb-md row-list-separator d-flex flex-wrap">
<div class="col-lg-auto col-xl-4">
<pre class="text-green">trimValue</pre>
</div>
<div class="w-100 d-xl-none"></div>
<div class="col-lg-4 col-xl-3">
boolean
<br /><br />
</div>
<div class="col-lg-8 col-xl-5">
<p>
Whether or not to trim the field value before running the validation ( select, checkbox, radio and file input are not trimmed ).
</p>
<p>
<span class="text-green">Tip</span>: use this option with caution. If set to true and <code>validateOnEvents</code> contains "input", this will prevent the user to type spaces at the beginning/end and leads to a bad user experience.
</p>
</div>
</div>
<div class="clearfix padding-tb-md row-list-separator d-flex flex-wrap">
<div class="col-lg-auto col-xl-4">
<pre class="text-green">validateOnEvents</pre>
<div class="mt-1">
<a href="./demos/demo-option-validate-on-events.html">see demo</a>
</div>
</div>
<div class="w-100 d-xl-none"></div>
<div class="col-lg-4 col-xl-3">
string
<br /><br />
</div>
<div class="col-lg-8 col-xl-5">
<p>
Events on which the validation will fire ( only for required fields )
<br /><br />
<span class="text-green">Tip</span>: always add <code>change</code> to the events list in order to properly validate checkbox, radio, file inputs and selects.
<br />
For example: <code>change input</code> or <code>change blur</code>.
<br /><br />
<span class="text-green">Tip</span>: in order to validate "textual" fields ( with type text, email etc ) only on change event, you must set this option to <code>change</code>. Setting this option with multiple values ( for example <code>change input</code> ) will fire validation for "textual" fields ONLY on <code>input</code> event.
</p>
</div>
</div>
</div>
<div class="card-footer no-bg">
<p>
Default field options:
</p>
<pre>
<code class="language-js">{
beforeValidation: [beforeValidationDefault],
cssClasses: {
dirty: 'is-dirty',
error: 'has-error',
errorEmpty: 'has-error-empty',
errorRule: 'has-error-rule',
modified: 'is-modified',
pending: 'is-pending',
touched: 'is-touched',
valid: 'is-valid'
},
focusOnRelated: true,
maxFileSize: 10,
onValidationCheckAll: false,
preventPasteFields: '[type="password"], [data-equal-to]',
questionContainer: '[data-formjs-question]',
skipUIfeedback: false,
strictHtmlValidation: true,
trimValue: false,
validateOnEvents: 'input change'
}
</code></pre>
</div>
</div>
</div>
<br />
<!-- Form Options -->
<div id="form-options">
<h3 class="sticky-title mt-0 ml-4em bg-transparent"><span class="small">Form Options</span></h3>
<div class="panel panel-default panel-transparent no-bg mt-5">
<div class="sticky-header card-header bg-white text-dark clearfix d-none d-lg-block">
<div class="d-flex">
<div class="col-lg-6 col-xl-3">
name ( type )<span class="d-inline d-xl-none">, parameters</span>
</div>
<div class="col-xl-5 d-none d-xl-block">
parameters
</div>
<div class="col-lg-6 col-xl-4">
description
</div>
</div>
</div>
<div class="card-body">
<div class="clearfix padding-tb-md row-list-separator d-flex flex-wrap">
<div class="col-lg-auto col-xl-3">
<pre class="text-green">ajaxOptions</pre>
<p>( object )</p>
</div>
<div class="w-100 d-xl-none"></div>
<div class="col-lg-6 col-xl-5">
</div>
<div class="col-lg-6 col-xl-4">
<p>
See <a href="https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters" target="_blank">MDN documentation</a>
<br /><br />
In addition, you can set these properties:
</p>
<ul>
<li>
<span class="text-green">timeout</span>: ( number )
</li>
<li>
<span class="text-green">url</span>: ( string )
</li>
</ul>
<p>
<b class="text-green">NOTE</b>: Attribute <code>enctype="multipart/form-data"</code> on form tag will not set header <code>Content-Type</code> since it's better to let the browser set it automatically.
<br />
Manually set header <code>Content-Type</code> only for specific, manual-management cases.
<br />
Setting form attribute <code>enctype</code> or header <code>Content-Type</code> will allow data transformation to <code>FormData</code>.
</p>
</div>
</div>
<div class="clearfix padding-tb-md row-list-separator d-flex flex-wrap">
<div class="col-lg-auto col-xl-3">
<pre class="text-green">ajaxSubmit</pre>
<p>( boolean )</p>
</div>
<div class="w-100 d-xl-none"></div>
<div class="col-lg-6 col-xl-5">
</div>
<div class="col-lg-6 col-xl-4">
<p>
To allow submit the form via AJAX.
</p>
</div>
</div>
<div class="clearfix padding-tb-md row-list-separator d-flex flex-wrap">
<div class="col-lg-auto col-xl-3">
<pre class="text-green">beforeSend</pre>
<p>( function / array of functions )</p>
</div>
<div class="w-100 d-xl-none"></div>
<div class="col-lg-6 col-xl-5">
<p class="d-lg-none m-0">
Parameters:
</p>
<p>
Each function:
</p>
<ul>
<li>
<span class="text-green">data</span>: ( Object )
<pre>
<code class="language-js">{
formData: {},
stopExecution: false
}</code></pre>
<ul>
<li>
<span class="text-green">formData</span>: Object ( ONLY for AJAX forms ) with the form data
</li>
<li>
<span class="text-green">stopExecution</span>: Boolean ( default is false ) whether or not to prevent the form submit ( AJAX or default ).
</li>
</ul>
</li>
</ul>
<p>
Additionally, the keyword <code>this</code> is bound to the Form instance.
</p>
</div>
<div class="col-lg-6 col-xl-4">
<p class="d-lg-none m-0">
Description:
</p>
<p>
Each function:<br /><br />
It is executed as Promise ( or chain/sequence of Promises if as array ).<br /><br />
For AJAX forms:<br />
Fires before the AJAX call starts. If used to modify the form data or prevent the AJAX call to start, it must return the object <code>data</code> ( optionally as Promise ) passed to it.
<br /><br />
For HTML forms:<br />
Fire before form submit. Can be used to execute some custom code ( example: populate a hidden field ) or to prevent the form submit ( in this case, it must have a return statement as above ).
</p>
</div>
</div>
<div class="clearfix padding-tb-md row-list-separator d-flex flex-wrap">
<div class="col-lg-auto col-xl-3">
<pre class="text-green">cssClasses</pre>
<p>( object )</p>
</div>
<div class="w-100 d-xl-none"></div>
<div class="col-lg-6 col-xl-5">
</div>
<div class="col-lg-6 col-xl-4">
<p>
JS object with keys:
</p>
<ul>
<li>
<span class="text-green">ajaxComplete</span>: ( string ) CSS class(es) to be applied when the ajax call for form submission has been completed ( useful for ajax forms )
</li>
<li>
<span class="text-green">ajaxError</span>: ( string ) CSS class(es) to be applied when the ajax call for form submission has finished with an error ( useful for ajax forms )
</li>
<li>
<span class="text-green">ajaxPending</span>: ( string ) CSS class(es) to be applied when the ajax call for form submission starts and removed when it finishes ( useful for ajax forms )
</li>
<li>
<span class="text-green">ajaxSuccess</span>: ( string ) CSS class(es) to be applied when the ajax call for form submission has finished with success ( useful for ajax forms )
</li>
<li>
<span class="text-green">error</span>: ( string ) CSS class(es) to be applied when the form is not valid
</li>
<li>
<span class="text-green">pending</span>: ( string ) CSS class(es) to be applied when the form validation starts and removed when it finishes
</li>
<li>
<span class="text-green">submit</span>: ( string ) CSS class(es) to be applied when the form submission starts and removed when it finishes ( useful for ajax forms )
</li>
<li>
<span class="text-green">valid</span>: ( string ) CSS class(es) to be applied when the form is valid
</li>
</ul>
</div>
</div>
<div class="clearfix padding-tb-md row-list-separator d-flex flex-wrap">
<div class="col-lg-auto col-xl-3">
<pre class="text-green">getFormData</pre>
<p>( function )</p>
</div>
<div class="w-100 d-xl-none"></div>
<div class="col-lg-6 col-xl-5">
<p class="d-lg-none m-0">
Parameters:
</p>
<ul>
<li>
<span class="text-green">fields</span>: a filtered list of form fields.
</li>
<li>
<span class="text-green">trimValues</span>: boolean indicating if field values must be trimmed or not ( by default it takes the value from <code>fieldOptions.trimValue</code> - values from selects, checkboxes, radios and file inputs are not trimmed ).
</li>
</ul>
<p>
These fields are excluded:
<br />
<code>type="reset"</code>
<code>type="submit"</code>
<code>type="button"</code>
<code>type="file"</code>
<code>data-exclude-data</code>
<br />
If you want to select fields by yourself, you can access the form element through <code>this.$form</code>.
</p>
<p>
Additionally, the keyword <code>this</code> is bound to the Form instance.
</p>
</div>
<div class="col-lg-6 col-xl-4">
<p class="d-lg-none m-0">
Description:
</p>
<p>
If set, it will be will replace the default function for "getFormData" method.
</p>
</div>
</div>
<div class="clearfix padding-tb-md row-list-separator d-flex flex-wrap">
<div class="col-lg-auto col-xl-3">
<pre class="text-green">groups</pre>
<p>( array of CSS selectors )</p>
</div>
<div class="w-100 d-xl-none"></div>
<div class="col-lg-6 col-xl-5">
</div>
<div class="col-lg-6 col-xl-4">
<p>
List of CSS selectors to define groups of validation.<br />
If defined they will act like "steps", so, on form submit or call method <code>validateForm</code>, the fields that match the selector will be valdiated ( see also method <code>validateFieldsGroup</code> )
</p>
</div>
</div>
<div class="clearfix padding-tb-md row-list-separator d-flex flex-wrap">
<div class="col-lg-auto col-xl-3">
<pre class="text-green">handleFileUpload</pre>
<p>( boolean )</p>
</div>
<div class="w-100 d-xl-none"></div>
<div class="col-lg-6 col-xl-5">
</div>
<div class="col-lg-6 col-xl-4">
<p>
Whether or not to handle the file upload. It is a simple file upload via ajax.<br />
You must also set the enctype="multipart/form-data" attribute to the form.
<br />
<span class="small">( NOT used if <code>ajaxSubmit: false</code> )</span>
</p>
</div>
</div>
<div class="clearfix padding-tb-md row-list-separator d-flex flex-wrap">
<div class="col-lg-auto col-xl-3">
<pre class="text-green">handleSubmit</pre>
<p>( boolean )</p>
</div>
<div class="w-100 d-xl-none"></div>
<div class="col-lg-6 col-xl-5">
</div>
<div class="col-lg-6 col-xl-4">
<p class="d-lg-none m-0">
Description:
</p>
<p>
Whether or not to handle form submit ( AJAX or default )<br />
If set to false, you will have to handle form submit by yourself.
</p>
</div>
</div>
<div class="clearfix padding-tb-md row-list-separator d-flex flex-wrap">
<div class="col-lg-auto col-xl-3">
<pre class="text-green">nestedMultipartDataToJSON</pre>
<p>( boolean )</p>
</div>
<div class="w-100 d-xl-none"></div>
<div class="col-lg-6 col-xl-5">
</div>
<div class="col-lg-6 col-xl-4">
<p class="d-lg-none m-0">
Description:
</p>
<p>
Whether or not to allow, for FormData objects ( for mulitpart forms ), transformation of nested objects into JSON string.<br />
See comment in JS section of demo <a href="./demos/demo-get-form-data-complex.html">Get Form Data ( Complex Structure )</a> for details. Same rules apply to basic structure creation.
</p>
</div>
</div>
<div class="clearfix padding-tb-md row-list-separator d-flex flex-wrap">
<div class="col-lg-auto col-xl-3">
<pre class="text-green">onInitCheckFilled</pre>
<p>( boolean )</p>
</div>
<div class="w-100 d-xl-none"></div>
<div class="col-lg-6 col-xl-5">
</div>
<div class="col-lg-6 col-xl-4">
<p class="d-lg-none m-0">
Description:
</p>
<p>
Whether or not to validate filled fields on initialization.<br />
See event <code>fjs.form:init</code> in section <a href="#builtin-events">Built-in Events</a>.
</p>
</div>
</div>
</div>
<div class="card-footer no-bg">
<div class="mt-3">
<p>
Default form options:
</p>
<pre>
<code class="language-js">{
ajaxOptions: {
cache: 'no-store',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
method: 'POST',
mode: 'same-origin',
redirect: 'follow',
timeout: 0,
url: location.href
},
ajaxSubmit: true,
beforeSend: [],
cssClasses: {
ajaxComplete: 'ajax-complete',
ajaxError: 'ajax-error',
ajaxPending: 'ajax-pending',
ajaxSuccess: 'ajax-success',
error: 'form-error',
pending: 'form-pending',
submit: 'is-submitting',
valid: 'is-valid'
},
getFormData: getFormDataDefault,
groups: [],
handleFileUpload: true,
handleSubmit: true,
nestedMultipartDataToJSON: true,
onInitCheckFilled: true
}
</code></pre>
</div>
</div>
</div>
</div>
</div>
<!-- Methods -->
<div id="methods">
<h3 class="sticky-title">Methods</h3>
<div class="panel panel-default panel-transparent no-bg mt-5">
<div class="sticky-header card-header bg-white text-dark clearfix d-none d-lg-block">
<div class="d-flex">
<div class="col-lg-7 col-xl-4">
name<span class="d-inline d-xl-none">, description & parameters</span>
</div>
<div class="col-xl-5 d-none d-xl-block">
description & parameters
</div>
<div class="col-lg-5 col-xl-3">
return value
</div>
</div>
</div>
<div class="card-body">
<div class="">
<div class="clearfix padding-tb-md row-list-separator d-flex flex-wrap">
<div class="col-lg-auto col-xl-4">
<pre class="text-green">destroy()</pre>
<span class="badge badge-pill badge-yellow">Lite</span>
</div>
<div class="w-100 d-xl-none"></div>
<div class="col-lg-7 col-xl-5">
<p class="d-lg-none m-0">
Description:
</p>
<p>
This method will:
</p>
<ul>
<li>
Remove all events listeners from the form instance
</li>
<li>
<span class="badge badge-pill badge-yellow">Lite</span>
Remove the form instance attached to the form element
</li>
</ul>
</div>
<div class="col-lg-5 col-xl-3">
</div>
</div>
<div class="clearfix padding-tb-md row-list-separator d-flex flex-wrap">
<div class="col-lg-auto col-xl-4">
<pre class="text-green">getFormData( [trimValues] )</pre>
</div>
<div class="w-100 d-xl-none"></div>
<div class="col-lg-7 col-xl-5">
<p class="d-lg-none m-0">
Description:
</p>
<p>
Get a JS object of the form data with all user answers.
<br />
Collected data depends on the field as follow:
</p>
<ul>
<li>
checkbox ( single ): boolean
</li>
<li>
checkbox / select ( multiple ): array of strings
</li>
<li>
radio: value set or null
</li>
<li>
others: set / given value
</li>
</ul>
<hr />
<p>
Default function supports 2 ways of creating data object:
</p>
<ul>
<li>
Use field name attribute as object key ( see example in the next column )
</li>
<li>
Use dot-notation-like way to create a nested/complex data structure ( see <a href="./demos/demo-get-form-data-complex.html">demo</a> )
</li>
</ul>
<hr />
<p>
The function set in options.formOptions.getFormData will be used to collect data.<br />
See <a href="#form-options">Form Options Section</a> for details.
</p>
<p>
Attribute <code>data-exclude-data</code> can be used to avoid the plugin to take in consideration the field when collecting form data.
</p>
<p>
Additionally, the keyword <code>this</code> is bound to the Form instance.
</p>
<hr />
<p class="d-lg-none m-0">
Parameters:
</p>
<ul>
<li>
<span class="text-green">trimValues</span>: ( Optional ) boolean indicating whether or not to trim field values when collecting data ( by default it takes the value from <code>fieldOptions.trimValue</code> - values from selects, checkboxes, radios and file inputs are not trimmed )
</li>
</ul>
</div>
<div class="col-lg-5 col-xl-3">
<p class="d-lg-none m-0">
Return value:
</p>
<p>
For simple structure, an object like:
</p>
<pre>
<code class="language-js">{
name: 'Valerio',
city: 'Milan',
website:'http://www.valeriodipunzio.com'
}</code></pre>
<p>
For complex structure, see <a href="./demos/demo-get-form-data-complex.html">demo</a>
</p>
</div>
</div>
<div class="clearfix padding-tb-md row-list-separator d-flex flex-wrap">
<div class="col-lg-auto col-xl-4">
<pre class="text-green">validateField( field[, fieldOptions] )</pre>
<span class="badge badge-pill badge-yellow">Lite</span>
</div>
<div class="w-100 d-xl-none"></div>
<div class="col-lg-7 col-xl-5">
<p class="d-lg-none m-0">