-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
33 lines (27 loc) · 1.08 KB
/
index.js
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
export default (form) => {
if (!form) {
throw Error('Target form element missing for function `reportValidity`.')
}
if (HTMLFormElement.prototype.reportValidity) {
return form.reportValidity();
} else {
if (form.checkValidity()) {
return true;
}
if (!form.reportValidityFakeSubmit) {
form.reportValidityFakeSubmit = document.createElement('button');
form.reportValidityFakeSubmit.setAttribute('type', 'submit');
form.reportValidityFakeSubmit.setAttribute('hidden', 'hidden');
form.reportValidityFakeSubmit.setAttribute('style', 'display:none');
form.reportValidityFakeSubmit.setAttribute('class', 'reportValidityFakeSubmit');
form.reportValidityFakeSubmit.addEventListener('click', evt => {
if (form.checkValidity()) {
evt.preventDefault();
}
});
form.appendChild(form.reportValidityFakeSubmit);
}
form.reportValidityFakeSubmit.click();
return false;
}
}