-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
demo-standalone.html
237 lines (220 loc) · 9.81 KB
/
demo-standalone.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<!DOCTYPE html>
<html lang="en" class="no-js">
<head>
<title>Bootstrap 5 tags demo</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/modern-css-reset/dist/reset.min.css" />
<link href="tags-standalone.min.css" rel="stylesheet" />
<script type="module">
import Tags from "./tags.js";
Tags.init("select[multiple]:not(#regular)");
// Multiple inits should not matter
Tags.init("select[multiple]:not(#regular)");
// Reset does not fire a change input
document.getElementById("regular").addEventListener("change", function (ev) {
console.log(this.selectedOptions);
});
</script>
<style>
body {
font-family: sans-serif;
}
.mb-3 {
margin-bottom: 1em;
}
.container {
padding: 2em
}
/* Animated menu */
@keyframes dropdownAnimation {
from {
opacity: 0;
margin-top: calc(var(--bs-dropdown-spacer, 0.125)*var(--dropdown-animation-factor))
}
to {
opacity: 1;
margin-top: calc(var(--bs-dropdown-spacer, 0.125)*var(--dropdown-animation-end-factor))
}
}
@keyframes dropupAnimation {
from {
opacity: 0;
margin-bottom: calc(var(--bs-dropdown-spacer, 0.125)*var(--dropdown-animation-factor))
}
to {
opacity: 1;
margin-bottom: calc(var(--bs-dropdown-spacer, 0.125)*var(--dropdown-animation-end-factor))
}
}
@media(prefers-reduced-motion: no-preference) {
.dropdown .dropdown-menu.show,
.dropup .dropdown-menu.show {
--dropdown-animation-factor: -2;
--dropdown-animation-end-factor: 1;
animation-name: dropdownAnimation;
animation-duration: .25s;
animation-iteration-count: 1;
animation-timing-function: ease-out;
animation-fill-mode: forwards
}
.dropdown .dropdown-menu[data-popper-placement],
.dropup .dropdown-menu[data-popper-placement] {
--dropdown-animation-end-factor: 0
}
.dropup .dropdown-menu.show {
--dropdown-animation-factor: 2;
--dropdown-animation-end-factor: -1
}
.dropup .dropdown-menu[data-popper-placement].show {
--dropdown-animation-factor: -2;
--dropdown-animation-end-factor: 0;
animation-name: dropupAnimation
}
}
</style>
</head>
<body>
<div class="container">
<h1>Demo</h1>
<form class="needs-validation" novalidate method="get" action="https://vercel-dumper.vercel.app/">
<div class="row mb-3 g-3">
<div class="col-md-4">
<label for="validationTags" class="form-label">Tags</label>
<select class="form-select" id="validationTags" name="tags[]" multiple>
<option disabled hidden value="">Choose a tag...</option>
<option value="1" selected="selected">Apple</option>
<option value="2">Banana</option>
<option value="3">Orange</option>
</select>
<div class="invalid-feedback">Please select a valid tag.</div>
</div>
</div>
<div class="row mb-3 g-3">
<div class="col-md-4">
<label for="validationTagsClear" class="form-label">Tags (allow clear)</label>
<select class="form-select" id="validationTagsClear" name="tagsClear[]" multiple data-allow-clear="true">
<option disabled hidden value="">Choose a tag...</option>
<option value="1" selected="selected">Apple</option>
<option value="2">Banana</option>
<option value="3">Orange</option>
</select>
<div class="invalid-feedback">Please select a valid tag.</div>
</div>
</div>
<div class="row mb-3 g-3">
<div class="col-md-4">
<label for="validationTagsThreshold" class="form-label">Tags (allow clear + 0 threshold)</label>
<select class="form-select" id="validationTagsThreshold" name="tagsClearThreshold[]" multiple data-allow-clear="true"
data-suggestions-threshold="0">
<option disabled hidden value="">Choose a tag...</option>
<option value="1" selected="selected">Apple</option>
<option value="2">Banana</option>
<option value="3">Orange</option>
</select>
<div class="invalid-feedback">Please select a valid tag.</div>
</div>
</div>
<div class="row mb-3 g-3">
<div class="col-md-4">
<label for="validationTagsShow" class="form-label">Tags (show all + custom colors)</label>
<select class="form-select" id="validationTagsShow" name="tags_show[]" multiple data-show-all-suggestions="true">
<option disabled hidden value="">Choose a tag...</option>
<option value="1" selected="selected">Apple</option>
<option value="2" data-badge-style="success" selected="selected">Banana</option>
<option value="3" data-badge-style="warning" data-badge-class="text-dark">Orange</option>
<option value="4" data-badge-style="secondary">Blueberry</option>
<option value="5">Strawberry</option>
<option value="6">Cranberry</option>
<option value="7">Huckleberry</option>
<option value="8">Chokeberry</option>
<option value="9">Elderberry</option>
<option value="10">Gooseberry</option>
<option value="11">Blackberry</option>
<option value="12">Raspberry</option>
<option value="13">Goji berry</option>
<option value="14">Salmon berry</option>
<option value="15">Sumac berry</option>
</select>
<div class="invalid-feedback">Please select a valid tag.</div>
</div>
</div>
<div class="row mb-3 g-3">
<div class="col-md-4">
<label for="validationTagsNew" class="form-label">Tags (allow new)</label>
<select class="form-select" id="validationTagsNew" name="tags_new[]" multiple data-allow-new="true">
<option disabled hidden value="">Choose a tag...</option>
<option value="1" selected="selected">Apple</option>
<option value="2">Banana</option>
<option value="3">Orange</option>
</select>
<div class="invalid-feedback">Please select a valid tag.</div>
</div>
</div>
<div class="row mb-3 g-3">
<div class="col-md-4">
<label for="regexTags" class="form-label">Tags (allow new only if it matches regex)</label>
<select class="form-select" id="regexTags" name="tags_regex[]" multiple data-allow-new="true" data-regex=".*@mycompany\.com$">
<option disabled hidden value="">Add mail address</option>
<option value="1" selected="selected">[email protected]</option>
<option value="2">[email protected]</option>
<option value="3">[email protected]</option>
</select>
<div class="invalid-feedback">Please select only @mycompany.com addresses.</div>
</div>
</div>
<div class="row mb-3 g-3">
<div class="col-md-4">
<label for="separatorTags" class="form-label">Tags (with space and comma separator)</label>
<select class="form-select" id="separatorTags" name="tags_separator[]" multiple data-allow-new="true" data-separator=" |,| ">
<option value="">Type a tag...</option><!-- you need at least one option with the placeholder -->
</select>
</div>
</div>
<div class="row mb-3 g-3">
<div class="col-md-4">
<label for="maxTags" class="form-label">Tags (max 2 tags + clear)</label>
<select class="form-select" id="maxTags" name="tags_max[]" multiple data-allow-new="true" data-max="2" data-allow-clear="1">
<option value="">Type a tag...</option><!-- you need at least one option with the placeholder -->
<option value="1">Apple</option>
<option value="2">Banana</option>
<option value="3">Orange</option>
</select>
</div>
</div>
<div class="row mb-3 g-3">
<div class="col-md-4">
<label for="validationTagsJson" class="form-label">Tags (server side)</label>
<select class="form-select" id="validationTagsJson" name="tags_json[]" multiple data-allow-new="true" data-server="demo.json"
data-live-server="1">
<option disabled hidden value="">Choose a tag...</option>
</select>
</div>
</div>
<div class="row mb-3 g-3">
<div class="col-md-4">
<label for="disabledTags" class="form-label">Tags (disabled)</label>
<select class="form-select" id="disabledTags" name="tags_disabled[]" multiple disabled data-allow-new="true">
<option disabled hidden value="">Choose a tag...</option>
<option value="1">Apple</option>
<option value="2">Banana</option>
<option value="3">Orange</option>
</select>
</div>
</div>
<input type="reset" value="Reset" class="btn btn-outline-dark""/>
<button class=" btn btn-primary" type="submit">Submit form</button>
<hr>
<p>A regular select below to test reset</p>
<select class="form-select" id="regular" name="regular[]" multiple>
<option disabled hidden value="">Choose a tag...</option>
<option value="1" selected="selected">Apple</option>
<option value="2">Banana</option>
<option value="3">Orange</option>
</select>
<hr>
<p>A disabled input for reference</p>
<input class="form-control" type="text" placeholder="Disabled input" aria-label="Disabled input example" disabled>
<hr>
</form>
</div>
</body>
</html>