-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
1112 lines (1058 loc) · 48.2 KB
/
index.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" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=1, initial-scale=1.0" />
<link rel="icon" type="image/png" sizes="32x32" href=" data:image/png;base64,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" />
<title>JS Form</title>
<style>
/* @font-face {
font-family: 'virtuous-slab';
src: url('css/fonts/PublicSans-Light.woff2') format('woff2');
border #444c56
cc
} */
@import url('https://fonts.googleapis.com/css2?family=Public+Sans:wght@300&display=swap');
:root {
--BodyBackground: whitesmoke;
--FieldsetLegend: black;
--FieldsetBorder: black;
--FieldsetShadow: black;
--FieldsetBackground: whitesmoke;
--LabelLarge: black;
--LabelTop: dimgrey;
--LabelTopBackground: whitesmoke;
--LabelBorderActive: black;
--LabelShadowActive: dimgrey;
--InputText: black;
--InputBackground: whitesmoke;
--InputBorder: black;
--InputShadow: black;
--InputShadowHover: dimgrey;
--InputShadowFocus: dimgrey;
--ListBoxBackground: whitesmoke;
--ScrollbarBackground: whitesmoke;
--ScrollbaThumb: dimgrey;
--ScrollbarCorner: blue;
--ListBoxLiChecked: darkgrey;
--ListBoxLiHover: lightgrey;
--CheckboxCheckedBackground: whitesmoke;
--CheckboxCheckedShadow: dimgrey;
--CheckboxCheckedInside: black;
}
[data-theme='dark'] {
--BodyBackground: #22272e;
--FieldsetLegend: #adbac7;
--FieldsetBorder: black;
--FieldsetShadow: black;
--FieldsetBackground: #1c2128;
--LabelLarge: #768390;
--LabelTop: #768390;
--LabelTopBackground: transparent;
--LabelBorderActive: #444c56;
--LabelShadowActive: black;
--InputText: #adbac7;
--InputBackground: #22272e;
--InputBorder: #444c56;
--InputBorder: black;
--InputShadow: black;
--InputShadowHover: black;
--InputShadowFocus: black;
--ListBoxBackground: #22272e;
--ScrollbarBackground: #22272e;
--ScrollbaThumb: #768390;
--ListBoxLiChecked: #1c2128;
--ListBoxLiHover: #1c2128;
--CheckboxCheckedBackground: #22272e;
--CheckboxCheckedShadow: black;
--CheckboxCheckedInside: black;
}
* {
-webkit-transition: color 100ms linear;
-ms-transition: color 100ms linear;
transition: color 100ms linear;
-webkit-transition: background-color 100ms linear;
-ms-transition: background-color 100ms linear;
transition: background-color 100ms linear;
}
* {
box-sizing: border-box;
}
body {
position: relative;
background: var(--BodyBackground);
margin: 2rem auto;
max-width: max-content;
padding: 1em;
margin: 2em auto;
}
#FORMVALUES {
opacity: 0;
-webkit-transition: 1.4s;
transition: opacity 0.3s linear;
}
#FORMVALUES fieldset {
font-family: 'Public Sans', sans-serif;
padding: 0em 1em;
margin: 20px;
max-width: max-content;
background: var(--FieldsetBackground);
border: 1px solid var(--FieldsetBorder);
box-shadow: 4px 4px 0 var(--FieldsetShadow);
-webkit-transition: 1.4s;
transition: opacity 0.3s linear;
}
pre {
font-family: 'JetBrains Mono', monospace;
font-size: 1em;
line-height: 2em;
color: #333;
}
fieldset.floatLabel {
padding: 1.5rem;
margin: 1em;
background: #fff;
min-width: 20rem;
max-width: 90vh;
background: var(--FieldsetBackground);
border: 1px solid var(--FieldsetBorder);
box-shadow: 4px 4px 0 var(--FieldsetShadow);
}
label {
white-space: nowrap;
}
.floatLabel legend {
position: relative;
/* top: -0.25em; */
color: var(--FieldsetLegend);
font-family: 'Public Sans', sans-serif;
font-size: 1.5em;
}
.floatLabel .inputGroup {
display: flex !important;
/* align-content: flex-start; */
flex-wrap: wrap;
margin-bottom: 0em !important;
}
.floatLabel .inputGroup > * {
max-width: max-content;
}
.inputGroup div {
margin-top: 0;
}
.inputGroup div:not(:last-child) {
margin-right: 1.5em;
}
.floatLabel {
font-size: 16px !important;
font-family: 'Public Sans', sans-serif !important;
}
.floatLabel .inputGroup,
.floatLabel .InputElement,
.floatLabel .TextareaElement,
.floatLabel .ListBox {
display: block;
width: 100%;
/* height:1.9em; */
position: relative;
margin-bottom: 1.5em;
}
.floatLabel label:not(li label) {
position: absolute;
left: 0;
top: 0.04em;
padding: 0.3em 0.5em 0.25em 0.5em;
pointer-events: none;
cursor: text;
font-size: 1em;
color: var(--LabelLarge);
-webkit-transition: 0.2s;
transition: 0.2s;
}
.floatLabel .isActive label,
.floatLabel label.isTop {
top: -1em;
left: 0.5em;
padding: 0.1em 0.1em;
background: var(--LabelTopBackground);
color: var(--LabelTop);
font-size: 0.8em;
z-index: 2;
-webkit-transition: 0.2s;
transition: 0.2s;
}
.floatLabel input[type='text']::placeholder,
.floatLabel input[type='select']::placeholder,
.floatLabel textarea::placeholder {
opacity: 0;
-webkit-transition: 0.4s;
transition: 0.2s;
}
.floatLabel .isActive input::placeholder,
.floatLabel .isActive textarea::placeholder {
opacity: 0.5;
-webkit-transition: 0.4s;
transition: 0.4s;
}
.floatLabelButton,
.floatLabel input[type='text'],
.floatLabel input[type='select'],
.floatLabel textarea {
font-size: 1em;
line-height: 1.3em;
/* padding: 0.25em 0.5em; */
/* padding: 0.4em 0.5em 0.1em 0.5em; */
padding: 0.35em 0.5em 0.2em 0.5em;
border: 0;
color: var(--InputText);
background: var(--InputBackground);
width: 100%;
outline: var(--InputBorder) solid 1px;
box-shadow: 4px 4px 0 var(--InputShadow);
-webkit-transition: 0.1s;
transition: 0.1s;
}
.floatLabel textarea:placeholder-shown {
height: 1.8em;
-webkit-transition: 0.2s;
transition: 0.2s;
}
.floatLabel textarea,
.floatLabel textarea:focus {
height: 15em;
-webkit-transition: 0.3s;
transition: 0.3s;
/* substract the outlines for the same height as input fields, just for CHROME & co */
-webkit-margin-after: -4px;
}
.floatLabelButton {
line-height: 1em !important;
width: 45% !important;
padding: 0.35em 0.5em 0.35em !important;
cursor: pointer;
}
.floatLabel select:hover,
.floatLabel input[type='text']:hover,
.floatLabel input[type='select']:hover,
.floatLabel textarea:hover,
.floatLabelButton:hover {
box-shadow: 4px 4px 0 var(--InputShadowHover);
-webkit-transition: 0.1s;
transition: 0.1s;
}
.floatLabel select:focus,
.floatLabel input[type='text']:focus,
.floatLabel .isActive input,
.floatLabel textarea:focus,
.floatLabelButton.submitButtonActive {
box-shadow: 2px 2px 0 var(--InputShadowFocus) !important;
transform: translate(2px, 2px);
-webkit-transition: 0.1s;
transition: 0.1s;
}
.floatLabel .ListBox ul {
position: absolute;
max-height: 0px;
overflow: hidden;
background: var(--ListBoxBackground);
width: 100%;
list-style: none;
padding: 0;
z-index: 5;
margin: 0;
-webkit-transition: 0.3s;
transition: 0.3s;
}
.floatLabel .ListBox.isActive ul {
max-height: 100px;
left: 2px;
/* FF */
top: calc(2em + 2px);
/* Chrome */
top: 2em;
overflow-y: scroll;
overflow-x: hidden;
scrollbar-width: thin;
z-index: 5;
outline: #000 solid 1px;
box-shadow: 2px 2px 0 var(--LabelShadowActive), -1px -1px 0px 0px var(--LabelBorderActive);
-webkit-transition: 0.3s;
transition: 0.3s;
}
.floatLabel .ListBox.isActive ul::-webkit-scrollbar {
height: 0px;
width: 5px;
background: var(--ScrollbarBackground);
}
.floatLabel .ListBox.isActive ul::-webkit-scrollbar-thumb {
background: var(--ScrollbaThumb);
/* -webkit-box-shadow: 0px 1px 2px #555; */
}
.floatLabel .ListBox.isActive ul::-webkit-scrollbar-corner {
background: var(--ScrollbarCorner);
}
.floatLabel .ListBox li input:checked ~ label {
background: var(--ListBoxLiChecked);
}
.floatLabel .ListBox li input:checked ~ label:hover,
.floatLabel .ListBox li label:hover {
background: var(--ListBoxLiHover);
cursor: pointer;
}
.floatLabel .ListBox li label {
display: inline-block;
padding: 0.25em 0.5em;
line-height: 1em;
font-size: 0.85em;
width: 100%;
color: var(--LabelLarge);
}
.floatLabel .InputCheckbox label {
position: relative;
left: 0;
top: 0;
padding: 0.3em 0.5em 0.25em 0.25em;
pointer-events: initial;
cursor: pointer;
font-size: 1em;
color: var(--LabelLarge);
-webkit-transition: 0.2s;
transition: 0.2s;
}
.floatLabel .InputCheckbox {
position: relative;
width: 100%;
height: 1.9em;
margin-bottom: 0.5em;
margin-top: -0.5em;
}
.floatLabel .InputCheckbox [type='checkbox'] {
position: relative;
left: 15px;
top: -4px;
z-index: 0;
-webkit-appearance: none;
}
.floatLabel .InputCheckbox [type='checkbox'] + label {
/* position: absolute; */
z-index: 5;
}
.floatLabel .InputCheckbox [type='checkbox'] + label:before {
width: 12px;
height: 12px;
border-radius: 0px;
border: 1px solid var(--InputBorder);
background-color: var(--InputBackground);
box-shadow: 2px 2px 0 var(--InputShadow);
display: block;
content: '';
float: left;
margin-right: 5px;
z-index: 5;
position: relative;
}
.floatLabel .InputCheckbox [type='checkbox']:checked + label:before {
margin: 1px 4px 0 1px;
box-shadow: inset 0px 0px 0px 2px var(--CheckboxCheckedBackground), 1px 1px 0 var(--CheckboxCheckedShadow);
background-color: var(--CheckboxCheckedInside);
}
</style>
</head>
<body class="center">
<label style="position: absolute; top: 10px; right: 20px" for="darkmodecheckbox">
<input type="checkbox" id="darkmodecheckbox" style="display: none" />
<em id="darkmodelable" style="color: dimgrey; cursor: pointer">Enable Dark Mode</em>
</label>
<script>
const toggleSwitch = document.getElementById('darkmodecheckbox');
function switchTheme(e) {
if (e.target.checked) {
document.documentElement.setAttribute('data-theme', 'dark');
document.getElementById('darkmodelable').style.color = '#dimgrey';
document.getElementById('darkmodelable').innerHTML = 'Enable Light Mode';
} else {
document.getElementById('darkmodelable').innerHTML = 'Enable Dark Mode';
document.getElementById('darkmodelable').style.color = '#768390';
document.documentElement.setAttribute('data-theme', 'light');
}
}
toggleSwitch.addEventListener('change', switchTheme, false);
</script>
<div id="FORM"></div>
<div id="FORMVALUES" style="opacity: 0"></div>
<script id="CREATEFORM">
const deb = console.log.bind(window.console);
//let FORM = document.getElementById("FORM");
// Create a break line element
// let br = document.createElement('br');
function createForm(json) {
//
// make obj handles
let data = json.FormData;
let meta = json.FormMeta;
//
// create the form
let form = document.createElement('form');
form.setAttribute('method', meta.method);
form.setAttribute('action', meta.action);
form.setAttribute('name', meta.name);
form.setAttribute('autocomplete', 'off');
//
// loops for every form item
data.forEach((d) => {
// TEXT INPUT
if ('text' === d.type) {
form.appendChild(createInputText(d));
}
// TEXTAREA
if ('textarea' === d.type) {
form.appendChild(createTextarea(d));
}
// checkboxGroup
// let divChk = document.createElement('div');
// divChk.setAttribute('class', 'checkboxGroup');
// if ('checkboxGroup' === d.type) {
// d.items.forEach((i) => {
// divChk.appendChild(createcheckboxGroup(i));
// });
// form.appendChild(divChk);
// }
// SELECT
if ('select' === d.type) {
form.appendChild(createListBox(d));
}
// INPUTGROUP
if ('inputGroup' === d.type) {
//
// SOURROUNDING DIV
let divGroup = document.createElement('div');
divGroup.setAttribute('class', 'inputGroup');
d.items.forEach((i) => {
i.GroupName = d.name;
if ('text' === i.type) {
divGroup.appendChild(createInputText(i));
}
if ('checkbox' === i.type) {
divGroup.appendChild(createInputCheckbox(i));
}
});
form.appendChild(divGroup);
}
});
//
// CREATE LISTBOX
//
function createListBox(d) {
// SOURROUNDING DIV
let div = document.createElement('div');
div.setAttribute('class', 'ListBox');
// INPUT FIELD
let input = document.createElement('input');
input.setAttribute('type', d.type);
input.setAttribute('name', d.name);
input.setAttribute('class', 'ListBoxInput');
input.setAttribute('onclick', 'openListBox(this)');
input.setAttribute('placeholder', d.placeholder);
// input.setAttribute('value', d.placeholder);
// LABEL
let label = document.createElement('label');
label.textContent = d.titel;
// LIST
let ul = document.createElement('ul');
d.items.forEach((i) => {
// deb(i)
let li = document.createElement('li');
// LABEL
let ItemLabel = document.createElement('label');
ItemLabel.textContent = i.name;
ItemLabel.setAttribute('class', 'ListBoxItem');
ItemLabel.setAttribute('for', i.value);
// ItemLabel.setAttribute('onclick', 'addListBoxItem(this)');
// CHECKBOX
let ckbox = document.createElement('input');
ckbox.setAttribute('type', 'checkbox');
ckbox.setAttribute('name', i.name);
ckbox.setAttribute('id', i.value);
ckbox.setAttribute('class', 'ListBoxItem');
ckbox.setAttribute('style', 'display:none');
ckbox.setAttribute('onclick', 'addListBoxItem(this)');
// CONCAT LISTITEMS
li.appendChild(ckbox);
li.appendChild(ItemLabel);
ul.appendChild(li);
});
// CONCAT EVERYTHING
div.appendChild(label);
div.appendChild(input);
div.appendChild(ul);
return div;
}
//
// CREATE CHECKBOXGROUP
//
// function createcheckboxGroup(d) {
// // SOURROUNDING DIV
// let div = document.createElement('div');
// div.setAttribute('class', 'CheckboxElement');
// // INPUT FIELD
// let input = document.createElement('input');
// input.setAttribute('type', 'checkbox');
// input.setAttribute('name', d.name);
// // LABEL
// let label = document.createElement('label');
// label.textContent = d.name;
// // CONCAT EVERYTHING
// div.appendChild(input);
// div.appendChild(label);
// return div;
// }
//
// CREATE INPUT TEXT
//
function createInputText(d) {
// SOURROUNDING DIV
let div = document.createElement('div');
div.setAttribute('class', 'InputElement');
// INPUT FIELD
let input = document.createElement('input');
input.setAttribute('type', d.type);
input.setAttribute('name', d.name);
input.setAttribute('placeholder', d.placeholder);
input.setAttribute('onclick', 'activateInput(this)');
// input.setAttribute('value', d.placeholder);
// LABEL
let label = document.createElement('label');
label.textContent = d.titel;
// CONCAT EVERYTHING
div.appendChild(label);
div.appendChild(input);
return div;
}
//
// CREATE INPUT CHECKBOX
//
function createInputCheckbox(d) {
deb(d);
// SOURROUNDING DIV
let div = document.createElement('div');
div.setAttribute('class', 'InputCheckbox');
// SPAN FOR NEW CHECKBOX
let span = document.createElement('span');
span.setAttribute('class', 'CustomCheckbox');
// INPUT FIELD
let input = document.createElement('input');
input.setAttribute('type', d.type);
input.setAttribute('value', d.value);
input.setAttribute('name', d.GroupName + '[]');
input.setAttribute('id', 'ckb' + d.titel);
// input.setAttribute("style", "display:none;");
// LABEL
let label = document.createElement('label');
label.setAttribute('class', 'ckbLabel');
label.setAttribute('for', 'ckb' + d.titel);
label.textContent = d.titel;
// CONCAT EVERYTHING
div.appendChild(input);
// div.appendChild(span);
div.appendChild(label);
return div;
}
//
// CREATE TEXTAREA
//
function createTextarea(d) {
//
// SOURROUNDING DIV
let div = document.createElement('div');
div.setAttribute('class', 'TextareaElement');
//
// INPUT FIELD
let input = document.createElement('textarea');
input.setAttribute('type', d.type);
input.setAttribute('name', d.name);
input.setAttribute('placeholder', d.placeholder);
input.setAttribute('onclick', 'activateInput(this)');
// input.setAttribute('value', d.placeholder);
//
// LABEL
let label = document.createElement('label');
label.textContent = d.titel;
// label.setAttribute('class', 'LabelTop');
//
// CONCAT EVERYTHING
div.appendChild(label);
div.appendChild(input);
return div;
}
//
// SUBMIT BUTTON
let submit = document.createElement('input');
submit.setAttribute('type', 'submit');
submit.setAttribute('value', 'Submit');
submit.setAttribute('id', 'submitButton');
submit.setAttribute('class', 'floatLabelButton');
form.appendChild(submit);
//
// CREATE THE FULL FORMFIELD
// FIELDSET
let fieldset = document.createElement('fieldset');
fieldset.setAttribute('class', 'floatLabel');
// LEGEND
let legend = document.createElement('legend');
legend.innerText = meta.name;
// CONCAT WITH FORM
fieldset.appendChild(legend);
fieldset.appendChild(form);
// INSERT IN DOM
document.getElementById(meta.ID).appendChild(fieldset);
} // createForm
</script>
<script id="EVENTHANDLER">
//
// OPEN LISBOX
//
function openListBox(el) {
el.parentNode.classList.add('isActive');
}
//
// ACTIVATE INPUT
//
function activateInput(el) {
el.parentNode.classList.add('isActive');
}
//
// LISTBOXITEM TO INPUT
//
function addListBoxItem(el) {
// get ckeckbox value, input element & lable
let ckbValue = el.id;
let InputValue = el.parentNode.parentNode.previousSibling.value;
let InputLabel = el.parentNode.parentNode.previousSibling.previousSibling;
// add (remove) value to input
if (el.checked) {
el.parentNode.parentNode.previousSibling.value = InputValue + ckbValue + ', ';
} else {
el.parentNode.parentNode.previousSibling.value = InputValue.replace(ckbValue + ', ', '');
}
var event = new Event('change');
el.parentNode.parentNode.previousSibling.dispatchEvent(event);
// set label on top if input ha a value and vice versa
if (0 < el.parentNode.parentNode.previousSibling.value.length) {
InputLabel.setAttribute('class', 'isTop');
} else {
InputLabel.removeAttribute('class', 'isTop');
}
}
window.addEventListener('load', function () {
//
// EVENTLISTENER CLICK
//
document.addEventListener(
'click',
(evt) => {
let targetEl = evt.target;
// set input as notActive (remove isActive), lable down, shaddow move back, close ListBox
// loop up over elements and search for .isActive class,
// if not found, remove all .isActive from the document
do {
if (targetEl.classList !== undefined && targetEl.classList.contains('isActive')) {
return;
}
targetEl = targetEl.parentNode;
} while (targetEl);
document.querySelectorAll('.isActive').forEach((el) => {
el.classList.remove('isActive');
});
},
true
);
//
// EVENTLISTENER CHANGE
//
const allInputs = document.querySelectorAll("input[type='text'],input[type='select'], textarea");
allInputs.forEach(function (el) {
// deb(el)
// if (null === el.parentNode.parentNode.previousSibling) {
// const labelListBox = el.previousSibling;
// } else {
// const labelListBox = el.parentNode.parentNode.previousSibling;
// }
const labelListBox = el.parentNode.parentNode.previousSibling;
const label = el.previousSibling;
el.addEventListener(
'change',
(evt) => {
if (0 < el.value.length) {
if (null === labelListBox) {
deb(el.previousSibling);
// deb(el.parentNode.parentNode.previousSibling);
}
// labelListBox.setAttribute('class', 'isTop');
label.setAttribute('class', 'isTop');
} else {
// labelListBox.removeAttribute('class', 'isTop');
label.removeAttribute('class', 'isTop');
}
},
true
);
});
});
window.addEventListener('load', function () {
// //
// // GET ITEMS OF LISTBOX UL
// //
// const ListBox = document.querySelectorAll('.ListBox ul');
// // deb(ListBox)
// // FOREACH LISTBOX
// ListBox.forEach(function (ul) {
// const CKBBOX = ul.querySelectorAll('input');
// // deb(CKBBOX)
// ul.addEventListener('click', (evt) => {
// let inputSelect = evt.target.parentNode.parentNode.previousSibling;
// deb('\n\n NEW CLICK');
// deb(evt.target);
// if ('ListBoxItem' === evt.target.getAttribute('class')) {
// // COLLECT ALL VALUES FROM CHECKED CHECKBOXES
// let InputItems = '';
// ul.childNodes.forEach(function (li) {
// if (li.firstChild.checked) {
// InputItems += li.firstChild.name + ', ';
// }
// });
// if (InputItems) {
// inputSelect.classList.add('inputFocus');
// inputSelect.value = InputItems.replace(/,\s*$/, '');
// } else {
// // IF INPUTITEMS IS EMPTY, REMOVE STRING FROM INPUT VALUE && AND SET FOCUS FOR PLACEHOLDER
// inputSelect.focus();
// inputSelect.value = null;
// }
// // IF CKICK IS OUTSINE OF LISTBOX
// // } else if (evt.target.querySelector('.ListBoxItem')) {
// // } else if ('showPlaceholder' !== evt.target.getAttribute('class')) {
// } else {
// // CLOSE LISTBOX
// // deb(evt.target.parentNode.parentNode);
// // evt.target.parentNode.parentNode.removeAttribute('class', 'LBopen');
// // inputSelect.setAttribute('class', 'LabelTop');
// // // MOVE BACK LISTBOX INPUT
// // inputSelect.removeAttribute('class', 'inputFocus');
// }
// });
// });
// document.addEventListener('click', (evt) => {
// deb(evt.target);
// if ('ListBoxItem' !== evt.target.getAttribute('class')) {
// const ListBox = document.querySelectorAll('.ListBox ul');
// ListBox.forEach(function (ul) {
// ul.removeAttribute('class', 'LBopen');
// ul.previousSibling.setAttribute('class', 'LabelTop');
// // MOVE BACK LISTBOX INPUT
// ul.previousSibling.removeAttribute('class', 'inputFocus');
// });
// deb('doc');
// deb(evt.target.getAttribute('class'));
// }
// });
// //
// // EVENTS FOR ALL INPUT TEXT && TEXTAREAS
// let FormElement = document.querySelectorAll("input[type='text'],input[type='select'], textarea");
// FormElement.forEach(function (el) {
// // deb(el)
// //
// // IF FIELD HAS A PRESETTED VALUE
// if (el.value) {
// // AD CLASS TO LABLE TO LIFT IT UP
// // el.previousSibling.setAttribute('class', 'LabelTop');
// // ADD CLASS TO SHOW PLACEHOLDER
// el.setAttribute('class', 'showPlaceholder');
// }
// // IF FIELD IS IN FOCUS
// el.addEventListener('focus', function () {
// // AD CLASS TO LABLE TO LIFT IT UP
// el.previousSibling.setAttribute('class', 'LabelTop');
// // ADD CLASS TO SHOW PLACEHOLDER
// el.setAttribute('class', 'showPlaceholder');
// //
// // DROPDOWN SELECT LIST
// if ('select' === el.attributes.type.nodeValue) {
// el.nextSibling.setAttribute('class', 'LBopen');
// // el.classList.add('inputFocus');
// // el.nextSibling.setAttribute('class', 'inputFocus');
// deb(el);
// // el.setAttribute('class', 'LabelTop');
// }
// }); // addEventListener(focus)
// //
// // IF FIELD IS NOT IN FOCUS
// el.addEventListener('blur', function () {
// if (!el.value) {
// // deb("blur")
// // REMOVE CLASS FROM LABLE
// el.previousSibling.removeAttribute('class', 'LabelTop');
// // REMOVE CLASS TO HIDE PLACEHOLDER & SCHOW LABLE AGAIN
// // el.removeAttribute('class', 'showPlaceholder');
// el.classList.remove('showPlaceholder');
// }
// // DROPDOWN SELECT LIST
// if ('select' === el.attributes.type.nodeValue) {
// // el.nextSibling.removeAttribute('class', 'LBopen');
// }
// });
// // deb(el.attributes.type.nodeValue)
// }); //ForEach FormElement
//
// SET SUBMIT BUTTON STATE
document.getElementById('submitButton').addEventListener('mousedown', function () {
this.classList.add('submitButtonActive');
this.addEventListener('mouseup', function () {
this.classList.remove('submitButtonActive');
});
});
}); // window.load (EVENTHANDLER)
</script>
<script id="FORMSUBMIT">
window.addEventListener('load', function () {
function showData() {
let FormName = data.FormMeta.name;
let FormElements = document.forms[FormName].elements;
deb(FormElements);
FormValues = {};
for (let element of FormElements) {
if (element.value && element.name) {
// remove ListBox checkboxGroup
if ('ListBoxItem' === element.getAttribute('class')) {
continue;
}
if ('checkbox' === element.type) {
if (element.checked) {
deb(element);
if (!FormValues[element.name]) {
FormValues[element.name] = [];
}
FormValues[element.name].push(element.value);
}
} else {
FormValues[element.name] = element.value;
}
}
}
// deb(FormValues)
let values = JSON.stringify(FormValues, undefined, 4);
values = values.replaceAll('{', '');
values = values.replaceAll('}', '');
values = values.replaceAll('"', '');
// values = values.replaceAll(',', '');
values = values.replaceAll(' ', '');
let FORMVALUES = document.getElementById('FORMVALUES');
FORMVALUES.innerHTML = "<fieldset><legend style='font-size: 1.4em'>Form Values</legend><pre>" + values + '</pre></fieldset>';
FORMVALUES.style.opacity = 1;
}
//
// CLICKHANDLER for everything?
document.addEventListener('click', (evt) => {
const LEGEND = document.querySelector('#FORMVALUES legend'); // DEV
const FORMVALUES = document.querySelector('#FORMVALUES'); // DEV
let targetElement = evt.target; // clicked element
do {
// REMOVE FORM VALUES (DEV)
if (targetElement == LEGEND) {
FORMVALUES.style.opacity = 0;
return;
}
// deb(targetElement);
targetElement = targetElement.parentNode;
} while (targetElement);
// deb('outside');
});
//
// KEYHANDLER
document.onkeydown = function (evt) {
evt = evt || window.event;
const FORMVALUES = document.querySelector('#FORMVALUES');
var isEscape = false;
if ('key' in evt) {
// deb(evt);
if (evt.key === 'Escape' || evt.key === 'Esc') {
FORMVALUES.style.opacity = 0;
}
}
};
// function sendData() {
// const XHR = new XMLHttpRequest();
// const FD = new FormData(form);
// XHR.addEventListener('load', function (event) {
// deb(event.target.responseText);
// });
// XHR.addEventListener('error', function (event) {
// deb('Oops! Something went wrong.');
// });
// XHR.open('POST', 'api.php');
// deb(form);
// XHR.send(FD);
// }
const form = document.getElementById('FORM');
form.addEventListener('submit', function (event) {
event.preventDefault();
// sendData();
showData();
});
});
</script>
<script id="JSONDATA">
const data = {
FormMeta: {
name: 'Testform',
ID: 'FORM',
method: 'POST',
action: '',
},
FormData: [
{
type: 'inputGroup',
items: [
{
type: 'text',
name: 'firstname',
titel: 'Firstname',
placeholder: 'how are you called',
},
{
type: 'text',
name: 'surename',
titel: 'Surename',
placeholder: 'how are you called',
},
],
},
{
type: 'inputGroup',
name: 'TOPs',
items: [
{
type: 'checkbox',
value: 'one',
titel: 'TOP I',
},
{
type: 'checkbox',
value: 'two',
titel: 'TOP II',
},
{
type: 'checkbox',
value: 'three',