zidan-select 2.2.4 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +95 -50
- package/dist/file/plugin-file-core.css +31 -5
- package/dist/file/plugin-file-core.min.css +9 -0
- package/dist/file/plugin-file-theme.css +23 -6
- package/dist/file/plugin-file-theme.min.css +9 -0
- package/dist/file/zidan-file.d.ts +32 -0
- package/dist/file/zidan-file.js +196 -23
- package/dist/file/zidan-file.min.js +11 -0
- package/dist/plugin-core.css +106 -15
- package/dist/plugin-core.min.css +10 -0
- package/dist/plugin-theme.css +36 -6
- package/dist/plugin-theme.min.css +13 -0
- package/dist/select/plugin-select-core.css +22 -3
- package/dist/select/plugin-select-core.min.css +9 -0
- package/dist/select/plugin-select-theme.css +28 -4
- package/dist/select/plugin-select-theme.min.css +9 -0
- package/dist/select/zidan-select.d.ts +33 -0
- package/dist/select/zidan-select.js +277 -26
- package/dist/select/zidan-select.min.js +11 -0
- package/dist/zidan-form.js +448 -58
- package/dist/zidan-form.min.js +14 -0
- package/docs/build.md +11 -10
- package/docs/comparison.md +11 -6
- package/docs/html-and-wordpress.md +893 -0
- package/docs/index.html +13 -3
- package/docs/options.md +57 -9
- package/docs/validation.md +36 -1
- package/package.json +21 -1
- package/plugin-core.css +106 -15
- package/plugin-theme.css +36 -6
- package/zidan-form.d.ts +422 -0
- package/zidan-form.js +448 -58
|
@@ -0,0 +1,893 @@
|
|
|
1
|
+
# Static HTML & WordPress cookbook
|
|
2
|
+
|
|
3
|
+
Copy-paste recipes for hand-written HTML pages, WordPress sites and page builders. Every example
|
|
4
|
+
below is a **complete working page or block** — no build tools, no npm, no framework required.
|
|
5
|
+
If you only need the reference, see [Options & data attributes](options.md) and the
|
|
6
|
+
[JavaScript API](https://github.com/akhtar1985/zidan-select#javascript-api).
|
|
7
|
+
|
|
8
|
+
Contents:
|
|
9
|
+
|
|
10
|
+
1. [Pick the files first](#1-pick-the-files-first)
|
|
11
|
+
2. [Five ways to switch a control on](#2-five-ways-to-switch-a-control-on)
|
|
12
|
+
3. [Complete static page — full build](#3-complete-static-page--full-build)
|
|
13
|
+
4. [Complete select-only page](#4-complete-select-only-page)
|
|
14
|
+
5. [Complete file-only page](#5-complete-file-only-page)
|
|
15
|
+
6. [Enhance by ID or class from JavaScript](#6-enhance-by-id-or-class-from-javascript)
|
|
16
|
+
7. [WordPress](#7-wordpress)
|
|
17
|
+
8. [Other hosts and website builders](#8-other-hosts-and-website-builders)
|
|
18
|
+
9. [Shopify](#9-shopify)
|
|
19
|
+
10. [Copy-paste recipes](#10-copy-paste-recipes)
|
|
20
|
+
11. [Troubleshooting](#11-troubleshooting)
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## 1. Pick the files first
|
|
25
|
+
|
|
26
|
+
Load **one** build per page. Each build is standalone; a subset is not an add-on to the full
|
|
27
|
+
bundle. Both CSS files are always needed: `plugin-core.css` carries layout and mechanics (no
|
|
28
|
+
colours), `plugin-theme.css` carries colours, presets and skins.
|
|
29
|
+
|
|
30
|
+
| Your page needs… | Load these files |
|
|
31
|
+
| --- | --- |
|
|
32
|
+
| Selects / combobox / tags only | `dist/select/zidan-select.js` + `plugin-select-core.css` + `plugin-select-theme.css` |
|
|
33
|
+
| File uploads only | `dist/file/zidan-file.js` + `plugin-file-core.css` + `plugin-file-theme.css` |
|
|
34
|
+
| Several control types together | `zidan-form.js` + `plugin-core.css` + `plugin-theme.css` |
|
|
35
|
+
|
|
36
|
+
Pinned CDN URLs (replace `2.3.0` when you upgrade):
|
|
37
|
+
|
|
38
|
+
| Build | JavaScript | CSS |
|
|
39
|
+
| --- | --- | --- |
|
|
40
|
+
| Full | `https://cdn.jsdelivr.net/npm/zidan-select@2.3.0/zidan-form.js` | `…@2.3.0/plugin-core.css` + `…@2.3.0/plugin-theme.css` |
|
|
41
|
+
| Select-only | `https://cdn.jsdelivr.net/npm/zidan-select@2.3.0/dist/select/zidan-select.js` | `…@2.3.0/dist/select/plugin-select-core.css` + `…plugin-select-theme.css` |
|
|
42
|
+
| File-only | `https://cdn.jsdelivr.net/npm/zidan-select@2.3.0/dist/file/zidan-file.js` | `…@2.3.0/dist/file/plugin-file-core.css` + `…plugin-file-theme.css` |
|
|
43
|
+
|
|
44
|
+
Prefer self-hosting? Download the same files (`npm pack zidan-select@2.3.0`, or the raw files
|
|
45
|
+
from GitHub) and keep them next to your page:
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
my-site/
|
|
49
|
+
├─ index.html
|
|
50
|
+
└─ assets/zidan/
|
|
51
|
+
├─ zidan-form.js
|
|
52
|
+
├─ plugin-core.css
|
|
53
|
+
└─ plugin-theme.css
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Then use relative paths: `assets/zidan/plugin-core.css`. `.min` copies exist inside `dist/`
|
|
57
|
+
(`dist/zidan-form.min.js`, `dist/plugin-core.min.css`, `dist/plugin-theme.min.css`) if you
|
|
58
|
+
prefer minified files.
|
|
59
|
+
|
|
60
|
+
> **Never load the full build and a subset on the same page.** The second copy is ignored
|
|
61
|
+
> (the library keeps the first initialised instance), and you would not get the API you expect.
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## 2. Five ways to switch a control on
|
|
66
|
+
|
|
67
|
+
Nothing is touched unless it opts in. Pick the one that matches your situation.
|
|
68
|
+
|
|
69
|
+
| Situation | What to use | Where it runs |
|
|
70
|
+
| --- | --- | --- |
|
|
71
|
+
| You control the markup and want **zero JavaScript** | `data-zidan*` attributes and marker classes | Automatic, on `DOMContentLoaded` |
|
|
72
|
+
| Enhance **every select and file input** inside one form | `<form class="zidan-form">` (or `data-zidan-form`) | Automatic |
|
|
73
|
+
| You only have **IDs or classes** (CMS, page builder) | `window.ZIDAN_FORM_CONFIG` targets | Automatic, before the script |
|
|
74
|
+
| Enhance **one specific field** | `zidanSelect('#id', {…})` / `zidanField('#id', {…})` | Your own `<script>` |
|
|
75
|
+
| Page content is **rendered later** (AJAX, SPA, builder) | `ZidanForm.refresh(scope)` or `ZidanForm.observe(scope)` | Your own `<script>` |
|
|
76
|
+
|
|
77
|
+
### 2a. Attributes and marker classes (no JavaScript)
|
|
78
|
+
|
|
79
|
+
```html
|
|
80
|
+
<select name="country" class="zidan-select"
|
|
81
|
+
data-zidan-options='{"mode":"combobox","placeholder":"Search a country…"}'>…</select>
|
|
82
|
+
|
|
83
|
+
<select name="tags" class="zidan-select" multiple
|
|
84
|
+
data-zidan-options='{"mode":"tags","maxTags":3}'>…</select>
|
|
85
|
+
|
|
86
|
+
<input type="text" class="zidan-field" data-zidan-icon="mail" data-zidan-clear>
|
|
87
|
+
<input type="file" class="zidan-field" data-zidan-options='{"variant":"dropzone"}'>
|
|
88
|
+
<input type="checkbox" class="zidan-field" data-zidan-variant="switch">
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
`data-zidan="select"` works the same as the `zidan-select` class, and
|
|
92
|
+
`data-zidan="checkbox|file|input|textarea|radio-group"` works the same as `zidan-field`.
|
|
93
|
+
The JSON attribute carries any literal option; callbacks and upload functions need a small JS
|
|
94
|
+
block instead.
|
|
95
|
+
|
|
96
|
+
### 2b. Form scope
|
|
97
|
+
|
|
98
|
+
```html
|
|
99
|
+
<form class="zidan-form" method="post">
|
|
100
|
+
<!-- every <select> and every <input type="file"> here is enhanced, marked or not -->
|
|
101
|
+
<select name="plan">…</select>
|
|
102
|
+
<input type="file" name="cv" accept=".pdf">
|
|
103
|
+
<!-- other inputs still need an attribute or the zidan-field class -->
|
|
104
|
+
<input type="email" name="email" data-zidan="input">
|
|
105
|
+
</form>
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### 2c. Config targets by ID or class (no inline `zidanSelect` call)
|
|
109
|
+
|
|
110
|
+
Define the config **before** the library script. IDs, classes and full selectors are accepted:
|
|
111
|
+
|
|
112
|
+
```html
|
|
113
|
+
<script>
|
|
114
|
+
window.ZIDAN_FORM_CONFIG = {
|
|
115
|
+
targets: ['#country', 'select.product-variants',
|
|
116
|
+
{ selector: '#brands', options: { mode: 'tags', maxTags: 3 } }],
|
|
117
|
+
fieldTargets: [
|
|
118
|
+
{ selector: '#email', options: { icon: 'mail', clearable: true } },
|
|
119
|
+
{ selector: '#avatar', options: { variant: 'avatar' } }
|
|
120
|
+
],
|
|
121
|
+
formTargets: ['#checkout']
|
|
122
|
+
};
|
|
123
|
+
</script>
|
|
124
|
+
<script src="assets/zidan/zidan-form.js"></script>
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### 2d. Direct call by ID or class
|
|
128
|
+
|
|
129
|
+
```html
|
|
130
|
+
<select id="country">…</select>
|
|
131
|
+
<select class="product-select">…</select>
|
|
132
|
+
|
|
133
|
+
<script src="assets/zidan/zidan-form.js"></script>
|
|
134
|
+
<script>
|
|
135
|
+
// one select by ID
|
|
136
|
+
var country = zidanSelect('#country', { mode: 'combobox', placeholder: 'Search…' });
|
|
137
|
+
|
|
138
|
+
// every select with that class (returns an array when several match)
|
|
139
|
+
var products = zidanSelect('.product-select', { mode: 'select', clearable: true });
|
|
140
|
+
|
|
141
|
+
// a plain input with JS-only options
|
|
142
|
+
zidanField('#email', { icon: 'mail', clearable: true, counter: 80 });
|
|
143
|
+
</script>
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### 2e. Content rendered after page load
|
|
147
|
+
|
|
148
|
+
```html
|
|
149
|
+
<script src="assets/zidan/zidan-form.js"></script>
|
|
150
|
+
<script>
|
|
151
|
+
// after injecting new markup: pass the element, not a selector
|
|
152
|
+
var scope = document.querySelector('#checkout');
|
|
153
|
+
ZidanForm.refresh(scope); // enhance new nodes + update existing ones
|
|
154
|
+
|
|
155
|
+
// or keep a container in sync automatically:
|
|
156
|
+
ZidanForm.observe(scope); // MutationObserver; destroys removed instances
|
|
157
|
+
</script>
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## 3. Complete static page — full build
|
|
163
|
+
|
|
164
|
+
Save this as `index.html` and open it in a browser (double-clicking the file works). Every
|
|
165
|
+
control is enhanced automatically; the script at the bottom only pretends to submit so you can
|
|
166
|
+
see the native `FormData`.
|
|
167
|
+
|
|
168
|
+
```html
|
|
169
|
+
<!DOCTYPE html>
|
|
170
|
+
<html lang="en">
|
|
171
|
+
<head>
|
|
172
|
+
<meta charset="utf-8">
|
|
173
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
174
|
+
<title>ZidanForm static example</title>
|
|
175
|
+
|
|
176
|
+
<!-- structure first, theme second -->
|
|
177
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/zidan-select@2.3.0/plugin-core.css">
|
|
178
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/zidan-select@2.3.0/plugin-theme.css">
|
|
179
|
+
</head>
|
|
180
|
+
<body>
|
|
181
|
+
|
|
182
|
+
<main style="max-width:560px;margin:40px auto;padding:0 20px">
|
|
183
|
+
<h1>Booking request</h1>
|
|
184
|
+
|
|
185
|
+
<form class="zidan-form" method="post" action="/thanks.html">
|
|
186
|
+
<p>
|
|
187
|
+
<label for="country">Country</label>
|
|
188
|
+
<select id="country" name="country" required data-zidan-select="combobox">
|
|
189
|
+
<option value="">Choose a country…</option>
|
|
190
|
+
<option>United Kingdom</option>
|
|
191
|
+
<option>United States</option>
|
|
192
|
+
<option>Japan</option>
|
|
193
|
+
</select>
|
|
194
|
+
</p>
|
|
195
|
+
|
|
196
|
+
<p>
|
|
197
|
+
<label for="email">Email</label>
|
|
198
|
+
<input id="email" type="email" name="email" required
|
|
199
|
+
data-zidan="input" data-zidan-auto-icon="true" data-zidan-clear>
|
|
200
|
+
</p>
|
|
201
|
+
|
|
202
|
+
<p>
|
|
203
|
+
<label for="phone">Phone</label>
|
|
204
|
+
<input id="phone" type="tel" name="phone"
|
|
205
|
+
data-zidan="input" data-zidan-phone="true"
|
|
206
|
+
data-zidan-phone-country="GB" data-zidan-phone-format="international">
|
|
207
|
+
</p>
|
|
208
|
+
|
|
209
|
+
<p>
|
|
210
|
+
<label for="guests">Guests</label>
|
|
211
|
+
<input id="guests" type="number" name="guests" min="1" max="8" value="2"
|
|
212
|
+
data-zidan="input" data-zidan-stepper="stacked">
|
|
213
|
+
</p>
|
|
214
|
+
|
|
215
|
+
<p>
|
|
216
|
+
<label for="budget">Budget</label>
|
|
217
|
+
<input id="budget" type="range" name="budget" min="0" max="1000" step="50" value="500"
|
|
218
|
+
data-zidan="input" data-zidan-output="#budget-out">
|
|
219
|
+
<output id="budget-out">500</output>
|
|
220
|
+
</p>
|
|
221
|
+
|
|
222
|
+
<p>
|
|
223
|
+
<label>
|
|
224
|
+
<input type="checkbox" name="news" value="yes"
|
|
225
|
+
data-zidan="checkbox" data-zidan-variant="switch"
|
|
226
|
+
data-zidan-label="Email me offers">
|
|
227
|
+
</label>
|
|
228
|
+
</p>
|
|
229
|
+
|
|
230
|
+
<fieldset data-zidan="radio-group" data-zidan-variant="inline">
|
|
231
|
+
<legend>Contact preference</legend>
|
|
232
|
+
<label><input type="radio" name="contact" value="email" checked> Email</label>
|
|
233
|
+
<label><input type="radio" name="contact" value="phone"> Phone</label>
|
|
234
|
+
</fieldset>
|
|
235
|
+
|
|
236
|
+
<p>
|
|
237
|
+
<label for="message">Message</label>
|
|
238
|
+
<textarea id="message" name="message" rows="4" maxlength="300"
|
|
239
|
+
data-zidan="textarea" data-zidan-counter="300"></textarea>
|
|
240
|
+
</p>
|
|
241
|
+
|
|
242
|
+
<p>
|
|
243
|
+
<label for="docs">Documents</label>
|
|
244
|
+
<input id="docs" type="file" name="docs" multiple accept="image/*,.pdf"
|
|
245
|
+
data-zidan="file" data-zidan-max-files="3" data-zidan-max-size-mb="5"
|
|
246
|
+
data-zidan-title="Drop files here"
|
|
247
|
+
data-zidan-simulate-upload="true">
|
|
248
|
+
</p>
|
|
249
|
+
|
|
250
|
+
<button type="submit">Send request</button>
|
|
251
|
+
</form>
|
|
252
|
+
</main>
|
|
253
|
+
|
|
254
|
+
<script src="https://cdn.jsdelivr.net/npm/zidan-select@2.3.0/zidan-form.js"></script>
|
|
255
|
+
<script>
|
|
256
|
+
// Demo only: show the native FormData instead of navigating away.
|
|
257
|
+
document.querySelector('.zidan-form').addEventListener('submit', function (event) {
|
|
258
|
+
event.preventDefault(); // remove this line to post for real
|
|
259
|
+
var data = new FormData(event.currentTarget);
|
|
260
|
+
console.log(Array.from(data.entries()));
|
|
261
|
+
alert('Captured ' + Array.from(data.keys()).length + ' fields — see the console.');
|
|
262
|
+
});
|
|
263
|
+
</script>
|
|
264
|
+
</body>
|
|
265
|
+
</html>
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
What is happening:
|
|
269
|
+
|
|
270
|
+
- `class="zidan-form"` enhances the two selects and any file input inside; the other controls
|
|
271
|
+
carry `data-zidan` attributes or the `zidan-field` class.
|
|
272
|
+
- `data-zidan-simulate-upload="true"` fakes progress so the upload UI works with no server.
|
|
273
|
+
Point `data-zidan-upload-url="/upload"` at a real endpoint when you have one.
|
|
274
|
+
- No JS call is needed for enhancement; the script's auto-init runs once when the page is parsed.
|
|
275
|
+
- `required` still blocks an empty submit, and the posted `FormData` contains the real values.
|
|
276
|
+
|
|
277
|
+
---
|
|
278
|
+
|
|
279
|
+
## 4. Complete select-only page
|
|
280
|
+
|
|
281
|
+
Only selects on this page? Load the trimmed build. It exposes `zidanSelect`, `initZidanSelects`
|
|
282
|
+
and `ZidanSelect`; `zidanField` does not exist here.
|
|
283
|
+
|
|
284
|
+
```html
|
|
285
|
+
<!DOCTYPE html>
|
|
286
|
+
<html lang="en">
|
|
287
|
+
<head>
|
|
288
|
+
<meta charset="utf-8">
|
|
289
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
290
|
+
<title>Select-only example</title>
|
|
291
|
+
<link rel="stylesheet"
|
|
292
|
+
href="https://cdn.jsdelivr.net/npm/zidan-select@2.3.0/dist/select/plugin-select-core.css">
|
|
293
|
+
<link rel="stylesheet"
|
|
294
|
+
href="https://cdn.jsdelivr.net/npm/zidan-select@2.3.0/dist/select/plugin-select-theme.css">
|
|
295
|
+
</head>
|
|
296
|
+
<body style="max-width:520px;margin:40px auto;padding:0 20px">
|
|
297
|
+
|
|
298
|
+
<label for="country">Country</label>
|
|
299
|
+
<select id="country" name="country">
|
|
300
|
+
<option value="">Choose…</option>
|
|
301
|
+
<option>France</option>
|
|
302
|
+
<option>Germany</option>
|
|
303
|
+
<option>Japan</option>
|
|
304
|
+
</select>
|
|
305
|
+
|
|
306
|
+
<p>
|
|
307
|
+
<label for="sku">Product</label>
|
|
308
|
+
<select id="sku" name="sku">
|
|
309
|
+
<option value="basic">Basic</option>
|
|
310
|
+
<option value="pro">Pro</option>
|
|
311
|
+
</select>
|
|
312
|
+
</p>
|
|
313
|
+
|
|
314
|
+
<script src="https://cdn.jsdelivr.net/npm/zidan-select@2.3.0/dist/select/zidan-select.js"></script>
|
|
315
|
+
<script>
|
|
316
|
+
zidanSelect('#country', {
|
|
317
|
+
mode: 'combobox',
|
|
318
|
+
placeholder: 'Search a country…',
|
|
319
|
+
clearable: true
|
|
320
|
+
});
|
|
321
|
+
zidanSelect('#sku', { mode: 'select', layout: 'soft-pill' });
|
|
322
|
+
</script>
|
|
323
|
+
</body>
|
|
324
|
+
</html>
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
Class-based auto-init also works without any call:
|
|
328
|
+
`<select class="zidan-select">` is enhanced on load by the same build.
|
|
329
|
+
|
|
330
|
+
---
|
|
331
|
+
|
|
332
|
+
## 5. Complete file-only page
|
|
333
|
+
|
|
334
|
+
Only uploads on this page? Load the file-only build. It exposes `zidanField`,
|
|
335
|
+
`initZidanForms` and the field classes; `zidanSelect` / `initZidanSelects` do not exist here.
|
|
336
|
+
|
|
337
|
+
```html
|
|
338
|
+
<!DOCTYPE html>
|
|
339
|
+
<html lang="en">
|
|
340
|
+
<head>
|
|
341
|
+
<meta charset="utf-8">
|
|
342
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
343
|
+
<title>File upload example</title>
|
|
344
|
+
<link rel="stylesheet"
|
|
345
|
+
href="https://cdn.jsdelivr.net/npm/zidan-select@2.3.0/dist/file/plugin-file-core.css">
|
|
346
|
+
<link rel="stylesheet"
|
|
347
|
+
href="https://cdn.jsdelivr.net/npm/zidan-select@2.3.0/dist/file/plugin-file-theme.css">
|
|
348
|
+
</head>
|
|
349
|
+
<body style="max-width:520px;margin:40px auto;padding:0 20px">
|
|
350
|
+
|
|
351
|
+
<form id="app" method="post">
|
|
352
|
+
<label for="cv">CV (PDF, max 5 MB)</label>
|
|
353
|
+
<input id="cv" type="file" name="cv" accept=".pdf">
|
|
354
|
+
|
|
355
|
+
<label for="shots">Screenshots</label>
|
|
356
|
+
<input id="shots" type="file" name="shots" multiple accept="image/*">
|
|
357
|
+
</form>
|
|
358
|
+
|
|
359
|
+
<script src="https://cdn.jsdelivr.net/npm/zidan-select@2.3.0/dist/file/zidan-file.js"></script>
|
|
360
|
+
<script>
|
|
361
|
+
zidanField('#cv', {
|
|
362
|
+
variant: 'dropzone',
|
|
363
|
+
title: 'Drop your CV here',
|
|
364
|
+
maxFiles: 1,
|
|
365
|
+
maxSizeMB: 5,
|
|
366
|
+
simulateUpload: true // demo progress; use uploadUrl or upload() for real uploads
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
zidanField('#shots', { variant: 'gallery', maxFiles: 6 });
|
|
370
|
+
</script>
|
|
371
|
+
</body>
|
|
372
|
+
</html>
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
Real upload endpoint instead of the fake progress:
|
|
376
|
+
|
|
377
|
+
```js
|
|
378
|
+
zidanField('#cv', {
|
|
379
|
+
uploadUrl: '/upload.php', // XHR multipart, one request per file
|
|
380
|
+
maxFiles: 1,
|
|
381
|
+
maxSizeMB: 5
|
|
382
|
+
});
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
---
|
|
386
|
+
|
|
387
|
+
## 6. Enhance by ID or class from JavaScript
|
|
388
|
+
|
|
389
|
+
`zidanSelect()` and `zidanField()` both accept a CSS selector, an element, or a NodeList.
|
|
390
|
+
A selector that matches once returns an instance; several matches return an array.
|
|
391
|
+
|
|
392
|
+
```html
|
|
393
|
+
<!-- selects -->
|
|
394
|
+
<select id="country">…</select>
|
|
395
|
+
<select class="variant-select" data-sku="a1">…</select>
|
|
396
|
+
<select class="variant-select" data-sku="b2">…</select>
|
|
397
|
+
|
|
398
|
+
<!-- fields -->
|
|
399
|
+
<input id="email" type="email">
|
|
400
|
+
<fieldset id="delivery">
|
|
401
|
+
<legend>Delivery</legend>
|
|
402
|
+
<label><input type="radio" name="delivery" value="home" checked> Home</label>
|
|
403
|
+
<label><input type="radio" name="delivery" value="locker"> Locker</label>
|
|
404
|
+
</fieldset>
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
```js
|
|
408
|
+
// by ID
|
|
409
|
+
zidanSelect('#country', { mode: 'combobox' });
|
|
410
|
+
|
|
411
|
+
// by class — returns an array when there is more than one match
|
|
412
|
+
var variants = zidanSelect('.variant-select', { layout: 'floating-label' });
|
|
413
|
+
|
|
414
|
+
// a radio group must be attached to its <fieldset>
|
|
415
|
+
zidanField('#delivery', { variant: 'tile' });
|
|
416
|
+
|
|
417
|
+
// read values later; the native controls always hold the truth
|
|
418
|
+
ZidanSelect.get('#country').getValue();
|
|
419
|
+
ZidanForm.get('#email').getValue();
|
|
420
|
+
document.querySelector('#email').value;
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
If the script sits in `<head>`, wait for the DOM (or use `defer`):
|
|
424
|
+
|
|
425
|
+
```html
|
|
426
|
+
<script src="assets/zidan/zidan-form.js" defer></script>
|
|
427
|
+
<script>
|
|
428
|
+
document.addEventListener('DOMContentLoaded', function () {
|
|
429
|
+
zidanSelect('#country', { mode: 'tags' });
|
|
430
|
+
});
|
|
431
|
+
</script>
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
If the markup is injected later (AJAX, modal, template engine), call one of:
|
|
435
|
+
|
|
436
|
+
```js
|
|
437
|
+
ZidanForm.init(scope); // enhance anything new inside scope
|
|
438
|
+
ZidanForm.refresh(scope); // enhance + update sizes of existing instances
|
|
439
|
+
ZidanForm.observe(scope); // keep watching a container automatically
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
Each of these takes an **element** (`document.querySelector('#checkout')`), not a selector
|
|
443
|
+
string. For a page-wide pass use `document.body`.
|
|
444
|
+
|
|
445
|
+
---
|
|
446
|
+
|
|
447
|
+
## 7. WordPress
|
|
448
|
+
|
|
449
|
+
WordPress needs two things: the four files reachable from the browser, and a block/template
|
|
450
|
+
with the markup. Use a **child theme** (or a tiny must-use plugin) so theme updates do not wipe
|
|
451
|
+
the files.
|
|
452
|
+
|
|
453
|
+
### 7a. Put the files in place
|
|
454
|
+
|
|
455
|
+
Upload with FTP/SFTP or the hosting file manager:
|
|
456
|
+
|
|
457
|
+
```
|
|
458
|
+
wp-content/themes/your-child-theme/
|
|
459
|
+
└─ assets/zidan/
|
|
460
|
+
├─ zidan-form.js
|
|
461
|
+
├─ plugin-core.css
|
|
462
|
+
└─ plugin-theme.css
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
### 7b. Enqueue them from `functions.php`
|
|
466
|
+
|
|
467
|
+
```php
|
|
468
|
+
<?php
|
|
469
|
+
// wp-content/themes/your-child-theme/functions.php
|
|
470
|
+
add_action('wp_enqueue_scripts', function () {
|
|
471
|
+
// Load only on the pages that contain the form.
|
|
472
|
+
if (!is_page(array('contact', 'get-a-quote'))) {
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
$base = get_stylesheet_directory_uri() . '/assets/zidan';
|
|
477
|
+
|
|
478
|
+
wp_enqueue_style('zidan-core', $base . '/plugin-core.css', array(), '2.3.0');
|
|
479
|
+
wp_enqueue_style('zidan-theme', $base . '/plugin-theme.css', array('zidan-core'), '2.3.0');
|
|
480
|
+
wp_enqueue_script('zidan-form', $base . '/zidan-form.js', array(), '2.3.0', true);
|
|
481
|
+
|
|
482
|
+
// Optional: configure fields by ID/class without inline HTML scripts.
|
|
483
|
+
wp_add_inline_script('zidan-form', "window.ZIDAN_FORM_CONFIG = {
|
|
484
|
+
targets: ['#country'],
|
|
485
|
+
fieldTargets: [
|
|
486
|
+
{ selector: '#email', options: { icon: 'mail', clearable: true } }
|
|
487
|
+
]
|
|
488
|
+
};", 'before');
|
|
489
|
+
});
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
Prefer a CDN? Replace the three `$base . '…'` URLs with the pinned jsDelivr URLs from
|
|
493
|
+
[section 1](#1-pick-the-files-first); the enqueue calls stay the same.
|
|
494
|
+
|
|
495
|
+
### 7c. Add the form markup
|
|
496
|
+
|
|
497
|
+
Paste this into a **Custom HTML block** (Gutenberg) or an Elementor **HTML widget**:
|
|
498
|
+
|
|
499
|
+
```html
|
|
500
|
+
<form class="zidan-form" method="post" action="/contact-thanks/">
|
|
501
|
+
<label for="country">Country</label>
|
|
502
|
+
<select id="country" name="country" required>
|
|
503
|
+
<option value="">Choose…</option>
|
|
504
|
+
<option>United Kingdom</option>
|
|
505
|
+
<option>Germany</option>
|
|
506
|
+
</select>
|
|
507
|
+
|
|
508
|
+
<label for="email">Email</label>
|
|
509
|
+
<input id="email" type="email" name="email" required data-zidan="input">
|
|
510
|
+
|
|
511
|
+
<label for="cv">CV</label>
|
|
512
|
+
<input id="cv" type="file" name="cv" accept=".pdf"
|
|
513
|
+
data-zidan="file" data-zidan-max-size-mb="5">
|
|
514
|
+
|
|
515
|
+
<button type="submit">Send</button>
|
|
516
|
+
</form>
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
`class="zidan-form"` is enough to enhance the select and the file input; the email input needs
|
|
520
|
+
its `data-zidan="input"` attribute. No script goes into the page itself — the enqueued file
|
|
521
|
+
auto-initialises.
|
|
522
|
+
|
|
523
|
+
### 7d. WordPress caveats
|
|
524
|
+
|
|
525
|
+
- **Plugin/theme already loads ZidanForm?** Do not enqueue a second copy. The guard keeps the
|
|
526
|
+
first one, but duplicate files double the download.
|
|
527
|
+
- **Caching/optimisation plugins** (Autoptimize, WP Rocket, LiteSpeed) may combine or defer the
|
|
528
|
+
script. If nothing is enhanced, check the page source for `zidan-form`; exclude the three
|
|
529
|
+
files from combination/minification while debugging.
|
|
530
|
+
- **Contact Form 7 / Gravity Forms / WPForms** generate their own markup and CSS. ZidanForm can
|
|
531
|
+
lift selects inside those forms with `formTargets: ['#their-form-id']`, but visual conflicts
|
|
532
|
+
are likely; test one form before applying it site-wide.
|
|
533
|
+
- **Page builders** usually preserve `data-*` attributes. If a builder strips them, keep the
|
|
534
|
+
element IDs and initialise through `ZIDAN_FORM_CONFIG.targets` instead.
|
|
535
|
+
- **CSS order**: framework CSS → `plugin-core.css` → `plugin-theme.css` → child-theme overrides.
|
|
536
|
+
On Bootstrap/Tailwind sites also set `data-zidan-framework="bootstrap"` (or `"tailwind"`) on
|
|
537
|
+
`<html>` or the form.
|
|
538
|
+
|
|
539
|
+
---
|
|
540
|
+
|
|
541
|
+
## 8. Other hosts and website builders
|
|
542
|
+
|
|
543
|
+
**Netlify, Vercel, GitHub Pages, plain shared hosting** — nothing special: keep the HTML and
|
|
544
|
+
`assets/zidan/` in the same folder tree and use relative paths, exactly as in section 3.
|
|
545
|
+
|
|
546
|
+
**Blogger, Squarespace, Wix, Webflow** — add the `<script src>` and
|
|
547
|
+
CSS links inside their "code injection" area (site-wide) or a single embed block, then place the
|
|
548
|
+
markup in the page. If the platform only allows one embed block, put the `<script src>` call
|
|
549
|
+
**after** the markup in that same block; a `<script>` tag in an embed runs normally.
|
|
550
|
+
Shopify has its own section: [9. Shopify](#9-shopify).
|
|
551
|
+
|
|
552
|
+
```html
|
|
553
|
+
<!-- inside one embed block: markup first, script last -->
|
|
554
|
+
<select class="zidan-select" data-zidan-options='{"mode":"combobox"}'>…</select>
|
|
555
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/zidan-select@2.3.0/plugin-core.css">
|
|
556
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/zidan-select@2.3.0/plugin-theme.css">
|
|
557
|
+
<script src="https://cdn.jsdelivr.net/npm/zidan-select@2.3.0/zidan-form.js"></script>
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
For the single-select case, the select-only build is smaller: swap in the
|
|
561
|
+
`dist/select/` files from section 4.
|
|
562
|
+
|
|
563
|
+
---
|
|
564
|
+
|
|
565
|
+
## 9. Shopify
|
|
566
|
+
|
|
567
|
+
ZidanForm works in **storefront theme templates** — product pages, contact forms, newsletter
|
|
568
|
+
signups, cart notes. It does **not** work on the Shopify checkout (custom scripts are blocked
|
|
569
|
+
there; use Checkout UI Extensions) or in the Shopify admin (that uses Polaris).
|
|
570
|
+
|
|
571
|
+
A runnable mock product page lives at
|
|
572
|
+
<https://akhtar1985.github.io/zidan-select/shopify.html> — variant combobox, quantity stepper,
|
|
573
|
+
gift-wrap switch, tile radios and an upload dropzone, with the Liquid snippets below on the page.
|
|
574
|
+
|
|
575
|
+
### 9a. Add the files to the theme
|
|
576
|
+
|
|
577
|
+
1. Online Store → Themes → **Edit code** → **Assets** → **Add a new asset**, upload
|
|
578
|
+
`zidan-form.js`, `plugin-core.css` and `plugin-theme.css` (or the select-only build if only
|
|
579
|
+
selects are needed).
|
|
580
|
+
2. Reference them in `layout/theme.liquid`, after the theme's base stylesheet:
|
|
581
|
+
|
|
582
|
+
```liquid
|
|
583
|
+
{{ 'plugin-core.css' | asset_url | stylesheet_tag }}
|
|
584
|
+
{{ 'plugin-theme.css' | asset_url | stylesheet_tag }}
|
|
585
|
+
<script src="{{ 'zidan-form.js' | asset_url }}" defer></script>
|
|
586
|
+
```
|
|
587
|
+
|
|
588
|
+
`asset_url` serves the files from Shopify's CDN, so no external host is required. CSS order:
|
|
589
|
+
theme base styles → `plugin-core.css` → `plugin-theme.css` → your overrides.
|
|
590
|
+
|
|
591
|
+
### 9b. Product form
|
|
592
|
+
|
|
593
|
+
Liquid renders the variants; ZidanForm only upgrades the control. The real `<select>` stays in
|
|
594
|
+
the DOM, so `change` listeners (Dawn's price/availability updates) keep working.
|
|
595
|
+
|
|
596
|
+
```liquid
|
|
597
|
+
<form action="{{ routes.cart_add_url }}" method="post" class="zidan-form">
|
|
598
|
+
<input type="hidden" name="form_type" value="product">
|
|
599
|
+
<input type="hidden" name="utf8" value="✓">
|
|
600
|
+
|
|
601
|
+
<label for="variant-select">Size</label>
|
|
602
|
+
<select id="variant-select" name="id" class="zidan-select"
|
|
603
|
+
data-zidan-options='{"mode":"combobox","placeholder":"Choose a size…"}'>
|
|
604
|
+
{% for variant in product.variants %}
|
|
605
|
+
<option value="{{ variant.id }}"
|
|
606
|
+
{% if variant == product.selected_or_first_available_variant %}selected{% endif %}
|
|
607
|
+
{% unless variant.available %}disabled{% endunless %}>
|
|
608
|
+
{{ variant.title }} — {{ variant.price | money }}
|
|
609
|
+
</option>
|
|
610
|
+
{% endfor %}
|
|
611
|
+
</select>
|
|
612
|
+
|
|
613
|
+
<label for="quantity">Quantity</label>
|
|
614
|
+
<input id="quantity" type="number" name="quantity" value="1" min="1" max="20"
|
|
615
|
+
data-zidan="input" data-zidan-stepper="stacked">
|
|
616
|
+
|
|
617
|
+
<label>
|
|
618
|
+
<input type="checkbox" name="properties[Gift wrap]" value="Yes"
|
|
619
|
+
data-zidan="checkbox" data-zidan-variant="switch"
|
|
620
|
+
data-zidan-label="Gift wrap">
|
|
621
|
+
</label>
|
|
622
|
+
|
|
623
|
+
<button type="submit" name="add">Add to cart</button>
|
|
624
|
+
</form>
|
|
625
|
+
```
|
|
626
|
+
|
|
627
|
+
> **Dawn users:** Dawn's `variant-selects` component owns its markup and JS. Use this markup in
|
|
628
|
+
> a custom section, or remove Dawn's variant picker before adding yours — do not run both on the
|
|
629
|
+
> same select. Line-item properties (`properties[...]`) are ordinary form fields and post with
|
|
630
|
+
> the form.
|
|
631
|
+
|
|
632
|
+
### 9c. Contact and newsletter forms
|
|
633
|
+
|
|
634
|
+
```liquid
|
|
635
|
+
{% form 'contact', class: 'zidan-form' %}
|
|
636
|
+
<input type="email" name="contact[email]" required
|
|
637
|
+
data-zidan="input" data-zidan-auto-icon="true" data-zidan-clear>
|
|
638
|
+
<textarea name="contact[body]" rows="4" maxlength="400"
|
|
639
|
+
data-zidan="textarea" data-zidan-counter="400"></textarea>
|
|
640
|
+
<button type="submit">Send</button>
|
|
641
|
+
{% endform %}
|
|
642
|
+
|
|
643
|
+
{% form 'customer', class: 'zidan-form' %}
|
|
644
|
+
<input type="hidden" name="contact[tags]" value="newsletter">
|
|
645
|
+
<input type="email" name="contact[email]" required
|
|
646
|
+
data-zidan="input" data-zidan-clear>
|
|
647
|
+
<button type="submit">Subscribe</button>
|
|
648
|
+
{% endform %}
|
|
649
|
+
```
|
|
650
|
+
|
|
651
|
+
### 9d. Field theme from the theme editor
|
|
652
|
+
|
|
653
|
+
Expose the preset in a section setting so merchants can switch it without editing code:
|
|
654
|
+
|
|
655
|
+
```liquid
|
|
656
|
+
{% schema %}
|
|
657
|
+
{
|
|
658
|
+
"name": "ZidanForm style",
|
|
659
|
+
"settings": [
|
|
660
|
+
{
|
|
661
|
+
"type": "select",
|
|
662
|
+
"id": "zidan_theme",
|
|
663
|
+
"label": "Field theme",
|
|
664
|
+
"options": [
|
|
665
|
+
{"value": "default", "label": "Default"},
|
|
666
|
+
{"value": "modern", "label": "Modern"},
|
|
667
|
+
{"value": "minimal", "label": "Minimal"},
|
|
668
|
+
{"value": "dark", "label": "Dark"},
|
|
669
|
+
{"value": "glass", "label": "Glass"}
|
|
670
|
+
],
|
|
671
|
+
"default": "modern"
|
|
672
|
+
}
|
|
673
|
+
]
|
|
674
|
+
}
|
|
675
|
+
{% endschema %}
|
|
676
|
+
|
|
677
|
+
<div data-zidan-theme="{{ section.settings.zidan_theme }}">
|
|
678
|
+
{% comment %} your form markup {% endcomment %}
|
|
679
|
+
</div>
|
|
680
|
+
```
|
|
681
|
+
|
|
682
|
+
### 9e. File uploads: app proxy plus a hidden property
|
|
683
|
+
|
|
684
|
+
Shopify's cart and order forms cannot carry a file. Upload through an **app proxy**
|
|
685
|
+
(`/apps/your-app/upload` forwards to your server), then put the resulting URL into a line-item
|
|
686
|
+
property so it reaches the order:
|
|
687
|
+
|
|
688
|
+
```liquid
|
|
689
|
+
<input type="file" id="artwork" data-zidan="file"
|
|
690
|
+
data-zidan-max-size-mb="8" data-zidan-title="Drop your artwork">
|
|
691
|
+
<input type="hidden" name="properties[Artwork URL]" id="artwork-url">
|
|
692
|
+
```
|
|
693
|
+
|
|
694
|
+
```js
|
|
695
|
+
zidanField('#artwork', {
|
|
696
|
+
upload: function (file, context) {
|
|
697
|
+
var body = new FormData();
|
|
698
|
+
body.append('file', file);
|
|
699
|
+
fetch('/apps/your-app/upload', { method: 'POST', body: body, signal: context.signal })
|
|
700
|
+
.then(function (response) {
|
|
701
|
+
return response.ok ? response.json() : Promise.reject(response.status);
|
|
702
|
+
})
|
|
703
|
+
.then(function (json) {
|
|
704
|
+
context.complete(json);
|
|
705
|
+
document.getElementById('artwork-url').value = json.url;
|
|
706
|
+
})
|
|
707
|
+
.catch(context.fail);
|
|
708
|
+
}
|
|
709
|
+
});
|
|
710
|
+
```
|
|
711
|
+
|
|
712
|
+
Never mark the upload as `autoUpload` on a price-bearing form unless the upload endpoint is
|
|
713
|
+
ready — the property field stays empty until the upload completes.
|
|
714
|
+
|
|
715
|
+
### 9f. Headless storefronts (Hydrogen, Remix, Next.js)
|
|
716
|
+
|
|
717
|
+
Use the npm package and the framework lifecycle patterns from [frameworks.md](frameworks.md):
|
|
718
|
+
|
|
719
|
+
```jsx
|
|
720
|
+
import { useEffect, useRef } from 'react';
|
|
721
|
+
import { zidanSelect } from 'zidan-select';
|
|
722
|
+
import 'zidan-select/css/core';
|
|
723
|
+
import 'zidan-select/css/theme';
|
|
724
|
+
|
|
725
|
+
export function VariantPicker() {
|
|
726
|
+
const ref = useRef(null);
|
|
727
|
+
useEffect(() => {
|
|
728
|
+
const instance = zidanSelect(ref.current, { mode: 'combobox' });
|
|
729
|
+
return () => instance.destroy();
|
|
730
|
+
}, []);
|
|
731
|
+
return <select ref={ref} name="id">{/* variant options */}</select>;
|
|
732
|
+
}
|
|
733
|
+
```
|
|
734
|
+
|
|
735
|
+
### 9g. Shopify caveats
|
|
736
|
+
|
|
737
|
+
- **Checkout is off-limits.** Theme code cannot run there. For Plus stores, `checkout.liquid` is
|
|
738
|
+
deprecated — use Checkout UI Extensions.
|
|
739
|
+
- **Shipping to many merchants?** Package the assets in a theme app extension's app-embed block
|
|
740
|
+
instead of editing each theme; the embed block can inject the CSS/JS on the storefront.
|
|
741
|
+
- **Two copies of the library**: some apps ship ZidanForm themselves. Check
|
|
742
|
+
`window.ZidanForm` in the console before enqueuing your own copy.
|
|
743
|
+
- **CSP and asset URLs** are not an issue for theme assets served by `asset_url`.
|
|
744
|
+
|
|
745
|
+
---
|
|
746
|
+
|
|
747
|
+
## 10. Copy-paste recipes
|
|
748
|
+
|
|
749
|
+
Change the theme for one area (or set it on `<html>` for the whole site):
|
|
750
|
+
|
|
751
|
+
```html
|
|
752
|
+
<html data-zidan-theme="modern">
|
|
753
|
+
<!-- or -->
|
|
754
|
+
<form class="zidan-form" data-zidan-theme="dark" data-zidan-layout="floating">
|
|
755
|
+
```
|
|
756
|
+
|
|
757
|
+
Match an existing CSS framework:
|
|
758
|
+
|
|
759
|
+
```html
|
|
760
|
+
<html data-zidan-framework="bootstrap"> <!-- or tailwind / bulma / foundation -->
|
|
761
|
+
```
|
|
762
|
+
|
|
763
|
+
Searchable combobox:
|
|
764
|
+
|
|
765
|
+
```html
|
|
766
|
+
<select name="city" class="zidan-select"
|
|
767
|
+
data-zidan-options='{"mode":"combobox","searchable":true,"clearable":true}'>…</select>
|
|
768
|
+
```
|
|
769
|
+
|
|
770
|
+
Tags input (Enter commits, Backspace removes the last tag):
|
|
771
|
+
|
|
772
|
+
```html
|
|
773
|
+
<select name="skills" class="zidan-select" multiple
|
|
774
|
+
data-zidan-options='{"mode":"tags","maxTags":5,"placeholder":"Type a skill…"}'>…</select>
|
|
775
|
+
```
|
|
776
|
+
|
|
777
|
+
Phone input with country selector:
|
|
778
|
+
|
|
779
|
+
```html
|
|
780
|
+
<input type="tel" name="phone" data-zidan="input" data-zidan-phone="true"
|
|
781
|
+
data-zidan-phone-country="US" data-zidan-phone-format="national">
|
|
782
|
+
```
|
|
783
|
+
|
|
784
|
+
Number stepper with a hold-to-repeat button:
|
|
785
|
+
|
|
786
|
+
```html
|
|
787
|
+
<input type="number" name="qty" min="1" max="20" value="1" data-zidan="input"
|
|
788
|
+
data-zidan-stepper="split" data-zidan-stepper-long-press="true">
|
|
789
|
+
```
|
|
790
|
+
|
|
791
|
+
Range with a live output:
|
|
792
|
+
|
|
793
|
+
```html
|
|
794
|
+
<input type="range" name="budget" min="0" max="500" step="10" value="200"
|
|
795
|
+
data-zidan="input" data-zidan-output="#budget-out">
|
|
796
|
+
<output id="budget-out">200</output>
|
|
797
|
+
```
|
|
798
|
+
|
|
799
|
+
Text field with prefix, suffix, counter and clear button:
|
|
800
|
+
|
|
801
|
+
```html
|
|
802
|
+
<input type="text" name="amount" maxlength="12"
|
|
803
|
+
data-zidan="input" data-zidan-prefix="$" data-zidan-suffix="USD"
|
|
804
|
+
data-zidan-counter="12" data-zidan-clear>
|
|
805
|
+
```
|
|
806
|
+
|
|
807
|
+
Switch and card-style checkbox:
|
|
808
|
+
|
|
809
|
+
```html
|
|
810
|
+
<input type="checkbox" name="news" data-zidan="checkbox" data-zidan-variant="switch">
|
|
811
|
+
|
|
812
|
+
<label>
|
|
813
|
+
<input type="checkbox" name="plan" value="pro" data-zidan="checkbox"
|
|
814
|
+
data-zidan-variant="card" data-zidan-label="Pro plan"
|
|
815
|
+
data-zidan-description="Unlimited projects">
|
|
816
|
+
</label>
|
|
817
|
+
```
|
|
818
|
+
|
|
819
|
+
Card-style radio group (put the attributes on the `<fieldset>`):
|
|
820
|
+
|
|
821
|
+
```html
|
|
822
|
+
<fieldset data-zidan="radio-group" data-zidan-variant="tile">
|
|
823
|
+
<legend>Plan</legend>
|
|
824
|
+
<label><input type="radio" name="plan" value="starter" checked> Starter</label>
|
|
825
|
+
<label><input type="radio" name="plan" value="pro"> Pro</label>
|
|
826
|
+
</fieldset>
|
|
827
|
+
```
|
|
828
|
+
|
|
829
|
+
File uploads: dropzone with limits, avatar, gallery:
|
|
830
|
+
|
|
831
|
+
```html
|
|
832
|
+
<input type="file" name="docs" multiple accept=".pdf,image/*" data-zidan="file"
|
|
833
|
+
data-zidan-max-files="3" data-zidan-max-size-mb="5"
|
|
834
|
+
data-zidan-title="Drop documents here">
|
|
835
|
+
|
|
836
|
+
<input type="file" name="avatar" accept="image/*" data-zidan="file"
|
|
837
|
+
data-zidan-file-variant="avatar">
|
|
838
|
+
|
|
839
|
+
<input type="file" name="shots" multiple accept="image/*" data-zidan="file"
|
|
840
|
+
data-zidan-file-variant="gallery">
|
|
841
|
+
```
|
|
842
|
+
|
|
843
|
+
Upload to your own endpoint (no JS needed):
|
|
844
|
+
|
|
845
|
+
```html
|
|
846
|
+
<input type="file" name="cv" data-zidan="file" data-zidan-upload-url="/upload.php"
|
|
847
|
+
data-zidan-max-size-mb="5">
|
|
848
|
+
```
|
|
849
|
+
|
|
850
|
+
Custom uploader in JS (fetch, with abort and progress):
|
|
851
|
+
|
|
852
|
+
```js
|
|
853
|
+
zidanField('#cv', {
|
|
854
|
+
upload: function (file, context) {
|
|
855
|
+
fetch('/api/upload', {
|
|
856
|
+
method: 'POST',
|
|
857
|
+
body: context.formData,
|
|
858
|
+
signal: context.signal
|
|
859
|
+
}).then(function (response) {
|
|
860
|
+
return response.ok ? response.json() : Promise.reject(response.status);
|
|
861
|
+
}).then(context.complete).catch(context.fail);
|
|
862
|
+
}
|
|
863
|
+
});
|
|
864
|
+
```
|
|
865
|
+
|
|
866
|
+
---
|
|
867
|
+
|
|
868
|
+
## 11. Troubleshooting
|
|
869
|
+
|
|
870
|
+
| Symptom | Likely cause and fix |
|
|
871
|
+
| --- | --- |
|
|
872
|
+
| Controls still look native | CSS 404 — open DevTools → Network and check both stylesheets load. `plugin-core.css` alone is not enough. |
|
|
873
|
+
| Nothing is enhanced, console is clean | Script 404, or the file was loaded twice and ignored. Check the `src` path and search the page source for a second copy. |
|
|
874
|
+
| `ZidanSelect: target element not found` | The call ran before the markup, or the selector is wrong (IDs are case-sensitive). Move the script to the end of `<body>`, add `defer`, or wrap in `DOMContentLoaded`. |
|
|
875
|
+
| Some fields work, others do not | The untouched ones lack `data-zidan*`/`zidan-field`. Unmarked file inputs are only picked up inside `.zidan-form`. Compare with section 2. |
|
|
876
|
+
| `data-zidan-options` is ignored | Use single quotes for the attribute and double quotes inside the JSON. Only literal values are allowed; check the console for the warning. |
|
|
877
|
+
| Posted value is empty | Give the native control a `name`. The visible widget mirrors the real `<select>`/`<input>`. |
|
|
878
|
+
| File upload stays at 0% | No endpoint configured. Add `data-zidan-upload-url` / `uploadUrl`, or `simulateUpload: true` for demos. |
|
|
879
|
+
| Styles clash with Bootstrap/Tailwind | Set `data-zidan-framework="bootstrap"` (or `tailwind`) on `<html>` or the form; load theme CSS after the framework CSS. |
|
|
880
|
+
| WordPress: nothing loads | A caching/optimisation plugin moved or combined the files. View the page source for `zidan-form`; exclude the files and purge the cache. |
|
|
881
|
+
| WordPress: form plugin styles fight back | Start with `formTargets: ['#form-id']` on one form instead of site-wide marker classes. |
|
|
882
|
+
| Shopify: controls stay native | The theme asset is not referenced in `layout/theme.liquid`, or a theme-cache/CDN is serving an old layout. Check the page source for `asset_url` output and the three files. |
|
|
883
|
+
|
|
884
|
+
---
|
|
885
|
+
|
|
886
|
+
## What next
|
|
887
|
+
|
|
888
|
+
- Every option and data attribute: [options.md](options.md)
|
|
889
|
+
- Native, jQuery Validation, JustValidate and Parsley: [validation.md](validation.md)
|
|
890
|
+
- Tokens, presets, layouts and adapters: [theming.md](theming.md)
|
|
891
|
+
- React, Vue, Angular and Next.js: [frameworks.md](frameworks.md)
|
|
892
|
+
- Click through one control at a time: [field playground](https://akhtar1985.github.io/zidan-select/playground.html)
|
|
893
|
+
- More trimmed-build details: [build.md](build.md#select-only-and-file-only-builds)
|