-
Notifications
You must be signed in to change notification settings - Fork 0
/
form-element-association.html
77 lines (71 loc) · 2.18 KB
/
form-element-association.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
<html>
<head>
<style>
div, my-editable, my-associated-editable {
border: 2px solid black;
}
</style>
</head>
<body>
<form>
<input type='text' />
<br />
<textarea></textarea>
<br />
<div contenteditable='true'></div>
<br />
<input type='checkbox' />
<br />
<my-checkbox></my-checkbox>
<br />
<my-associated-checkbox></my-associated-checkbox>
<br />
<my-editable></my-editable>
<br />
<my-associated-editable></my-associated-editable>
<br />
<input type='submit' value='Click' />
<br />
</form>
<script>
let form = document.querySelector('form');
let input1 = document.querySelector('input');
let textarea1 = document.querySelector('textarea');
let div1 = document.querySelector('div');
let input2 = document.querySelectorAll('input')[1];
let checkbox1 = document.querySelector('my-checkbox');
let associatedCheckbox1 = document.querySelector('my-associated-checkbox')
let editable1 = document.querySelector('my-editable');
let associatedEditable1 = document.querySelector('my-associated-editable');
let input3 = document.querySelectorAll('input')[2];
class Checkbox extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' });
let input = document.createElement('input');
input.setAttribute('type', 'checkbox');
this.shadowRoot.append(input);
}
}
window.customElements.define('my-checkbox', Checkbox);
class AssociatedCheckbox extends Checkbox {
static formAssociated = true;
}
window.customElements.define('my-associated-checkbox', AssociatedCheckbox);
class Editable extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' });
let div = document.createElement('div');
div.setAttribute('contenteditable', 'true');
this.shadowRoot.append(div);
}
}
window.customElements.define('my-editable', Editable);
class AssociatedEditable extends Editable {
static formAssociated = true;
}
window.customElements.define('my-associated-editable', AssociatedEditable);
</script>
</body>
</html>