-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfieldset-validation-element.js
More file actions
68 lines (60 loc) · 1.76 KB
/
fieldset-validation-element.js
File metadata and controls
68 lines (60 loc) · 1.76 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
import { cloneNodesObserver } from '../util.js'
import { getErrorListFromContainer, getErrorContainer } from '../error-containers.js'
/**
* @class
* @classdesc
* An abstract class that can be subclassed to provide specific validation
* scenarios for a fieldset. For example: {@link MinimumCheckboxValuesFieldsetValidationElement}
* is a subclass that validates that at least one value for the field name specified in
* this element is present in the `FormData`
*/
export class FieldsetValidationElement extends HTMLElement {
constructor() {
super();
}
connectedCallback() {
if(!this.isConnected){ return }
this.setupErrorListCloning()
}
/**
* Calls {@link cloneNodesObserver} to
* clone {@link FieldsetValidationElement#errorContainer} into
* {@link FieldsetValidationElement#errorContainerARIA} and keep them in sync.
*/
setupErrorListCloning() {
cloneNodesObserver(
getErrorListFromContainer(this.errorContainer),
getErrorListFromContainer(this.errorContainerARIA)
)
}
/**
* The `form` of the {@link FieldsetValidationElement#fieldset}
*/
get form() {
return this.fieldset.form
}
/**
* The element with the ID from the `fieldset` attribute
*/
get fieldset() {
return document.getElementById(this.getAttribute(`fieldset`))
}
/**
* The `field-name` attribute`
*/
get fieldName() {
return this.getAttribute(`field-name`)
}
/**
* See {@link getErrorContainer}, uses {@link FieldsetValidationElement#fieldset}
*/
get errorContainer(){
return getErrorContainer(this.fieldset);
}
/**
* The element with the ID from the `error-container-aria` attribute
*/
get errorContainerARIA(){
return document.getElementById(this.getAttribute(`error-container-aria`))
}
}