-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Expand file tree
/
Copy pathdemo.html
More file actions
74 lines (64 loc) · 2.2 KB
/
demo.html
File metadata and controls
74 lines (64 loc) · 2.2 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
69
70
71
72
73
74
<!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.11741289071.1e8e1c3f/dist/ionic/ionic.esm.js"
></script>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@ionic/core@8.4.4-dev.11741289071.1e8e1c3f/css/ionic.bundle.css"
/>
</head>
<body>
<div class="container">
<form id="my-form">
<ion-select
label="Default label"
placeholder="Favorite Fruit"
helper-text="Select your favorite fruit"
error-text="This field is required"
>
<ion-select-option value="apple">Apple</ion-select-option>
<ion-select-option value="banana">Banana</ion-select-option>
<ion-select-option value="orange">Orange</ion-select-option>
</ion-select>
<br />
<ion-button type="submit" size="small">Submit</ion-button>
</form>
</div>
<script>
const form = document.getElementById('my-form');
const favFruit = form.querySelector('ion-select');
form.addEventListener('submit', (event) => submit(event));
favFruit.addEventListener('ionChange', (event) => validateSelect(event));
favFruit.addEventListener('ionBlur', () => onIonBlur({ detail: { value: favFruit.value } }));
const validateSelect = (event) => {
if (!event.detail.value) {
favFruit.classList.add('ion-invalid');
favFruit.classList.remove('ion-valid');
} else {
favFruit.classList.remove('ion-invalid');
favFruit.classList.add('ion-valid');
}
};
const markTouched = () => {
favFruit.classList.add('ion-touched');
};
const onIonBlur = (event) => {
markTouched();
validateSelect(event);
};
const submit = (event) => {
event.preventDefault();
markTouched();
validateSelect({ detail: { value: favFruit.value } });
};
</script>
</body>
</html>