-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathform.html.eco
More file actions
2206 lines (2141 loc) · 74.8 KB
/
form.html.eco
File metadata and controls
2206 lines (2141 loc) · 74.8 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
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
---
layout : 'default'
css : 'form'
standalone : true
element : 'validation'
elementType : 'behavior'
title : 'Form Validation'
description : 'A form validation behavior checks data against a set of criteria before passing it along to the server'
type : 'UI Behavior'
---
<script src="/dist/components/form.js"></script>
<script src="/javascript/validate-form.js"></script>
<%- @partial('header', { tabs: { usage: 'Usage', examples: 'Examples', settings: 'Settings'} }) %>
<div class="main ui container">
<div class="ui active tab" data-tab="usage">
<h2 class="ui dividing header">Usage</h2>
<div class="auto example">
<h4 class="ui header">Specifying Validation Rules</h4>
<p>Form validation requires passing in a validation object with the rules required to validate your form.</p>
<div class="ui ignored info message">
A validation object includes a list of form elements, and rules to validate each field against. Fields are matched by either the <code>id</code>, <code>name</code>, or <code>data-validate</code> property (in that order) matching the identifier specified in the settings object. Validation objects must use either shorthand or longhand exclusively.
</div>
<div class="ignore code" data-title="Shorthand Validation">
$('.ui.form')
.form({
fields: {
name : 'empty',
gender : 'empty',
username : 'empty',
password : ['minLength[6]', 'empty'],
skills : ['minCount[2]', 'empty'],
terms : 'checked'
}
})
;
</div>
<div class="ui horizontal divider">or</div>
<div class="ignore code" data-title="Full Validation Settings">
$('.ui.form')
.form({
fields: {
name: {
identifier: 'name',
rules: [
{
type : 'empty',
prompt : 'Please enter your name'
}
]
},
skills: {
identifier: 'skills',
rules: [
{
type : 'minCount[2]',
prompt : 'Please select at least two skills'
}
]
},
gender: {
identifier: 'gender',
rules: [
{
type : 'empty',
prompt : 'Please select a gender'
}
]
},
username: {
identifier: 'username',
rules: [
{
type : 'empty',
prompt : 'Please enter a username'
}
]
},
password: {
identifier: 'password',
rules: [
{
type : 'empty',
prompt : 'Please enter a password'
},
{
type : 'minLength[6]',
prompt : 'Your password must be at least {ruleValue} characters'
}
]
},
terms: {
identifier: 'terms',
rules: [
{
type : 'checked',
prompt : 'You must agree to the terms and conditions'
}
]
}
}
})
;
</div>
<form class="ui form segment">
<p>Tell Us About Yourself</p>
<div class="two fields">
<div class="field">
<label>Name</label>
<input placeholder="First Name" name="name" type="text">
</div>
<div class="field">
<label>Gender</label>
<select class="ui dropdown" name="gender">
<option value="">Gender</option>
<option value="female">Female</option>
<option value="male">Male</option>
<option value="non-binary">Non-binary</option>
<option value="not-listed">None of the above</option>
</select>
</div>
</div>
<div class="two fields">
<div class="field">
<label>Username</label>
<input placeholder="Username" name="username" type="text">
</div>
<div class="field">
<label>Password</label>
<input type="password" name="password">
</div>
</div>
<div class="field">
<label>Skills</label>
<select name="skills" multiple class="ui dropdown">
<option value="">Select Skills</option>
<option value="css">CSS</option>
<option value="html">HTML</option>
<option value="javascript">Javascript</option>
<option value="design">Graphic Design</option>
<option value="plumbing">Plumbing</option>
<option value="mech">Mechanical Engineering</option>
<option value="repair">Kitchen Repair</option>
</select>
</div>
<div class="inline field">
<div class="ui checkbox">
<input type="checkbox" name="terms" />
<label>I agree to the terms and conditions</label>
</div>
</div>
<div class="ui primary submit button">Submit</div>
<div class="ui error message"></div>
</div>
</form>
<div class="color example">
<h4 class="ui header">Passing Parameters to Rules <div class="ui horizontal teal label">New in 2.2.3</div></h4>
<p>Typically rules that include a parameter are written <code>minLength[2]</code> with the value being passed in as brackets.</p>
<p>If passing in properties as a string is not ideal, or if you are pulling values from another javascript variable, it might make sense to consider using <code>value</code> to pass in the rule value.</p>
<div class="ignored code">
$('.ui.form').form({
fields: {
color: {
identifier: 'color',
rules: [{
type: 'regExp',
value: /rgb\((\d{1,3}), (\d{1,3}), (\d{1,3})\)/i,
}]
}
}
});
</div>
<form class="ui form segment">
<div class="field">
<label>Color</label>
<input placeholder="Enter rgb" name="color" type="text" value="rgb(255, 255, 255)">
</div>
<div class="ui primary submit button">Submit</div>
</form>
</div>
<div class="prompt example">
<h4 class="ui header">Customizing Prompts</h4>
<p>Form validation includes default error prompts for most cases, however these can be quite generic. To specify custom personalized values for a validation prompt use the <code>prompt</code> property with a rule.</p>
<div class="ui ignored info message">Starting in <div class="ui teal label">2.3.1</div> you can specify prompts as a function. This may be useful when returning validation for fields that require dynamic validation messages.</div>
<div class="ui ignored info message">You can set default messages for each validation rule type by modifying <code>$fn.form.settings.prompt</code></div>
<p>Prompt also supports custom templating with the following values replaced</p>
<table class="ui celled sortable basic table segment">
<tbody>
<tr>
<td class="four wide"><b>{name}</b></td>
<td>The current text of a field's label, or if no label available its placeholder text</td>
</tr>
<tr>
<td class="four wide"><b>{identifier}</b></td>
<td>The identifier used to match the field</td>
</tr>
<tr>
<td class="four wide"><b>{value}</b></td>
<td>The current field value</td>
</tr>
<tr>
<td class="four wide"><b>{ruleValue}</b></td>
<td>The value passed to a rule, for example <code>minLength[100]</code> would set this value to 100</td>
</tr>
</tbody>
</table>
<div class="ignored code">
$('.ui.form')
.form({
fields: {
field1: {
rules: [
{
type : 'empty'
}
]
},
field2: {
rules: [
{
type : 'exactly[dog]',
prompt : '{name} is set to "{value}" that is totally wrong. It should be {ruleValue}'
}
]
},
field3: {
rules: [
{
type : 'exactly[cat]',
prompt : function(value) {
if(value == 'dog') {
return 'I told you to put cat, not dog!';
}
return 'That is not cat';
}
}
]
},
}
})
;
</div>
<form class="ui form segment">
<div class="two fields">
<div class="field">
<label>Field 1</label>
<input type="text" name="field1">
</div>
<div class="field">
<label>Field 2</label>
<input type="text" name="field2">
</div>
<div class="field">
<label>Field 3</label>
<input type="text" name="field3">
</div>
</div>
<div class="ui primary submit button">Submit</div>
<div class="ui error message">
</div>
</form>
</div>
<div class="matching example">
<h4 class="ui header">Matching Fields</h4>
<p>By default the property name used in the validation object will match against the <code>id</code>, <code>name</code>, or <code>data-validate</code> property of each input to find the corresponding field to match validation rules against.</p>
<p>If you need to specify a different identifier you can use the <code>identifier</code> property on each validation rule</p>
<div class="ignored code">
$('.ui.form')
.form({
fields: {
name: {
identifier : 'special-name',
rules: [
{
type : 'empty'
}
]
}
}
})
;
</div>
<form class="ui form segment">
<div class="field">
<label>Special Field</label>
<input type="text" name="special-name">
</div>
<div class="ui primary submit button">Submit</div>
<div class="ui error message">
</div>
</form>
</div>
<div class="prompt example">
<h4 class="ui header">
Validating Programmatically
<div class="ui teal label">Updated in 2.2.8</div>
</h4>
<p>Form validation provides additional behaviors to programmatically trigger validation for either the form or an individual field, and check validation on the form or individual fields.</p>
<p>Please see the <a href="#behaviors">behaviors section</a> for an explanation on syntax.</p>
<table class="ui celled sortable basic table segment">
<tbody>
<tr>
<td class="four wide"><b>validate form</b></td>
<td>Validates entire form and displays errors if necessary</td>
</tr>
<tr>
<td class="four wide"><b>is valid</b></td>
<td>Returns whether a form is valid</td>
</tr>
<tr>
<td class="four wide"><b>is valid(fieldName)</b></td>
<td>Returns whether a field in a form is valid (does not update UI)</td>
</tr>
<tr>
<td class="four wide"><b>validate field(fieldName)</b></td>
<td>Validates a particular field and displays errors if necessary</td>
</tr>
</tbody>
</table>
<div class="ignored code">
$('.ui.form')
.form({
fields: {
email: 'empty',
name: 'empty'
}
})
;
if( $('.ui.form').form('is valid', 'email')) {
// email is valid
}
if( $('.ui.form').form('is valid')) {
// form is valid (both email and name)
}
</div>
</div>
<h2 class="ui dividing header">Rules</h2>
<div class="no example">
<h4 class="ui header">
Validation Rules
</h4>
<p>Validation rules are a set of conditions required to validate a field</p>
<div class="ui info message">Validation rules are found in <code>$.fn.form.settings.rules</code>, to add new global validation rules, modify <code>$.fn.form.settings.rules</code> to include your function.</div>
<div class="in red message">To pass parameters to a rule, use bracket notation in your settings object. For example <code>type: 'not[dog]'</code></div>
<h3 class="ui header"><a href="#empty">Empty</a></h3>
<table class="ui celled sortable basic table segment">
<tbody>
<tr>
<td class="four wide">empty</td>
<td class="twelve wide">A field is empty</td>
</tr>
<tr>
<td>checked</td>
<td>A checkbox field is checked</td>
</tr>
</tbody>
</table>
<h3 class="ui header"><a href="#content-type">Content Type</h3>
<table class="ui celled sortable basic table segment">
<tbody>
<tr>
<td class="four wide">email</td>
<td>A field is a valid email address</td>
<td class="six wide"></td>
</tr>
<tr>
<td>url</td>
<td>A field is a url</td>
<td></td>
</tr>
<tr>
<td>integer</td>
<td>A field is an integer value, or matches an integer range</td>
<td><code>integer</code> or <code>integer[1..10]</code></td>
</tr>
<tr>
<td>decimal</td>
<td>A field must be a decimal number</td>
<td></td>
</tr>
<tr>
<td>number</td>
<td>A field is any number decimal or non-decimal</td>
<td></td>
</tr>
<tr>
<td>regExp[expression]</td>
<td>Matches against a regular expression, when using bracketed notation RegExp values must be escaped.</td>
<td>
<code>regExp[/^[a-z0-9_-]{3,16}$/gi]]</code>
<div class="ui horizontal divider">Or</div>
<code>regExp[/^[a-z0-9_-]{3,16}$/]]</code>
</td>
</tr>
</tbody>
</table>
<h3 class="ui header"><a href="#payment">Payment</a></h3>
<table class="ui celled sortable basic table segment">
<tbody>
<tr>
<td class="four wide">creditCard</td>
<td class="six wide">A field is a valid credit card</td>
<td><code>creditCard</code></td>
</tr>
<tr>
<td>creditCard[types]</td>
<td>A field matches a specified array of card types</td>
<td><code>creditCard[visa,mastercard,unionpay]</code></td>
</tr>
</tbody>
</table>
<h3 class="ui header"><a href="#specified-content">Specified Content</a></h3>
<table class="ui celled sortable basic table segment">
<tbody>
<tr>
<td class="four wide">contains</td>
<td>A field contains text (case insensitive)</td>
<td class="six wide"><code>contains[foo]</code></td>
</tr>
<tr>
<td>containsExactly</td>
<td>A field contains text (case sensitive)</td>
<td><code>containsExactly[foo]</code></td>
</tr>
<tr>
<td>doesntContain</td>
<td>A field doesn't contain text (case insensitive)</td>
<td><code>doesntContain[foo]</code></td>
</tr>
<tr>
<td>doesntContainExactly</td>
<td>A field doesn't contain text (case sensitive)</td>
<td><code>doesntContainExactly[foo]</code></td>
</tr>
<tr>
<td>is</td>
<td>A field is a value (case insensitive)</td>
<td><code>is[foo]</code></td>
</tr>
<tr>
<td>isExactly</td>
<td>A field is a value (case-sensitive)</td>
<td><code>isExactly[foo]</code></td>
</tr>
<tr>
<td>not</td>
<td>A field is not a value (case insensitive)</td>
<td><code>not[foo]</code></td>
</tr>
<tr>
<td>notExactly</td>
<td>A field is not a value (case sensitive)</td>
<td><code>notExactly[foo]</code></td>
</tr>
</tbody>
</table>
<h3 class="ui header"><a href="#length">Length</a></h3>
<table class="ui celled sortable basic table segment">
<tbody>
<tr>
<td class="four wide">minLength</td>
<td>A field is less than a min length</td>
<td class="six wide"><code>minLength[5]</code></td>
</tr>
<tr>
<td>exactLength</td>
<td>A field is exactly length</td>
<td><code>exactLength[16]</code></td>
</tr>
<tr>
<td>maxLength</td>
<td>A field is less than a max length</td>
<td><code>maxLength[50]</code></td>
</tr>
</tbody>
</table>
<h3 class="ui header"><a href="#matching-fields">Matching Fields</a></h3>
<table class="ui celled sortable basic table segment">
<tbody>
<tr>
<td class="four wide">match</td>
<td class="six wide">A field should match the value of another validation field, for example to confirm passwords</td>
<td><code>match[password]</code></td>
</tr>
<tr>
<td>different</td>
<td>A field should be different than another specified field</td>
<td><code>different[choice]</code></td>
</tr>
</tbody>
</table>
<h3 class="ui header"><a href="#selection-count">Selection Count</a></h3>
<table class="ui celled sortable basic table segment">
<tbody>
<tr>
<td class="four wide">minCount</td>
<td>A multiple select field contains at minimum (count) selections</td>
<td class="six wide"><code>minCount[count]</code></td>
</tr>
<tr>
<td>exactCount</td>
<td>A multiple select field contains exactly (count) selections</td>
<td><code>exactCount[count]</code></td>
</tr>
<tr>
<td>maxCount</td>
<td>A multiple select field contains at maximum (count) selections</td>
<td><code>maxCount[count]</code></td>
</tr>
</tbody>
</table>
</div>
<div class="custom rule example">
<h4 class="ui header">Adding Custom Rules</h4>
<p>You can extend form validation to include your own rules. Keep in mind these will need to be executed synchronously.</p>
<div class="ignore code">
// some arbitrary business-logic
window.user = {
name : 'Simon',
adminLevel : 1
};
// custom form validation rule
$.fn.form.settings.rules.adminLevel = function(value, adminLevel) {
return (window.user.adminLevel >= adminLevel)
};
$('.ui.form')
.form({
fields: {
dog: {
identifier: 'dog',
rules: [
{
type: 'adminLevel[2]',
prompt: 'You must be at least a level-2 admin to add a dog'
}
]
}
}
})
;
</div>
<form class="ui form segment">
<p>Let's go ahead and get you signed up.</p>
<div class="field">
<label>Dog</label>
<input placeholder="Dog" name="dog" type="text">
</div>
<div class="ui primary submit button">
<i class="add icon"></i>
Add Dog
</div>
<div class="ui error message"></div>
</form>
</div>
<div class="inline example">
<h4 class="ui header">Built-in Events</h4>
<p>
Form will automatically attach events to specially labeled form fields
</p>
<ul class="ui list">
<li>Fields will blur on <code>escape</code> key press</li>
<li>Fields will submit form on <code>enter</code></li>
<li>Submit events will be attached to <code>click</code> on any element inside the form with class <code>submit</code></li>
<li>Reset events will be attached to <code>click</code> on any element inside the form with class <code>reset</code></li>
<li>Clear events will be attached to <code>click</code> on any element inside the form with class <code>clear</code></li>
</ul>
<form class="ui form segment">
<div class="field">
<label>Test Field</label>
<input placeholder="Test Field" name="name" type="text">
</div>
<div class="ui primary submit button">Submit</div>
<div class="ui reset button">Reset</div>
<div class="ui clear button">Clear</div>
</form>
</div>
<h2 class="ui dividing header">Manipulating Forms</h2>
<div class="inline example">
<h4 class="ui header">Reset / Clear Fields</h4>
<p>
Calling <code>$('form').form('reset')</code>, or clicking any reset element will return all form values to their <em>default value</em>. This is the value the form fields were set to when the page loaded.
</p>
<p>Calling <code>$('form').form('clear')</code> will remove all values from form fields and reset dropdowns to placeholder text</p>
<div class="ui ignored warning message">
Form <code>reset</code> works by caching default values on page load. For this to work correctly any form that uses reset will need to initialize on page load.
</div>
<div class="ui ignored info message">
Reset and clear will modify all form fields, not just those which have validation rules
</div>
<form class="ui form segment">
<div class="two fields">
<div class="field">
<label>Name</label>
<input placeholder="First Name" name="name" type="text">
</div>
<div class="field">
<label>Gender</label>
<div class="ui selection dropdown">
<input name="gender" type="hidden">
<div class="default text">Gender</div>
<i class="dropdown icon"></i>
<div class="menu">
<div class="item" data-value="female">Female</div>
<div class="item" data-value="male">Male</div>
<div class="item" data-value="non-binary">Non-binary</div>
<div class="item" data-value="not-listed">None of the above</div>
</div>
</div>
</div>
</div>
<div class="field">
<label>Username</label>
<input placeholder="Username" name="username" type="text">
</div>
<div class="field">
<label>Password</label>
<input name="password" type="password">
</div>
<div class="inline field">
<div class="ui checkbox">
<input name="terms" type="checkbox">
<label>I agree to the terms and conditions</label>
</div>
</div>
<div class="ui primary submit button">Submit</div>
<div class="ui reset button">Reset</div>
<div class="ui clear button">Clear</div>
</form>
</div>
<div class="writing no example">
<h4 class="ui header">Writing Values</h4>
<p>
Form includes behaviors for reading from and writing to form fields.
</p>
<div class="code" data-demo="true">
$('.writing.example form')
// set one value
.form('set value', 'name', 'Jack')
// set several values
.form('set values', {
name : 'Jack',
gender : 'male',
colors : ['red', 'grey'],
username : 'jlukic',
password : 'youdliketoknow',
terms : true
})
;
</div>
<form class="ui form segment">
<div class="two fields">
<div class="field">
<label>Name</label>
<input placeholder="First Name" name="name" type="text">
</div>
<div class="field">
<label>Gender</label>
<div class="ui selection dropdown">
<input name="gender" type="hidden">
<div class="default text">Gender</div>
<i class="dropdown icon"></i>
<div class="menu">
<div class="item" data-value="female">Female</div>
<div class="item" data-value="male">Male</div>
<div class="item" data-value="non-binary">Non-binary</div>
<div class="item" data-value="not-listed">None of the above</div>
</div>
</div>
</div>
</div>
<div class="field">
<label>Username</label>
<input placeholder="Username" name="username" type="text">
</div>
<div class="field">
<label>Password</label>
<input name="password" type="password">
</div>
<div class="inline fields">
<label for="colors">Favorite Colors</label>
<div class="field">
<div class="ui checkbox">
<input type="checkbox" name="colors[]" value="red" />
<label>Red</label>
</div>
</div>
<div class="field">
<div class="ui checkbox">
<input type="checkbox" name="colors[]" value="blue" />
<label>Blue</label>
</div>
</div>
<div class="field">
<div class="ui checkbox">
<input type="checkbox" name="colors[]" value="green" />
<label>Green</label>
</div>
</div>
<div class="field">
<div class="ui checkbox">
<input type="checkbox" name="colors[]" value="grey" />
<label>Grey</label>
</div>
</div>
</div>
<div class="inline field">
<div class="ui checkbox">
<input name="terms" type="checkbox">
<label>I agree to the terms and conditions</label>
</div>
</div>
<div class="ui primary submit button">Submit</div>
<div class="ui clear button">Clear</div>
</form>
</div>
<div class="get no example">
<h4 class="ui header">Getting Values</h4>
<p>
You can also read values from form fields using <code>get value</code> and <code>get values</code>
</p>
<div class="ui ignored info message">
Although <code>get values</code> allows you to use any matching identifier, returned values will always use the corresponding <code>name</code> attribute of the element.
</div>
<div class="code" data-demo="true">
var
$form = $('.get.example form'),
// get one value
colors = $form.form('get value', 'colors'),
// get list of values
fields = $form.form('get values', ['name', 'colors']),
// get all values
allFields = $form.form('get values')
;
console.log(colors);
console.log(fields);
console.log(allFields);
</div>
<form class="ui form segment">
<div class="two fields">
<div class="field">
<label>Name</label>
<input placeholder="First Name" name="name" type="text">
</div>
<div class="field">
<label>Gender</label>
<div class="ui selection dropdown">
<input name="gender" type="hidden">
<div class="default text">Gender</div>
<i class="dropdown icon"></i>
<div class="menu">
<div class="item" data-value="female">Female</div>
<div class="item" data-value="male">Male</div>
<div class="item" data-value="non-binary">Non-binary</div>
<div class="item" data-value="not-listed">None of the above</div>
</div>
</div>
</div>
</div>
<div class="field">
<label>Username</label>
<input placeholder="Username" name="username" type="text">
</div>
<div class="field">
<label>Password</label>
<input name="password" type="password">
</div>
<div class="inline fields">
<label for="colors">Favorite Colors</label>
<div class="field">
<div class="ui checkbox">
<input type="checkbox" name="colors[]" value="red" />
<label>Red</label>
</div>
</div>
<div class="field">
<div class="ui checkbox">
<input type="checkbox" name="colors[]" value="blue" />
<label>Blue</label>
</div>
</div>
<div class="field">
<div class="ui checkbox">
<input type="checkbox" name="colors[]" value="green" />
<label>Green</label>
</div>
</div>
<div class="field">
<div class="ui checkbox">
<input type="checkbox" name="colors[]" value="grey" />
<label>Grey</label>
</div>
</div>
</div>
<div class="inline field">
<div class="ui checkbox">
<input name="terms" type="checkbox">
<label>I agree to the terms and conditions</label>
</div>
</div>
<div class="ui primary submit button">Submit</div>
</form>
</div>
</div>
<div class="ui tab" data-tab="examples">
<h2 class="ui dividing header">Rule Examples</h2>
<div class="field example">
<h4 class="ui header">Empty</h4>
<p>The following shows examples of validating different types of empty or unchecked content.</p>
<form class="ui form">
<div class="field">
<label>Empty</label>
<input name="empty" type="text">
</div>
<div class="field">
<label>Dropdown</label>
<select class="ui dropdown" name="dropdown">
<option value="">Select</option>
<option value="1">Choice 1</option>
<option value="2">Choice 2</option>
</select>
</div>
<div class="inline field">
<div class="ui checkbox">
<input type="checkbox" name="checkbox" />
<label>Checkbox</label>
</div>
</div>
<div class="ui submit button">Submit</div>
<div class="ui error message"></div>
</form>
<div class="evaluated code">
$('.field.example form')
.form({
on: 'blur',
fields: {
empty: {
identifier : 'empty',
rules: [
{
type : 'empty',
prompt : 'Please enter a value'
}
]
},
dropdown: {
identifier : 'dropdown',
rules: [
{
type : 'empty',
prompt : 'Please select a dropdown value'
}
]
},
checkbox: {
identifier : 'checkbox',
rules: [
{
type : 'checked',
prompt : 'Please check the checkbox'
}
]
}
}
})
;
</div>
</div>
<div class="type example">
<h4 class="ui header">Content Type</h4>
<p>Inputs can match against common content types, or your own custom <a href="http://www.regular-expressions.info/" target="_blank">regular expressions</a>.</p>
<form class="ui form">
<div class="two fields">
<div class="field">
<label>Integer</label>
<input name="integer" type="text" value="101">
</div>
<div class="field">
<label>E-mail</label>
<input name="email" type="text" value="jack">
</div>
</div>
<div class="two fields">
<div class="field">
<label>Decimal</label>
<input name="decimal" type="text" value="1.1.1">
</div>
<div class="field">
<label>Number</label>
<input name="number" type="text" value="+200">
</div>
</div>
<div class="two fields">
<div class="field">
<label>URL</label>
<input name="url" type="text" value="ww.fakeurl.com">
</div>
<div class="field">
<label>RegEx</label>
<input name="regex" type="text" value="joe">
</div>
</div>
<div class="ui submit button">Submit</div>
<div class="ui error message"></div>
</form>
<div class="evaluated code">
$('.type.example form')
.form({
on: 'blur',
fields: {
integer: {
identifier : 'integer',
rules: [
{
type : 'integer[1..100]',
prompt : 'Please enter an integer value'
}
]
},
decimal: {
identifier : 'decimal',
rules: [
{
type : 'decimal',
prompt : 'Please enter a valid decimal'
}
]
},
number: {
identifier : 'number',
rules: [
{
type : 'number',
prompt : 'Please enter a valid number'
}
]
},
email: {
identifier : 'email',
rules: [
{
type : 'email',
prompt : 'Please enter a valid e-mail'
}
]
},
url: {
identifier : 'url',
rules: [
{
type : 'url',
prompt : 'Please enter a url'
}
]
},
regex: {
identifier : 'regex',
rules: [
{
type : 'regExp[/^[a-z0-9_-]{4,16}$/]',
prompt : 'Please enter a 4-16 letter username'
}
]
}
}
})
;
</div>