-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathform-association.html
More file actions
41 lines (35 loc) · 1.14 KB
/
form-association.html
File metadata and controls
41 lines (35 loc) · 1.14 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
<form id="face">
<pf-checkbox label="Parent"
name="options"
value="parent">
<pf-checkbox label="Child 1"
name="options"
value="child1"></pf-checkbox>
<pf-checkbox label="Child 2"
name="options"
value="child2"></pf-checkbox>
</pf-checkbox>
<pf-checkbox label="Sibling"
name="options"
value="sibling"></pf-checkbox>
<pf-button>Submit and Log Results</pf-button>
<fieldset>
<legend>FormData</legend>
<output name="output"></output>
</fieldset>
</form>
<script type="module">
import '@patternfly/elements/pf-checkbox/pf-checkbox.js';
const form = document.getElementById('face')
form.addEventListener('submit', event => {
event.preventDefault();
const formdata = new FormData(form);
console.log(event);
console.log(formdata)
const fields = Array.from(formdata.entries()).reduce((acc, [key, val]) => ({ ...acc,
[key]: key in acc ? [acc[key], val].flat() : val
}), {});
delete fields.output;
form.elements.output.textContent = JSON.stringify(fields);
})
</script>