zidan-select 0.0.0-stage → 2.0.2
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/LICENSE +21 -0
- package/README.md +581 -2
- package/dist/plugin-core.css +1073 -0
- package/dist/plugin-theme.css +1277 -0
- package/dist/zidan-form.cjs +2 -0
- package/dist/zidan-form.js +3047 -0
- package/dist/zidan-form.mjs +31 -0
- package/docs/build.md +145 -0
- package/docs/comparison.md +76 -0
- package/docs/frameworks.md +234 -0
- package/docs/index.html +76 -0
- package/docs/options.md +193 -0
- package/docs/theming.md +225 -0
- package/docs/validation.html +200 -0
- package/docs/validation.md +215 -0
- package/package.json +69 -4
- package/plugin-core.css +1073 -0
- package/plugin-theme.css +1277 -0
- package/zidan-form.js +3047 -0
- package/zidan-form.mjs +31 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 akhtar1985
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,582 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ZidanForm
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Zero-dependency form enhancement for the browser. Upgrade native `<select>`, checkbox,
|
|
4
|
+
switch, radio, file and text inputs **in place** — real form values, `FormData`,
|
|
5
|
+
`form.reset()` and constraint validation keep working, while structure and theme live in
|
|
6
|
+
two separate stylesheets.
|
|
7
|
+
|
|
8
|
+
[](https://akhtar1985.github.io/zidan-select/)
|
|
9
|
+
[](https://www.npmjs.com/package/zidan-select)
|
|
10
|
+
[](LICENSE)
|
|
11
|
+
|
|
12
|
+
- **One file of JS** — `zidan-form.js` (classic script, UMD-ish) + `zidan-form.mjs` (ESM wrapper).
|
|
13
|
+
- **Split CSS** — `plugin-core.css` (structure only) and `plugin-theme.css` (tokens, presets, skins).
|
|
14
|
+
- **Opt-in per control** — nothing is touched unless it carries a `data-zidan*` attribute or is
|
|
15
|
+
passed to the API.
|
|
16
|
+
- **Native-first** — the real input stays in the DOM at 1×1 px (never `display:none`), so
|
|
17
|
+
`FormData`, `reset()`, `required`, `:invalid` and jQuery Validation's `:hidden` ignore behave.
|
|
18
|
+
- **5 themes** `default · modern · minimal · dark · glass`.
|
|
19
|
+
- **5 select layouts** `classic-clean · floating-label · soft-pill · bordered-brutalist · glass-elevated`.
|
|
20
|
+
- **Field layouts** `stacked · inline · compact · floating · outlined · card`.
|
|
21
|
+
- **Framework adapters** standalone, Bootstrap 5, Tailwind CSS, Bulma, Foundation.
|
|
22
|
+
- WAI-ARIA labels, focus management, keyboard support throughout, `prefers-reduced-motion`.
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Why ZidanForm
|
|
27
|
+
|
|
28
|
+
Most form libraries fix one control. ZidanForm upgrades the whole form with the same API,
|
|
29
|
+
the same two stylesheets and no dependencies.
|
|
30
|
+
|
|
31
|
+
| | ZidanForm | Select2 | Choices.js | Tom Select | Slim Select |
|
|
32
|
+
| --- | --- | --- | --- | --- | --- |
|
|
33
|
+
| Runtime dependencies | **None** | jQuery | None | None | None |
|
|
34
|
+
| Controls covered | **Select, checkbox, switch, radio, file, text** | Select / tags | Select, text, tags | Select / tags | Select |
|
|
35
|
+
| Drag & drop file upload | **Built in** | — | — | — | — |
|
|
36
|
+
| Split structure / theme CSS | **Yes** | Partial | Partial | Partial | Partial |
|
|
37
|
+
| Validation coexistence tested | **Native, jQuery Validation, JustValidate, Parsley** | — | — | — | — |
|
|
38
|
+
| CSS-framework adapters | **Bootstrap, Tailwind, Bulma, Foundation** | — | — | — | — |
|
|
39
|
+
|
|
40
|
+
**Benefits**
|
|
41
|
+
|
|
42
|
+
- **One library for every control** — no mix of Select2 + Dropzone + custom checkbox CSS.
|
|
43
|
+
- **Native behavior survives** — `FormData`, `reset()`, `required`, `:invalid` and
|
|
44
|
+
`input.files` keep working because the real control is never `display:none`.
|
|
45
|
+
- **Themeable without forking** — structure lives in `plugin-core.css`, colours and skins in
|
|
46
|
+
`plugin-theme.css`; five presets plus your own tokens.
|
|
47
|
+
- **Fits existing validation** — jQuery Validation, JustValidate, Parsley and native HTML5 are
|
|
48
|
+
documented and tested, with `aria-invalid` sync and double-submit guards.
|
|
49
|
+
- **Opt-in and reversible** — enhance only `data-zidan*` controls; `destroy()` restores markup.
|
|
50
|
+
- **No build step** — classic script, ESM wrapper and plain CSS.
|
|
51
|
+
|
|
52
|
+
**Trade-offs:** smaller community than Select2, no React/Vue component package, and advanced
|
|
53
|
+
remote-search plugins are better served by Select2 or Tom Select. Full matrix, honest
|
|
54
|
+
limitations and migration notes: **[`docs/comparison.md`](docs/comparison.md)**.
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Contents
|
|
59
|
+
|
|
60
|
+
1. [Install](#install)
|
|
61
|
+
2. [Why ZidanForm](#why-zidanform)
|
|
62
|
+
3. [Quick start](#quick-start)
|
|
63
|
+
4. [Input types](#input-types)
|
|
64
|
+
5. [Options & data attributes](#options--data-attributes)
|
|
65
|
+
6. [JavaScript API](#javascript-api)
|
|
66
|
+
7. [Themes, layouts & frameworks](#themes-layouts--frameworks)
|
|
67
|
+
8. [Validation libraries](#validation-libraries)
|
|
68
|
+
9. [Form lifecycle & state sync](#form-lifecycle--state-sync)
|
|
69
|
+
10. [React, Next.js, Vue, Angular](#react-nextjs-vue-angular)
|
|
70
|
+
11. [Build & publish](#build--publish)
|
|
71
|
+
12. [Browser support](#browser-support)
|
|
72
|
+
13. [Migrating from 1.x](#migrating-from-1x)
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## Install
|
|
77
|
+
|
|
78
|
+
### npm
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
npm install zidan-select
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
```js
|
|
85
|
+
// ESM
|
|
86
|
+
import ZidanForm, { initZidanForms, initZidanSelects, zidanField } from 'zidan-select';
|
|
87
|
+
import 'zidan-select/css/core';
|
|
88
|
+
import 'zidan-select/css/theme';
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
```js
|
|
92
|
+
// CommonJS
|
|
93
|
+
const { ZidanForm, initZidanForms, initZidanSelects } = require('zidan-select');
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### CDN
|
|
97
|
+
|
|
98
|
+
```html
|
|
99
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/zidan-select@2/plugin-core.css">
|
|
100
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/zidan-select@2/plugin-theme.css">
|
|
101
|
+
<script src="https://cdn.jsdelivr.net/npm/zidan-select@2/zidan-form.js"></script>
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
`plugin-core.css` must come first. Load your own theme file *after* `plugin-theme.css` to
|
|
105
|
+
override presets.
|
|
106
|
+
|
|
107
|
+
### Files
|
|
108
|
+
|
|
109
|
+
| File | Purpose |
|
|
110
|
+
| --- | --- |
|
|
111
|
+
| `zidan-form.js` | All controls. Classic `<script>` → `window.ZidanForm` (+ legacy `window.ZidanSelect`). |
|
|
112
|
+
| `zidan-form.mjs` | ES module wrapper around the same file. |
|
|
113
|
+
| `plugin-core.css` | Layout, positioning, native-input handling, mechanics. **No colours, shadows or skins.** |
|
|
114
|
+
| `plugin-theme.css` | Tokens, colours, states, presets, layout skins, framework adapters. |
|
|
115
|
+
| `index.html`, `demo.css`, `demo.js` | The tabbed demo / theme showcase (not shipped logic). |
|
|
116
|
+
| `docs/` | Comparison, options, validation, frameworks, theming and build guides. |
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## Quick start
|
|
121
|
+
|
|
122
|
+
```html
|
|
123
|
+
<link rel="stylesheet" href="plugin-core.css">
|
|
124
|
+
<link rel="stylesheet" href="plugin-theme.css">
|
|
125
|
+
|
|
126
|
+
<form>
|
|
127
|
+
<select name="country" data-zidan-select="combobox" data-zidan-label="Country">
|
|
128
|
+
<option value="">Choose…</option>
|
|
129
|
+
<option>France</option>
|
|
130
|
+
<option>Japan</option>
|
|
131
|
+
</select>
|
|
132
|
+
|
|
133
|
+
<label>
|
|
134
|
+
<input type="checkbox" name="news" data-zidan="checkbox" data-zidan-variant="switch"
|
|
135
|
+
data-zidan-label="Newsletter">
|
|
136
|
+
</label>
|
|
137
|
+
|
|
138
|
+
<fieldset data-zidan="radio-group" data-zidan-variant="inline">
|
|
139
|
+
<legend>Plan</legend>
|
|
140
|
+
<label><input type="radio" name="plan" value="starter" checked> Starter</label>
|
|
141
|
+
<label><input type="radio" name="plan" value="pro"> Pro</label>
|
|
142
|
+
</fieldset>
|
|
143
|
+
|
|
144
|
+
<input type="file" name="docs" data-zidan="file" multiple>
|
|
145
|
+
<input type="text" name="email" data-zidan="input" data-zidan-label="Email" data-zidan-clear>
|
|
146
|
+
</form>
|
|
147
|
+
|
|
148
|
+
<script src="zidan-form.js"></script>
|
|
149
|
+
<script>
|
|
150
|
+
initZidanSelects(document);
|
|
151
|
+
initZidanForms(document);
|
|
152
|
+
</script>
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Auto-init runs on `DOMContentLoaded` for `[data-zidan-select]` and `[data-zidan*]` unless
|
|
156
|
+
disabled:
|
|
157
|
+
|
|
158
|
+
```html
|
|
159
|
+
<html data-zidan-auto-init="false">
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
```js
|
|
163
|
+
window.ZIDAN_SELECT_CONFIG = { autoInit: false };
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Windows/macOS keyboard behaviour, grouping, search and all select features live in
|
|
167
|
+
[`docs/options.md`](docs/options.md).
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## Input types
|
|
172
|
+
|
|
173
|
+
### Select / combobox / tags
|
|
174
|
+
|
|
175
|
+
```html
|
|
176
|
+
<select data-zidan-select="select" data-zidan-label="Team" multiple>…</select>
|
|
177
|
+
<select data-zidan-select="combobox" data-zidan-searchable="true" data-zidan-clearable="true">…</select>
|
|
178
|
+
<select data-zidan-select="tags" data-zidan-max-tags="3" data-zidan-allow-free-text="true">…</select>
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
`optgroup` becomes listbox groups, `disabled` options stay disabled, and the native
|
|
182
|
+
`<select>` keeps the value so `FormData` and `form.reset()` are untouched. Scrollbars:
|
|
183
|
+
`default · thin · fancy · hover · hidden` via `data-zidan-scrollbar`.
|
|
184
|
+
|
|
185
|
+
### Checkbox, switch & card
|
|
186
|
+
|
|
187
|
+
```html
|
|
188
|
+
<label><input type="checkbox" data-zidan="checkbox" data-zidan-label="Remember me"></label>
|
|
189
|
+
<label><input type="checkbox" data-zidan="checkbox" data-zidan-variant="switch" data-zidan-label="Dark mode"></label>
|
|
190
|
+
<label><input type="checkbox" data-zidan="checkbox" data-zidan-variant="card" data-zidan-label="Daily backup"></label>
|
|
191
|
+
<label><input type="checkbox" data-zidan="checkbox" data-zidan-indeterminate data-zidan-label="Select all"></label>
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
`indeterminate` is native: set it in markup or with
|
|
195
|
+
`input.indeterminate = true; input.__zidanField.update()` / `field.setIndeterminate(true)`.
|
|
196
|
+
The mixed state paints a bar and clears as soon as the user clicks, exactly like a native
|
|
197
|
+
checkbox.
|
|
198
|
+
|
|
199
|
+
### Radio groups
|
|
200
|
+
|
|
201
|
+
```html
|
|
202
|
+
<fieldset data-zidan="radio-group" data-zidan-variant="card" data-zidan-label="Seat">
|
|
203
|
+
<legend>Seat</legend>
|
|
204
|
+
<label><input type="radio" name="seat" value="window" required> Window</label>
|
|
205
|
+
<label><input type="radio" name="seat" value="aisle"> Aisle</label>
|
|
206
|
+
</fieldset>
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Variants: `stacked`, `inline`, `card`. Radios share a native `name`, so arrow keys, Home/End
|
|
210
|
+
and Space keep browser semantics; the wrapper adds `role="radiogroup"` when missing.
|
|
211
|
+
|
|
212
|
+
### File upload
|
|
213
|
+
|
|
214
|
+
```html
|
|
215
|
+
<input type="file" name="docs" multiple accept="image/*,.pdf"
|
|
216
|
+
data-zidan="file"
|
|
217
|
+
data-zidan-max-files="3"
|
|
218
|
+
data-zidan-max-size="1048576"
|
|
219
|
+
data-zidan-title="Drop documents here">
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
- Native `input.files` is the source of truth; removing a file rebuilds it with `DataTransfer`.
|
|
223
|
+
- Drag & drop, click to pick, thumbnails for images, extension badges otherwise.
|
|
224
|
+
- `maxFiles`, `maxSize` (bytes) / `maxSizeMB`, `accept` are validated with a live status message.
|
|
225
|
+
- `required` works: an empty file input fails native validation as usual.
|
|
226
|
+
|
|
227
|
+
### Text inputs & textarea
|
|
228
|
+
|
|
229
|
+
```html
|
|
230
|
+
<input type="text" data-zidan="input" data-zidan-label="Amount"
|
|
231
|
+
data-zidan-prefix="$" data-zidan-suffix="USD" data-zidan-clear>
|
|
232
|
+
|
|
233
|
+
<input type="password" data-zidan="input" data-zidan-label="Password" data-zidan-reveal>
|
|
234
|
+
|
|
235
|
+
<textarea data-zidan="textarea" data-zidan-label="Message" maxlength="140"
|
|
236
|
+
data-zidan-counter="140" data-zidan-clear></textarea>
|
|
237
|
+
|
|
238
|
+
<input type="text" data-zidan="input" data-zidan-layout="floating" data-zidan-label="Company">
|
|
239
|
+
<input type="range" data-zidan="input" data-zidan-label="Budget" data-zidan-output="#budget-out">
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
Supported types: `text`, `email`, `password`, `number`, `tel`, `url`, `search`, `date`,
|
|
243
|
+
`time`, `datetime-local`, `month`, `week`, `range`, `color`, plus `<textarea>`.
|
|
244
|
+
Range inputs can mirror their value into any element with `data-zidan-output`.
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
## Options & data attributes
|
|
249
|
+
|
|
250
|
+
### Field options
|
|
251
|
+
|
|
252
|
+
| Option | Data attribute | Type | Default | Description |
|
|
253
|
+
| --- | --- | --- | --- | --- |
|
|
254
|
+
| `variant` | `data-zidan-variant` | string | `default` | Checkbox `default/switch/card`; radio `stacked/inline/card`. |
|
|
255
|
+
| `layout` | `data-zidan-layout` | string | `stacked` | `stacked`, `inline`, `compact`, `floating`, `outlined`, `card`. |
|
|
256
|
+
| `theme` | `data-zidan-theme` | string | `default` | `default`, `modern`, `minimal`, `dark`, `glass`. |
|
|
257
|
+
| `framework` | `data-zidan-framework` | string | `none` | `none`, `bootstrap`, `tailwind`, `bulma`, `foundation`. |
|
|
258
|
+
| `label` | `data-zidan-label` | string | — | Label when no `<label>` exists. |
|
|
259
|
+
| `hint` | `data-zidan-hint` | string | — | Helper text; linked with `aria-describedby`. |
|
|
260
|
+
| `validation` | `data-zidan-validation` | `valid` \| `invalid` | — | Initial state. |
|
|
261
|
+
| `indeterminate` | `data-zidan-indeterminate` | boolean | `false` | Start mixed. |
|
|
262
|
+
| `clearable` | `data-zidan-clear` | boolean | `search` only | Clear button. |
|
|
263
|
+
| `reveal` | `data-zidan-reveal` | boolean | `false` | Password show/hide. |
|
|
264
|
+
| `prefix` / `suffix` | `data-zidan-prefix` / `-suffix` | string | — | Static adornments. |
|
|
265
|
+
| `counter` | `data-zidan-counter` | number | `maxlength` | Character limit for the counter; overrides `maxlength`. |
|
|
266
|
+
| `output` | `data-zidan-output` | selector | — | Range value is mirrored into this element. |
|
|
267
|
+
| `title` | `data-zidan-title` | string | `Choose a file` | File dropzone title. |
|
|
268
|
+
| `dropHint` | `data-zidan-drop-hint` | string | — | File dropzone subtitle. |
|
|
269
|
+
| `maxFiles` | `data-zidan-max-files` | number | — | File count limit. |
|
|
270
|
+
| `maxSize` | `data-zidan-max-size` | number | — | Bytes per file. |
|
|
271
|
+
| `maxSizeMB` | `data-zidan-max-size-mb` | number | — | Per-file limit in megabytes; `2` = 2 MB, decimals allowed. Ignored when `maxSize` is set. |
|
|
272
|
+
| `accept` | native `accept` | string | — | Validated on top of the native picker filter and shown in the drop hint. |
|
|
273
|
+
| `alwaysValidate` | — | boolean | `false` | Show invalid state without waiting for blur. |
|
|
274
|
+
|
|
275
|
+
### Select options
|
|
276
|
+
|
|
277
|
+
See [`docs/options.md`](docs/options.md) for the complete table (`mode`, `layout`,
|
|
278
|
+
`themeFramework`, `searchable`, `clearable`, `multiple`, `maxTags`, `suggestions`,
|
|
279
|
+
`fetchOptions`, `debounce`, `minChars`, callbacks, `customClasses`, `scrollbar`, …).
|
|
280
|
+
|
|
281
|
+
Validation state options on both layers: **the plugin never submits or blocks a form** — it
|
|
282
|
+
mirrors state and lets your validator decide.
|
|
283
|
+
|
|
284
|
+
---
|
|
285
|
+
|
|
286
|
+
## JavaScript API
|
|
287
|
+
|
|
288
|
+
```js
|
|
289
|
+
initZidanSelects(scope?, options?) → ZidanSelect[]
|
|
290
|
+
initZidanForms(scope?, options?) → Field[]
|
|
291
|
+
zidanField(target, options?) → Field | Field[]
|
|
292
|
+
ZidanForm.init(scope, options) → Field[]
|
|
293
|
+
ZidanForm.field(target, options) → Field | Field[]
|
|
294
|
+
ZidanForm.get(input) → Field | null
|
|
295
|
+
ZidanForm.refresh(scope?) → Field[] // re-scan + sync
|
|
296
|
+
ZidanForm.observe(scope, options?) → MutationObserver
|
|
297
|
+
ZidanForm.destroyAll()
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
`zidanField()` also accepts a plain `<input>`/`<textarea>` of a supported type, so JS-only
|
|
301
|
+
options such as `output` and `counter` work without any data attribute.
|
|
302
|
+
|
|
303
|
+
`ZidanForm.themes`, `.fieldLayouts` are live registries: `ZidanForm.themes.push('brand')`
|
|
304
|
+
adds a valid name (do it before fields initialise). `.frameworks` lists the built-in adapters.
|
|
305
|
+
`ZidanSelect.layouts`, `.frameworks`, `.scrollbars`, `.instances`, `.get()`,
|
|
306
|
+
`.destroyAll()` remain available.
|
|
307
|
+
|
|
308
|
+
Per-select instance: `open()`, `close()`, `toggle()`, `isOpen()`, `getValue()`,
|
|
309
|
+
`setValue(v)`, `clear()`, `setOptions(items)`, `enable()`, `disable()`, `setLayout()`,
|
|
310
|
+
`setFramework()`, `setScrollbar()`, `setValidation()`, `refresh()`, `on()`, `off()`,
|
|
311
|
+
`destroy()`.
|
|
312
|
+
|
|
313
|
+
Per-field instance: `getValue()`, `setValue(v)`, `update()`, `refresh()`,
|
|
314
|
+
`setValidation(state)`, `getValidation()`, `setTheme()`, `setFramework()`, `setLayout()`,
|
|
315
|
+
`destroy()`, plus `setIndeterminate()`/`isChecked()` (checkbox), `setValue()` (radio group),
|
|
316
|
+
and `clear()` (file).
|
|
317
|
+
|
|
318
|
+
Events bubble from the wrapper as `zidan:change`, `zidan:validation`, `zidan:init`,
|
|
319
|
+
`zidan:destroy`, `zidan:error`:
|
|
320
|
+
|
|
321
|
+
```js
|
|
322
|
+
document.addEventListener('zidan:change', event => {
|
|
323
|
+
console.log(event.detail.kind, event.detail.value || event.detail.checked);
|
|
324
|
+
});
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
---
|
|
328
|
+
|
|
329
|
+
## Themes, layouts & frameworks
|
|
330
|
+
|
|
331
|
+
```html
|
|
332
|
+
<form data-zs-theme="dark" data-zs-framework="bootstrap">
|
|
333
|
+
<select data-zidan-select="combobox" data-zidan-layout="floating-label">…</select>
|
|
334
|
+
<input data-zidan="input" data-zidan-layout="outlined" data-zidan-label="Workspace">
|
|
335
|
+
</form>
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
Themes and frameworks resolve **per element → ancestor → `<html>`**. Set them once on a
|
|
339
|
+
form or on `<html>`; set them per instance to mix.
|
|
340
|
+
|
|
341
|
+
```js
|
|
342
|
+
ZidanForm.init(document, { theme: 'modern', framework: 'tailwind', layout: 'compact' });
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
Custom theme — no build step, core never changes:
|
|
346
|
+
|
|
347
|
+
```css
|
|
348
|
+
.my-brand {
|
|
349
|
+
--zs-primary: #e11d48;
|
|
350
|
+
--zs-primary-soft: #fff1f4;
|
|
351
|
+
--zs-focus-ring: rgba(225, 29, 72, 0.22);
|
|
352
|
+
--zs-radius: 14px;
|
|
353
|
+
--zs-check-checked-bg: #e11d48;
|
|
354
|
+
--zs-check-checked-border: #e11d48;
|
|
355
|
+
}
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
Token list, preset details and layout notes: [`docs/theming.md`](docs/theming.md).
|
|
359
|
+
|
|
360
|
+
### Layouts
|
|
361
|
+
|
|
362
|
+
| Layer | Values |
|
|
363
|
+
| --- | --- |
|
|
364
|
+
| Select | `classic-clean`, `floating-label`, `soft-pill`, `bordered-brutalist`, `glass-elevated` |
|
|
365
|
+
| Fields | `stacked`, `inline`, `compact`, `floating`, `outlined`, `card` |
|
|
366
|
+
| Containers | wrap fields in `.zs-form-grid` for an auto-fit grid; `.zs-full` spans a row |
|
|
367
|
+
|
|
368
|
+
---
|
|
369
|
+
|
|
370
|
+
## Validation libraries
|
|
371
|
+
|
|
372
|
+
The native control is never hidden from the accessibility tree, `FormData` or validators,
|
|
373
|
+
so most setups need no configuration. `aria-invalid`, `.zs-field--invalid` / `.zs-field--valid`
|
|
374
|
+
and `data-zs-validation` stay in sync with both native validity and manual state.
|
|
375
|
+
|
|
376
|
+
### Native HTML5
|
|
377
|
+
|
|
378
|
+
```html
|
|
379
|
+
<form novalidate>
|
|
380
|
+
<input required minlength="3" data-zidan="input" data-zidan-label="Name">
|
|
381
|
+
</form>
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
```js
|
|
385
|
+
form.addEventListener('submit', event => {
|
|
386
|
+
ZidanForm.refresh(form);
|
|
387
|
+
if (!form.checkValidity()) {
|
|
388
|
+
event.preventDefault();
|
|
389
|
+
form.querySelector(':invalid').focus();
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
### jQuery Validation
|
|
395
|
+
|
|
396
|
+
Default `ignore: ":hidden"` does **not** skip the plugin's 1×1 px controls. If your version
|
|
397
|
+
or a wrapper hides them, use:
|
|
398
|
+
|
|
399
|
+
```js
|
|
400
|
+
$('#form').validate({
|
|
401
|
+
ignore: [], // or: ':hidden:not(.zs-native-input)'
|
|
402
|
+
errorPlacement(error, element) {
|
|
403
|
+
var field = element.closest('.zs-field');
|
|
404
|
+
(field || element.parent()).append(error);
|
|
405
|
+
},
|
|
406
|
+
highlight(element) {
|
|
407
|
+
element.closest('.zs-field')?.classList.add('zs-field--invalid');
|
|
408
|
+
element.attr('aria-invalid', 'true');
|
|
409
|
+
},
|
|
410
|
+
unhighlight(element) {
|
|
411
|
+
element.closest('.zs-field')?.classList.remove('zs-field--invalid');
|
|
412
|
+
element.removeAttr('aria-invalid');
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
### JustValidate
|
|
418
|
+
|
|
419
|
+
```js
|
|
420
|
+
const validator = new JustValidate('#form', {
|
|
421
|
+
errorFieldCssClass: 'zs-field--invalid',
|
|
422
|
+
errorLabelStyle: { color: 'var(--zs-border-color-invalid)' }
|
|
423
|
+
});
|
|
424
|
+
validator.addField('#email', [{ rule: 'required' }, { rule: 'email' }]);
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
### Parsley
|
|
428
|
+
|
|
429
|
+
```html
|
|
430
|
+
<input data-zidan="input" data-parsley-required data-parsley-type="email">
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
```js
|
|
434
|
+
$('#form').parsley({
|
|
435
|
+
errorsContainer(parsleyField) {
|
|
436
|
+
return parsleyField.$element.closest('.zs-field');
|
|
437
|
+
}
|
|
438
|
+
});
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
### Avoiding double submits
|
|
442
|
+
|
|
443
|
+
```js
|
|
444
|
+
form.addEventListener('submit', event => {
|
|
445
|
+
if (form.dataset.busy === '1') { event.preventDefault(); return; }
|
|
446
|
+
if (!form.checkValidity()) return;
|
|
447
|
+
form.dataset.busy = '1';
|
|
448
|
+
event.preventDefault();
|
|
449
|
+
save(new FormData(form)).finally(() => { delete form.dataset.busy; });
|
|
450
|
+
});
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
Full recipes: [`docs/validation.md`](docs/validation.md). A runnable page that loads all three
|
|
454
|
+
libraries next to a native form ships as [`docs/validation.html`](docs/validation.html).
|
|
455
|
+
|
|
456
|
+
---
|
|
457
|
+
|
|
458
|
+
## Form lifecycle & state sync
|
|
459
|
+
|
|
460
|
+
| Requirement | How it works |
|
|
461
|
+
| --- | --- |
|
|
462
|
+
| Values | Native controls are never cloned: `input.value`, `.checked`, `.files` stay authoritative. |
|
|
463
|
+
| `FormData` | Works as-is; wrappers have no `name`. |
|
|
464
|
+
| `form.reset()` | Fields listen to `reset`, wait one tick and re-render from the native state. |
|
|
465
|
+
| Required/disabled/readonly/multiple | Mirrored at build time and on `update()`. |
|
|
466
|
+
| Dynamic DOM | `ZidanForm.observe(container)` initialises added nodes; `refresh()` re-syncs. |
|
|
467
|
+
| Teardown | `destroy()` restores the original input and removes every listener and node. `destroyAll()` for the whole page. |
|
|
468
|
+
|
|
469
|
+
```js
|
|
470
|
+
const observer = ZidanForm.observe(document.body);
|
|
471
|
+
// later
|
|
472
|
+
observer.disconnect();
|
|
473
|
+
ZidanForm.destroyAll();
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
The observer reacts to nodes added **or removed inside** the observed container. If you remove
|
|
477
|
+
the container itself, call `field.destroy()` (or `ZidanForm.destroyAll()`) first — the observer
|
|
478
|
+
cannot see a mutation above its own root.
|
|
479
|
+
|
|
480
|
+
---
|
|
481
|
+
|
|
482
|
+
## React, Next.js, Vue, Angular
|
|
483
|
+
|
|
484
|
+
Short version: initialise after mount, call `destroy()` before unmount, push state down with
|
|
485
|
+
`setValue()` and read it back from `onChange`/`zidan:change`. Native `<select>` values should
|
|
486
|
+
be controlled through the instance, because the plugin owns the visible trigger.
|
|
487
|
+
|
|
488
|
+
Complete, copy-pasteable examples (React 18, Next.js App Router with SSR-safe imports, Vue 3
|
|
489
|
+
`onMounted`, Angular `ngAfterViewInit` + `ControlValueAccessor` notes): [`docs/frameworks.md`](docs/frameworks.md).
|
|
490
|
+
|
|
491
|
+
Next.js CSS imports:
|
|
492
|
+
|
|
493
|
+
```js
|
|
494
|
+
// app/layout.js
|
|
495
|
+
import 'zidan-select/css/core';
|
|
496
|
+
import 'zidan-select/css/theme';
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
```jsx
|
|
500
|
+
'use client';
|
|
501
|
+
import { useEffect, useRef } from 'react';
|
|
502
|
+
import { initZidanForms, initZidanSelects } from 'zidan-select';
|
|
503
|
+
|
|
504
|
+
export default function Form() {
|
|
505
|
+
const ref = useRef(null);
|
|
506
|
+
useEffect(() => {
|
|
507
|
+
initZidanSelects(ref.current);
|
|
508
|
+
initZidanForms(ref.current);
|
|
509
|
+
return () => {
|
|
510
|
+
ZidanForm.fields.forEach(f => { if (ref.current?.contains(f.el)) f.destroy(); });
|
|
511
|
+
ZidanSelect.instances.forEach(s => { if (ref.current?.contains(s.el)) s.destroy(); });
|
|
512
|
+
};
|
|
513
|
+
}, []);
|
|
514
|
+
return <form ref={ref}>…</form>;
|
|
515
|
+
}
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
---
|
|
519
|
+
|
|
520
|
+
## Build & publish
|
|
521
|
+
|
|
522
|
+
The repo is dependency-free and works from source; `npm run build` only assembles `dist/`.
|
|
523
|
+
|
|
524
|
+
```bash
|
|
525
|
+
npm run dev # static server → http://localhost:4173
|
|
526
|
+
npm test # syntax + split-CSS + API checks (no browser, no deps)
|
|
527
|
+
npm run lint # node --check on every script
|
|
528
|
+
npm run build # dist/ (+ .min files when esbuild is installed)
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
| Command | What it does |
|
|
532
|
+
| --- | --- |
|
|
533
|
+
| `scripts/serve.mjs` | No-dependency demo server on port 4173 (`PORT=8080 npm run dev`). |
|
|
534
|
+
| `scripts/build.mjs` | Cleans `dist/`, copies the four assets, writes `dist/zidan-form.cjs`, and minifies with esbuild **if** it is installed. |
|
|
535
|
+
| `scripts/test.mjs` | Verifies syntax, that core CSS carries no colour literals, that all presets/adapters exist and the public API is exported. |
|
|
536
|
+
|
|
537
|
+
Publishing:
|
|
538
|
+
|
|
539
|
+
```bash
|
|
540
|
+
npm version minor # or patch/major — tags the release
|
|
541
|
+
npm run build
|
|
542
|
+
npm publish # `files` limits the tarball to JS, CSS, dist, docs, README, LICENSE
|
|
543
|
+
git push --follow-tags
|
|
544
|
+
```
|
|
545
|
+
|
|
546
|
+
GitHub Pages serves the repo root: the demo is `index.html` (no build needed), docs live in
|
|
547
|
+
`docs/`. Release notes should list theme/layout additions and any token renames.
|
|
548
|
+
|
|
549
|
+
Full checklist, folder tree and release automation notes: [`docs/build.md`](docs/build.md).
|
|
550
|
+
|
|
551
|
+
---
|
|
552
|
+
|
|
553
|
+
## Browser support
|
|
554
|
+
|
|
555
|
+
| Engine | Version | Notes |
|
|
556
|
+
| --- | --- | --- |
|
|
557
|
+
| Chrome / Edge | 105+ | Full theme + scrollbar control. |
|
|
558
|
+
| Firefox | 121+ | All controls; scrollbars keep the native thin gutter and `scrollbar-color` (no gradients, no thumb hover). |
|
|
559
|
+
| Safari / iOS Safari | 15.4+ | All controls; overlay scrollbars follow OS settings. |
|
|
560
|
+
| Node / SSR | 18+ | Import is side-effect free without a DOM; initialise after hydration. |
|
|
561
|
+
|
|
562
|
+
`prefers-reduced-motion` and `forced-colors` are respected. `:has()` is not required.
|
|
563
|
+
|
|
564
|
+
---
|
|
565
|
+
|
|
566
|
+
## Migrating from 1.x
|
|
567
|
+
|
|
568
|
+
| 1.x | 2.0 |
|
|
569
|
+
| --- | --- |
|
|
570
|
+
| `ZidanSelect.js` | `zidan-form.js` (same select engine inside; `window.ZidanSelect` kept as alias) |
|
|
571
|
+
| `ZidanSelect.mjs` | `zidan-form.mjs` |
|
|
572
|
+
| `ZidanSelect.css` | `plugin-core.css` + `plugin-theme.css` |
|
|
573
|
+
| `initZidanSelects()` | unchanged, plus `initZidanForms()` for the new controls |
|
|
574
|
+
| `zidanSelect()` | unchanged, plus `zidanField()` |
|
|
575
|
+
|
|
576
|
+
Update the two `<link>` tags, rename the `<script src>`, and keep the existing
|
|
577
|
+
`data-zidan-select` markup — it is unchanged.
|
|
578
|
+
|
|
579
|
+
---
|
|
580
|
+
|
|
581
|
+
MIT © akhtar1985 · [GitHub](https://github.com/akhtar1985/zidan-select) ·
|
|
582
|
+
[npm](https://www.npmjs.com/package/zidan-select)
|