Repository navigation
Expand file tree
/
Copy pathformform_demo.html
More file actions
557 lines (508 loc) · 11.8 KB
/
Copy pathformform_demo.html
File metadata and controls
557 lines (508 loc) · 11.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>FormForm2 demo</title>
<!-- Bootstrap core CSS -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet">
<!-- Bootstrap core JS dependencies -->
<script src="https://code.jquery.com/jquery-1.12.3.min.js" integrity="sha256-aaODHAgvwQW1bFOGXMeX+pC4PZIPsvn2h1sArYOhgXQ=" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<!-- Bootstrap FormForm -->
<script src="bootstrap-formform.js"></script>
<script>
$(document).on('change', '.btn-file :file', function() {
var input = $(this);
var filename = input.val().replace(/\\/g, '/').replace(/.*\//, '');
input.trigger( 'fileselect', [filename] );
} );
$(document).ready( function() {
input = [
{
"name": "username",
"label": "With placeholder and unspecified type",
"placeholder": "This is a placeholder"
},
{
"type": "button",
"label": "Button dropdown",
"dropdown":
{
"id_one": "Dropdown option 1",
"id_two": "Dropdown option 2",
"id_three": "Dropdown option 3"
}
},
{
"type": "text",
"name": "withaddon",
"label": "With left-hand button addon of class 'btn-warning'",
"addons":
[
{
"type": "button",
"classes": "btn-warning",
"label": "OK",
"icon": "ok"
}
]
},
{
"type": "text",
"name": "withaddon2",
"label": "With left-hand button dropdown addon",
"addons":
[
{
"type": "button",
"label": "Choose...",
"dropdown":
{
"id_one12": "Addon dropdown 1",
"id_two12": "Addon dropdown 2",
"id_three12": "Addon dropdown 3"
}
}
]
},
{
"type": "text",
"name": "withaddon3",
"label": "With right-hand button and dropdown addon",
"help-block": "Help-block: note that the alignment of the dropdown itself is adjusted",
"addons":
[
{
"type": "button",
"position": "right",
"label": "OK",
},
{
"type": "button",
"position": "right",
"label": "",
"dropdown":
{
"id_one1": "Addon dropdown 1",
"id_two1": "Addon dropdown 2",
"id_three1": "Addon dropdown 3"
}
}
]
},
{
"type": "checkboxgroup",
"label": "A checkbox group",
"options":
[
{
"name": "checkbox1",
"label": "Option 1",
"value": 1,
"checked": 1
},
{
"name": "checkbox2",
"label": "Option 2",
"value": 1
}
]
},
{
"type": "radiogroup",
"name": "radiogrp",
"value": "no",
"label": "A radiobutton group (with ‘additions’, an experimental feature)",
"options":
{
"no": "No, option 1, with 1 additional field",
"yes": "Yes, option 2, with 2 additional fields"
}
},
{
"type": "text",
"name": "addition1",
"id": "addition1",
"classes": "addition",
"data": {"for": "radiogrp_no"},
"label": "What is the cause of this?",
"value": ""
},
{
"type": "text",
"name": "addition2",
"id": "addition2",
"classes": "addition",
"data": {"for": "radiogrp_yes"},
"label": "How many times in the past six months?",
"value": ""
},
{
"type": "text",
"name": "addition3",
"id": "addition3",
"classes": "addition",
"data": {"for": "radiogrp_yes"},
"label": "Who is responsible for this?",
"value": ""
},
{
"type": "text",
"name": "withValue",
"label": "With value and error",
"value": "This is a value with <unsafe> \"characters\" & such",
"error": "This is the error message"
},
{
"type": "password",
"name": "password",
"label": "Password label with <unsafe> \"characters\""
},
{
"type": "textarea",
"name": "my_textarea",
"label": "A textarea with placeholder and value",
"value": "Remove this text to see the placeholder",
"placeholder": "This is a placeholder"
},
{
"type": "file",
"name": "file_upload",
"label": "A file input",
"btnlabel": "Choose a file...",
"icon": "file",
"classes": "btn-primary"
},
{
"type": "static",
"name": "static",
"label": "Bootstrap 'static' control",
"value": "This is static text"
},
{
"type": "select",
"name": "fruit",
"label": "Select input",
"value": "two",
"options":
{
"one": "Option 1",
"two": "This is the selected option",
"three": "Option 3"
}
},
{
"type": "button",
"label": "Button",
"classes": "btn-primary"
},
{
"type": "button",
"label": "Reset",
"classes": "btn-danger"
},
{
"type": "submit",
"label": "Submit",
"classes": "btn-success",
"icon": "search",
"id": "test_id",
"name": "test_name"
},
];
input2 = [
{
"name": "username2",
"label": "This is form 2",
"placeholder": "This is a placeholder"
},
{
"type": "password",
"name": "withaddon-password",
"label": "Password with right-hand button addon of class 'btn-success'",
"addons":
[
{
"type": "button",
"position": "right",
"classes": "btn-success",
"label": "Check",
"icon": "ok"
}
]
},
{
"type": "month",
"name": "withaddon-month",
"label": "Month with right-hand button addon of class 'btn-success'",
"addons":
[
{
"type": "button",
"position": "right",
"classes": "btn-success",
"label": "Check",
"icon": "ok"
}
]
},
{
"type": "time",
"name": "withaddon-time",
"label": "Time with right-hand button addon of class 'btn-success'",
"addons":
[
{
"type": "button",
"position": "right",
"classes": "btn-success",
"label": "Check",
"icon": "ok"
}
]
},
{
"type": "week",
"name": "withaddon-week",
"label": "Week with right-hand button addon of class 'btn-success'",
"addons":
[
{
"type": "button",
"position": "right",
"classes": "btn-success",
"label": "Check",
"icon": "ok"
}
]
},
{
"type": "number",
"name": "withaddon-number",
"label": "Number with right-hand button addon of class 'btn-success'",
"addons":
[
{
"type": "button",
"position": "right",
"classes": "btn-success",
"label": "Check",
"icon": "ok"
}
]
},
{
"type": "email",
"name": "withaddon-email",
"label": "Email with right-hand button addon of class 'btn-success'",
"addons":
[
{
"type": "button",
"position": "right",
"classes": "btn-success",
"label": "Check",
"icon": "ok"
}
]
},
{
"type": "url",
"name": "withaddon-url",
"label": "Url with right-hand button addon of class 'btn-success'",
"addons":
[
{
"type": "button",
"position": "right",
"classes": "btn-success",
"label": "Check",
"icon": "ok"
}
]
},
{
"type": "search",
"name": "withaddon-search",
"label": "Search with right-hand button addon of class 'btn-success'",
"addons":
[
{
"type": "button",
"position": "right",
"classes": "btn-success",
"label": "Check",
"icon": "ok"
}
]
},
{
"type": "tel",
"name": "withaddon-tel",
"label": "Tel with right-hand button addon of class 'btn-success'",
"addons":
[
{
"type": "button",
"position": "right",
"classes": "btn-success",
"label": "Check",
"icon": "ok"
}
]
},
{
"type": "color",
"name": "withaddon-color",
"label": "Color with right-hand button addon of class 'btn-success'",
"addons":
[
{
"type": "button",
"position": "right",
"classes": "btn-success",
"label": "Check",
"icon": "ok"
}
]
},
{
"type": "date",
"name": "withaddon-date",
"label": "Date with right-hand button addon of class 'btn-success'",
"addons":
[
{
"type": "button",
"position": "right",
"classes": "btn-success",
"label": "Check",
"icon": "ok"
}
]
},
{
"type": "datetime-local",
"name": "withaddon-datetime-local",
"label": "Datetime-local with right-hand button addon of class 'btn-success'",
"addons":
[
{
"type": "button",
"position": "right",
"classes": "btn-success",
"label": "Check",
"icon": "ok"
}
]
},
{
"type": "datetime",
"name": "withaddon-datetime",
"label": "Datetime with right-hand button addon of class 'btn-success'",
"addons":
[
{
"type": "button",
"position": "right",
"classes": "btn-success",
"label": "Check",
"icon": "ok"
}
]
},
{
"type": "button",
"label": "Cancel",
"classes": "btn-default",
},
{
"type": "submit",
"label": "OK",
"position": "right",
"classes": "btn-primary",
"icon": "ok"
}
];
renderForm();
} );
var form_elem1 = null;
var form_elem2 = null;
function renderForm( orientation, addcol1 )
{
if ( ! form_elem1 ) form_elem1 = $('#testform');
if ( form_elem1.length )
{
form_elem1.empty();
if ( orientation == 'h' ) form_elem1.addClass( 'form-horizontal' );
else form_elem1.removeClass( 'form-horizontal' );
var col1 = Math.min( 9, Math.max( 2, parseInt( $( '#col1' ).text() ) ) );
if ( addcol1 )
{
col1 += addcol1;
$( '#col1' ).text( col1 );
}
// create a FormForm instance
var form = new FormForm( form_elem1, input );
// (optionally) set the column widths (for horizontal forms)
form.col1 = col1;
form.col2 = 12 - col1;
// render
form.render();
}
if ( ! form_elem2 ) form_elem2 = $('#testform2');
if ( form_elem2.length )
{
form_elem2.empty();
var form2 = new FormForm( form_elem2, input2 );
form2.render();
}
// add example code snippets
$.each( [input, input2], function(f, forminput){
$.each(forminput, function(i,item){
$('#'+item.name).closest('.form-group')
.append($('<pre class="examplecode hidden">')
.text(JSON.stringify(item, null, '\t')))
});
});
}
function toggleSnippets()
{
$('.examplecode').toggleClass('hidden');
return false;
}
</script>
<style>
.container {
padding: 20px 35px;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<label>Form layout: </label>
<button type="button" class="btn btn-default btn-sm" onclick="return renderForm('v')">Vertical <span class="glyphicon glyphicon-arrow-down"></span></button></form>
<button type="button" class="btn btn-default btn-sm" onclick="return renderForm('h')">Horizontal <span class="glyphicon glyphicon-arrow-right"></span></button></form>
<label>column 1 width: </label>
<button type="button" class="btn btn-default btn-sm" onclick="return renderForm('h', -1)"><span class="glyphicon glyphicon-triangle-left"></span></button></form>
<span id="col1">4</span>
<button type="button" class="btn btn-default btn-sm" onclick="return renderForm('h', 1)"><span class="glyphicon glyphicon-triangle-right"></span></button></form>
<button type="button" class="btn btn-default btn-sm" onclick="return toggleSnippets()"><span class="glyphicon glyphicon-eye-open"></span> toggle code snippets</button></form>
</div>
<hr>
<div class="row">
<h1>Bootstrap FormForm2 demo</h1>
<h3>Form 1</h3>
<form id="testform" action="#" method="post"></form>
<hr>
<h3>Form 2</h3>
<form id="testform2" action="#" method="post"></form>
</div>
</div>
</body>
</html>