-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Expand file tree
/
Copy pathdemo.html
More file actions
58 lines (49 loc) · 1.68 KB
/
demo.html
File metadata and controls
58 lines (49 loc) · 1.68 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Input</title>
<link rel="stylesheet" href="../../common.css" />
<script src="../../common.js"></script>
<script
type="module"
src="https://cdn.jsdelivr.net/npm/@ionic/core@8.4.4-dev.11741206641.18dd4e91/dist/ionic/ionic.esm.js"
></script>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@ionic/core@8.4.4-dev.11741206641.18dd4e91/css/ionic.bundle.css"
/>
</head>
<body>
<div class="container">
<form id="my-form">
<ion-checkbox helper-text="This needs to be checked" error-text="This field is required">
I agree to the terms and conditions
</ion-checkbox>
<br />
<ion-button type="submit" size="small">Submit</ion-button>
</form>
</div>
<script>
const form = document.getElementById('my-form');
const agree = form.querySelector('ion-checkbox');
form.addEventListener('submit', (event) => submit(event));
agree.addEventListener('ionChange', (event) => validateCheckbox(event));
const validateCheckbox = (event) => {
agree.classList.add('ion-touched');
if (!event.detail.checked) {
agree.classList.add('ion-invalid');
agree.classList.remove('ion-valid');
} else {
agree.classList.remove('ion-invalid');
agree.classList.add('ion-valid');
}
};
const submit = (event) => {
event.preventDefault();
validateCheckbox({ detail: { checked: agree.checked } });
};
</script>
</body>
</html>