zidan-select 2.3.1 → 2.4.1
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 +171 -83
- package/dist/file/plugin-file-core.css +1 -1
- package/dist/file/plugin-file-core.min.css +1 -1
- package/dist/file/plugin-file-theme.css +1 -1
- package/dist/file/plugin-file-theme.min.css +1 -1
- package/dist/file/zidan-file.d.ts +1 -1
- package/dist/file/zidan-file.js +2 -2
- package/dist/file/zidan-file.min.js +2 -2
- package/dist/plugin-core.css +1 -1
- package/dist/plugin-core.min.css +1 -1
- package/dist/plugin-theme.css +1 -1
- package/dist/plugin-theme.min.css +1 -1
- package/dist/select/plugin-select-core.css +1 -1
- package/dist/select/plugin-select-core.min.css +1 -1
- package/dist/select/plugin-select-theme.css +1 -1
- package/dist/select/plugin-select-theme.min.css +1 -1
- package/dist/select/zidan-select.d.ts +1 -1
- package/dist/select/zidan-select.js +133 -2
- package/dist/select/zidan-select.min.js +2 -2
- package/dist/zidan-form.js +133 -2
- package/dist/zidan-form.min.js +2 -2
- package/docs/build.md +76 -48
- package/docs/comparison.md +3 -3
- package/docs/frameworks.md +19 -13
- package/docs/html-and-wordpress.md +20 -20
- package/docs/index.html +144 -84
- package/docs/options.md +138 -35
- package/docs/validation.html +96 -56
- package/docs/validation.md +7 -7
- package/package.json +4 -3
- package/plugin-core.css +1 -1
- package/plugin-theme.css +1 -1
- package/zidan-form.d.ts +45 -21
- package/zidan-form.js +133 -2
package/docs/index.html
CHANGED
|
@@ -1,121 +1,181 @@
|
|
|
1
1
|
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
2
|
+
<html lang="en" data-zs-theme="default" data-zs-framework="none">
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="utf-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
6
|
<title>ZidanForm documentation</title>
|
|
7
7
|
<meta name="description" content="ZidanForm documentation index: field playground, options and data attributes, validation compatibility, theming, framework integration, build and publish guides.">
|
|
8
8
|
<link rel="canonical" href="https://akhtar1985.github.io/zidan-select/docs/">
|
|
9
|
+
<meta name="theme-color" content="#4f6bed">
|
|
9
10
|
<meta property="og:type" content="website">
|
|
11
|
+
<meta property="og:site_name" content="ZidanForm">
|
|
10
12
|
<meta property="og:title" content="ZidanForm documentation">
|
|
11
13
|
<meta property="og:description" content="Options, validation, theming, frameworks and build guides for the ZidanForm vanilla form library.">
|
|
12
14
|
<meta property="og:url" content="https://akhtar1985.github.io/zidan-select/docs/">
|
|
13
15
|
<meta property="og:image" content="https://akhtar1985.github.io/zidan-select/docs/demo-inputs.png">
|
|
14
16
|
<meta name="twitter:card" content="summary_large_image">
|
|
15
|
-
<
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
padding: 48px 24px 72px;
|
|
21
|
-
font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
|
|
22
|
-
color: #101324;
|
|
23
|
-
background: #f5f6fb;
|
|
24
|
-
line-height: 1.6;
|
|
25
|
-
}
|
|
26
|
-
main { max-width: 720px; margin: 0 auto; }
|
|
27
|
-
a { color: #4f6bed; }
|
|
28
|
-
h1 { margin: 0 0 6px; font-size: 2rem; letter-spacing: -0.02em; }
|
|
29
|
-
p.lead { margin: 0 0 28px; color: #525a70; }
|
|
30
|
-
ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
|
|
31
|
-
li {
|
|
32
|
-
background: #fff;
|
|
33
|
-
border: 1px solid #e4e8f1;
|
|
34
|
-
border-radius: 14px;
|
|
35
|
-
padding: 16px 18px;
|
|
36
|
-
box-shadow: 0 1px 2px rgba(16, 19, 36, 0.05);
|
|
37
|
-
}
|
|
38
|
-
li strong { display: block; font-size: 0.95rem; }
|
|
39
|
-
li span { font-size: 0.85rem; color: #6b7385; }
|
|
40
|
-
code { background: #eef1fd; padding: 1px 5px; border-radius: 5px; font-size: 0.85em; }
|
|
41
|
-
footer { margin-top: 32px; font-size: 0.85rem; color: #6b7385; }
|
|
42
|
-
</style>
|
|
17
|
+
<link rel="stylesheet" href="../plugin-core.css">
|
|
18
|
+
<link rel="stylesheet" href="../plugin-theme.css">
|
|
19
|
+
<link rel="stylesheet" href="../demo.css">
|
|
20
|
+
<link rel="stylesheet" href="../nav.css">
|
|
21
|
+
<link rel="stylesheet" href="../docs.css">
|
|
43
22
|
</head>
|
|
44
23
|
<body>
|
|
45
|
-
<main>
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
24
|
+
<a class="skip-link" href="#docs-main">Skip to content</a>
|
|
25
|
+
<div class="bg-orbs" aria-hidden="true"><span class="orb"></span></div>
|
|
26
|
+
|
|
27
|
+
<header class="site-header">
|
|
28
|
+
<a class="brand" href="../index.html">
|
|
29
|
+
<span class="logo-mark" aria-hidden="true">Z</span>
|
|
30
|
+
<span>
|
|
31
|
+
<span class="brand-name">ZidanForm</span>
|
|
32
|
+
<span class="brand-sub">v2.4.1 · zero dependencies</span>
|
|
33
|
+
</span>
|
|
34
|
+
</a>
|
|
35
|
+
<button class="nav-toggle" type="button" aria-expanded="false" aria-controls="site-nav">
|
|
36
|
+
<span class="nav-toggle-bars" aria-hidden="true"><span></span><span></span><span></span></span>
|
|
37
|
+
<span>Menu</span>
|
|
38
|
+
</button>
|
|
39
|
+
<nav class="header-nav" id="site-nav" aria-label="Project links">
|
|
40
|
+
<a href="../index.html">Demo</a>
|
|
41
|
+
<a href="../advanced.html">Advanced</a>
|
|
42
|
+
<a href="../playground.html">Playground</a>
|
|
43
|
+
<a href="../ajax.html">AJAX</a>
|
|
44
|
+
<a href="../shopify.html">Shopify</a>
|
|
45
|
+
<a href="../index.html#compare">Compare</a>
|
|
46
|
+
<a href="../index.html#faq">FAQ</a>
|
|
47
|
+
<details class="nav-docs">
|
|
48
|
+
<summary>Docs</summary>
|
|
49
|
+
<div class="nav-docs-panel">
|
|
50
|
+
<a href="index.html" aria-current="page">Documentation index</a>
|
|
51
|
+
<a href="options.html">Options & data attributes</a>
|
|
52
|
+
<a href="comparison.html">Why & comparison</a>
|
|
53
|
+
<a href="frameworks.html">Frameworks</a>
|
|
54
|
+
<a href="html-and-wordpress.html">HTML & WordPress</a>
|
|
55
|
+
<a href="validation-guide.html">Validation</a>
|
|
56
|
+
<a href="theming.html">Theming</a>
|
|
57
|
+
<a href="build.html">Build & publish</a>
|
|
58
|
+
</div>
|
|
59
|
+
</details>
|
|
60
|
+
<a href="https://github.com/akhtar1985/zidan-select">GitHub</a>
|
|
61
|
+
<a href="https://www.npmjs.com/package/zidan-select">npm</a>
|
|
62
|
+
<label class="sr-only" for="quick-theme">Page theme</label>
|
|
63
|
+
<select id="quick-theme" aria-label="Page theme">
|
|
64
|
+
<option value="default">Default theme</option>
|
|
65
|
+
<option value="modern">Modern</option>
|
|
66
|
+
<option value="minimal">Minimal</option>
|
|
67
|
+
<option value="dark">Dark</option>
|
|
68
|
+
<option value="glass">Glass</option>
|
|
69
|
+
</select>
|
|
70
|
+
</nav>
|
|
71
|
+
</header>
|
|
72
|
+
|
|
73
|
+
<main id="docs-main" class="wrap docs-main">
|
|
74
|
+
<section class="hero docs-hero" aria-labelledby="docs-title">
|
|
75
|
+
<p class="eyebrow"><span class="eyebrow-dot" aria-hidden="true"></span> Documentation · guides & reference</p>
|
|
76
|
+
<h1 id="docs-title">Everything you need to <span>build with ZidanForm.</span></h1>
|
|
77
|
+
<p class="doc-blurb">
|
|
78
|
+
Zero-dependency form enhancement: select, checkbox, switch, radio, file upload, text,
|
|
79
|
+
number, phone, date and range inputs — with input icons, steppers, upload progress,
|
|
80
|
+
async validation, remote select pagination, RTL support and TypeScript declarations.
|
|
81
|
+
Start with the <a href="../index.html">interactive demo</a> or the
|
|
82
|
+
<a href="../playground.html">field playground</a>, then dive into the reference.
|
|
83
|
+
</p>
|
|
84
|
+
<div class="hero-actions">
|
|
85
|
+
<a class="btn btn-primary" href="../playground.html">Open the playground</a>
|
|
86
|
+
<a class="btn" href="../index.html">Interactive demo</a>
|
|
87
|
+
<a class="btn" href="options.html">Options reference</a>
|
|
88
|
+
</div>
|
|
89
|
+
</section>
|
|
90
|
+
|
|
54
91
|
<a href="../index.html">
|
|
55
|
-
<img src="demo-inputs.png" alt="Input icons, number stepper, phone formatting and range controls in the ZidanForm demo"
|
|
56
|
-
style="display:block;width:100%;max-width:640px;margin:0 0 28px;border-radius:14px;border:1px solid #e4e8f1;box-shadow:0 1px 2px rgba(16,19,36,.05)">
|
|
92
|
+
<img class="doc-screenshot" src="demo-inputs.png" alt="Input icons, number stepper, phone formatting and range controls in the ZidanForm demo">
|
|
57
93
|
</a>
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
94
|
+
|
|
95
|
+
<div class="doc-index-grid">
|
|
96
|
+
<a class="card doc-index-card" href="../advanced.html">
|
|
97
|
+
<strong>Advanced options & API reference</strong>
|
|
61
98
|
<span>Initialization and option precedence, async select pagination, tags, Promise validation, uploads, events, lifecycle, RTL, TypeScript and copyable HTML/JavaScript examples.</span>
|
|
62
|
-
</
|
|
63
|
-
<
|
|
64
|
-
<strong
|
|
99
|
+
</a>
|
|
100
|
+
<a class="card doc-index-card" href="../playground.html">
|
|
101
|
+
<strong>Field playground</strong>
|
|
65
102
|
<span>Pick one control, toggle its options, preview it live and copy the matching HTML attributes or vanilla JavaScript call.</span>
|
|
66
|
-
</
|
|
67
|
-
<
|
|
68
|
-
<strong
|
|
103
|
+
</a>
|
|
104
|
+
<a class="card doc-index-card" href="../ajax.html">
|
|
105
|
+
<strong>AJAX & remote data demo</strong>
|
|
106
|
+
<span>Declarative <code>data-zidan-fetch-url</code> against a real API, plus a hand-written <code>fetchOptions</code> example with paging, abort and cache state on screen.</span>
|
|
107
|
+
</a>
|
|
108
|
+
<a class="card doc-index-card" href="../index.html#controls">
|
|
109
|
+
<strong>Controls & options reference</strong>
|
|
69
110
|
<span>Every control family in one place: the options you reach for most, the two ways to initialise a field, and live examples — with links into the playground for the remaining options and the advanced reference for callbacks and the API.</span>
|
|
70
|
-
</
|
|
71
|
-
<
|
|
72
|
-
<strong
|
|
111
|
+
</a>
|
|
112
|
+
<a class="card doc-index-card" href="html-and-wordpress.html">
|
|
113
|
+
<strong>Static HTML & WordPress cookbook</strong>
|
|
73
114
|
<span>Complete copy-paste pages for plain HTML, select-only and file-only builds, ID/class targeting, WordPress <code>functions.php</code>, Shopify <code>asset_url</code> + Liquid sections, and troubleshooting for page builders and caching plugins.</span>
|
|
74
|
-
</
|
|
75
|
-
<
|
|
76
|
-
<strong
|
|
115
|
+
</a>
|
|
116
|
+
<a class="card doc-index-card" href="../shopify.html">
|
|
117
|
+
<strong>Shopify product-page demo</strong>
|
|
77
118
|
<span>A mock storefront product form: variant combobox, stepper, gift-wrap switch, tile radios and an upload dropzone — with the Liquid snippets to install it in a theme, and what Shopify's checkout does not allow.</span>
|
|
78
|
-
</
|
|
79
|
-
<
|
|
80
|
-
<strong
|
|
119
|
+
</a>
|
|
120
|
+
<a class="card doc-index-card" href="https://github.com/akhtar1985/zidan-select#which-files-should-you-load">
|
|
121
|
+
<strong>Which files should I load?</strong>
|
|
81
122
|
<span>Only want a select, or only a file upload? Load only that build — you do not need the full bundle. The complete form JS and CSS is for forms that enhance every input at once.</span>
|
|
82
|
-
</
|
|
83
|
-
<
|
|
84
|
-
<strong
|
|
123
|
+
</a>
|
|
124
|
+
<a class="card doc-index-card" href="comparison.html">
|
|
125
|
+
<strong>Why ZidanForm & comparison</strong>
|
|
85
126
|
<span>Feature matrix against Select2, Choices.js, Tom Select, Slim Select and Bootstrap, plus benefits, trade-offs and migration notes.</span>
|
|
86
|
-
</
|
|
87
|
-
<
|
|
88
|
-
<strong
|
|
127
|
+
</a>
|
|
128
|
+
<a class="card doc-index-card" href="options.html">
|
|
129
|
+
<strong>Options & data attributes</strong>
|
|
89
130
|
<span>Every JS option, data attribute, callback, event and instance method — remote pagination and cache controls, no-JS init by marker class, form scope, <code>data-zidan-options</code> JSON and config targets, in the full build and both subsets. TypeScript declarations ship with the package.</span>
|
|
90
|
-
</
|
|
91
|
-
<
|
|
92
|
-
<strong
|
|
93
|
-
<span>Native constraint validation, jQuery Validation, JustValidate, Parsley and double-submit guards
|
|
94
|
-
</
|
|
95
|
-
<
|
|
96
|
-
<strong
|
|
131
|
+
</a>
|
|
132
|
+
<a class="card doc-index-card" href="validation-guide.html">
|
|
133
|
+
<strong>Validation compatibility</strong>
|
|
134
|
+
<span>Native constraint validation, jQuery Validation, JustValidate, Parsley and double-submit guards, with copyable integration patterns.</span>
|
|
135
|
+
</a>
|
|
136
|
+
<a class="card doc-index-card" href="validation.html">
|
|
137
|
+
<strong>Live validation test bench</strong>
|
|
138
|
+
<span>Run the same form through native constraints, jQuery Validation, JustValidate and Parsley, then inspect each result live.</span>
|
|
139
|
+
</a>
|
|
140
|
+
<a class="card doc-index-card" href="theming.html">
|
|
141
|
+
<strong>Theming</strong>
|
|
97
142
|
<span>Token reference, five presets, layouts, framework adapters and custom themes.</span>
|
|
98
|
-
</
|
|
99
|
-
<
|
|
100
|
-
<strong
|
|
143
|
+
</a>
|
|
144
|
+
<a class="card doc-index-card" href="frameworks.html">
|
|
145
|
+
<strong>Framework integration</strong>
|
|
101
146
|
<span>React, Next.js (with SSR), Vue, Angular and state-sync patterns.</span>
|
|
102
|
-
</
|
|
103
|
-
<
|
|
104
|
-
<strong
|
|
147
|
+
</a>
|
|
148
|
+
<a class="card doc-index-card" href="build.html#select-only-and-file-only-builds">
|
|
149
|
+
<strong>Select-only & file-only builds</strong>
|
|
105
150
|
<span>Trimmed JS and matching CSS for pages that only need a select or a file upload, with every theme and framework adapter included.</span>
|
|
106
|
-
</
|
|
107
|
-
<
|
|
108
|
-
<strong
|
|
151
|
+
</a>
|
|
152
|
+
<a class="card doc-index-card" href="build.html">
|
|
153
|
+
<strong>Build & publish</strong>
|
|
109
154
|
<span>Repository layout, scripts, dist output, npm publishing and GitHub Pages.</span>
|
|
110
|
-
</
|
|
111
|
-
</
|
|
112
|
-
|
|
155
|
+
</a>
|
|
156
|
+
</div>
|
|
157
|
+
|
|
158
|
+
<p class="doc-source-note">
|
|
113
159
|
Markdown guides open rendered on GitHub; <a href="../index.html">the demo</a>, the
|
|
114
160
|
<a href="../playground.html">field playground</a>, the
|
|
115
161
|
<a href="../shopify.html">Shopify product-page demo</a> and the
|
|
116
162
|
<a href="validation.html">validation bench</a> run here on GitHub Pages.
|
|
117
163
|
Source: <a href="https://github.com/akhtar1985/zidan-select">github.com/akhtar1985/zidan-select</a>.
|
|
118
|
-
</
|
|
164
|
+
</p>
|
|
119
165
|
</main>
|
|
166
|
+
|
|
167
|
+
<footer class="site-footer">
|
|
168
|
+
<div class="wrap">
|
|
169
|
+
<p>
|
|
170
|
+
<strong>ZidanForm</strong> — MIT licensed, no dependencies.
|
|
171
|
+
<a href="../index.html">Demo</a> ·
|
|
172
|
+
<a href="../playground.html">Playground</a> ·
|
|
173
|
+
<a href="index.html">Documentation</a> ·
|
|
174
|
+
<a href="https://github.com/akhtar1985/zidan-select">GitHub</a>
|
|
175
|
+
</p>
|
|
176
|
+
</div>
|
|
177
|
+
</footer>
|
|
178
|
+
|
|
179
|
+
<script src="../nav.js"></script>
|
|
120
180
|
</body>
|
|
121
181
|
</html>
|
package/docs/options.md
CHANGED
|
@@ -7,9 +7,10 @@ passed to `initZidanSelects()` / `initZidanForms()` / `zidanSelect()` / `zidanFi
|
|
|
7
7
|
`data-zidan*` attribute, which is how JS-only options are applied.
|
|
8
8
|
|
|
9
9
|
> **Prefer to click through the options?** The
|
|
10
|
-
> [field playground](https://akhtar1985.github.io/zidan-select/playground.html) exposes
|
|
11
|
-
>
|
|
12
|
-
> JavaScript
|
|
10
|
+
> [field playground](https://akhtar1985.github.io/zidan-select/playground.html) exposes the main
|
|
11
|
+
> options for one control at a time and copies both supported HTML attributes and vanilla
|
|
12
|
+
> JavaScript. The [API lab](https://akhtar1985.github.io/zidan-select/#lab) exercises the complete
|
|
13
|
+
> option, callback, method and event inventory.
|
|
13
14
|
|
|
14
15
|
## Direct init by ID or class
|
|
15
16
|
|
|
@@ -131,13 +132,18 @@ Applies to `ZidanCheckbox`, `ZidanRadioGroup`, `ZidanFileUpload`, `ZidanTextFiel
|
|
|
131
132
|
|
|
132
133
|
| JS option | Data attribute | Type | Default | Notes |
|
|
133
134
|
| --- | --- | --- | --- | --- |
|
|
134
|
-
| `variant` | `data-zidan-variant` | string | `default` | Checkbox: `default`, `switch`, `card`, `button`, `minimal`. Radio: `stacked`, `inline`, `card`, `button`, `tile`. File: `dropzone`, `button`, `avatar`, `gallery`, `compact`. Range
|
|
135
|
+
| `variant` | `data-zidan-variant` | string | `default` | Checkbox: `default`, `switch`, `card`, `button`, `minimal`. Radio: `stacked`, `inline`, `card`, `button`, `tile`. File: `dropzone`, `button`, `avatar`, `gallery`, `compact`. Range uses `rangeVariant`. |
|
|
135
136
|
| `layout` | `data-zidan-layout` | string | `stacked` | `stacked`, `inline`, `compact`, `floating`, `outlined`, `card`. |
|
|
136
137
|
| `theme` | `data-zidan-theme`, `data-zs-theme` | string | `default` | `default`, `modern`, `minimal`, `dark`, `glass`. Resolves element → ancestor → `<html>`. |
|
|
137
138
|
| `framework` | `data-zidan-framework`, `data-zs-framework` | string | `none` | `none`, `bootstrap`, `tailwind`, `bulma`, `foundation`, `vanilla`. |
|
|
138
139
|
| `label` | `data-zidan-label` | string | — | Used when the markup has no `<label>`; a generated label is `<label for>`. If the markup already has a `<label>`, the generated one replaces it and the original is hidden until `destroy()`. |
|
|
139
140
|
| `hint` | `data-zidan-hint` | string | — | Rendered under the control and linked via `aria-describedby`. |
|
|
140
|
-
| `
|
|
141
|
+
| `description` | `data-zidan-description` | string | — | Second line for card, tile, button and minimal checkbox/radio variants. |
|
|
142
|
+
| `descriptions` | — | object | — | Radio group: `{ value: 'Description' }` fallback descriptions. |
|
|
143
|
+
| `messages` | — | object | — | Override built-in validation messages, including `required`, `phone`, `weekend` and `generic`. |
|
|
144
|
+
| `validate(value, field, context)` | — | function | — | Custom rule for text, checkbox, radio or file fields. Return `true`, `false`, a message string, Error or Promise; `context` is `{ signal, field, instance }`. |
|
|
145
|
+
| `showValidState` | — | boolean | `false` | Show a positive state after a successful async rule. |
|
|
146
|
+
| `validation` | `data-zidan-validation` | `valid` \| `invalid` | — | Initial state; later states come from validity or `setValidation()`. A preset `invalid` survives `update()` / `refresh()` and internal mirrors until user input/change/blur or `setValidation(null)`; programmatic value helpers that dispatch `change`, and a non-empty select value, also clear it. |
|
|
141
147
|
| `alwaysValidate` | — | boolean | `false` | Mark invalid as soon as native validity fails instead of on blur. |
|
|
142
148
|
| `indeterminate` | `data-zidan-indeterminate` | boolean | `false` | Checkbox starts mixed. |
|
|
143
149
|
| `clearable` | `data-zidan-clear` | boolean | `search` only | Clear button for text inputs and textarea. |
|
|
@@ -163,11 +169,22 @@ Applies to `ZidanCheckbox`, `ZidanRadioGroup`, `ZidanFileUpload`, `ZidanTextFiel
|
|
|
163
169
|
| --- | --- |
|
|
164
170
|
| `onInit` | `{ instance, variant?, type? }` |
|
|
165
171
|
| `onChange` | `{ instance, value }` (text/radio), `{ instance, checked, value }` (checkbox), `{ instance, files }` (file) |
|
|
166
|
-
| `
|
|
167
|
-
| `
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
172
|
+
| `onInput` | `{ instance, value }` (text/range) |
|
|
173
|
+
| `onValidation` | `{ instance, state, message? }` where `state` is `valid`, `invalid` or `null` |
|
|
174
|
+
| `onIconClick` | `{ instance, icon, position }` |
|
|
175
|
+
| `onStep` | `{ instance, value, direction }` |
|
|
176
|
+
| `onPicker` | `{ instance, type }` |
|
|
177
|
+
| `onPhoneCountry` | `{ instance, country }` |
|
|
178
|
+
| `onPhoneFormat` | `{ instance, format }` |
|
|
179
|
+
| `onRemove` | `{ instance, file, index }` |
|
|
180
|
+
| `onUploadStart` / `onUploadProgress` / `onUploadSuccess` | `{ instance, file, name, ... }` with size, progress or result |
|
|
181
|
+
| `onUpload` | Alias of `onUploadSuccess`. |
|
|
182
|
+
| `onUploadError` / `onUploadCancel` | `{ instance, file, name, error?, message? }` |
|
|
183
|
+
|
|
184
|
+
DOM events with the same information: `zidan:init`, `zidan:change`, `zidan:input`,
|
|
185
|
+
`zidan:validation`, `zidan:async-validation`, `zidan:remove`, `zidan:reveal`, `zidan:clear`,
|
|
186
|
+
`zidan:icon-click`, `zidan:step`, `zidan:picker`, `zidan:phone-country`, `zidan:phone-format`,
|
|
187
|
+
`zidan:upload-*`, `zidan:destroy` and `zidan:error`.
|
|
171
188
|
|
|
172
189
|
## Checkbox, switch & radio variants
|
|
173
190
|
|
|
@@ -241,6 +258,7 @@ Icons are sanitised with `DOMParser`: only SVG shape elements and safe attribute
|
|
|
241
258
|
| `stepperInterval` | `data-zidan-stepper-interval` | number | `90` | Repeat interval, ms. |
|
|
242
259
|
| `stepperUpLabel` | `data-zidan-stepper-up-label` | string | `Increase value` | Aria-label of “+”. |
|
|
243
260
|
| `stepperDownLabel` | `data-zidan-stepper-down-label` | string | `Decrease value` | Aria-label of “−”. |
|
|
261
|
+
| `stepperStep` | — | number | native `step` | Increment used by the stepper buttons and `stepUp()` / `stepDown()`. |
|
|
244
262
|
|
|
245
263
|
```html
|
|
246
264
|
<input type="number" min="0" max="10" value="3" data-zidan="input"
|
|
@@ -252,6 +270,8 @@ Icons are sanitised with `DOMParser`: only SVG shape elements and safe attribute
|
|
|
252
270
|
```
|
|
253
271
|
|
|
254
272
|
Methods: `stepUp(times = 1)`, `stepDown(times = 1)`, `setStepper(enabled)`.
|
|
273
|
+
`setStepper()` toggles the source attribute; destroy and reinitialise the field to add or remove
|
|
274
|
+
the generated stepper buttons.
|
|
255
275
|
Event: `zidan:step` → `{ value, direction, instance }`.
|
|
256
276
|
|
|
257
277
|
## Phone formatting
|
|
@@ -524,6 +544,7 @@ Callbacks: `onUploadStart`, `onUploadProgress`, `onUploadSuccess` / `onUpload`,
|
|
|
524
544
|
| `suggestions` | — | Tags suggestions. |
|
|
525
545
|
| `value` | — | Initial value(s). |
|
|
526
546
|
| `label` | `data-zidan-label` | Floating label text. An author `<label>` for the same control is hidden while the field is enhanced and restored by `destroy()`. |
|
|
547
|
+
| `ariaLabel` | — | Accessible name for the generated combobox input; defaults to `label`. |
|
|
527
548
|
| `placeholder` | `data-zidan-placeholder` | Trigger placeholder. |
|
|
528
549
|
|
|
529
550
|
### Behaviour
|
|
@@ -546,6 +567,15 @@ Callbacks: `onUploadStart`, `onUploadProgress`, `onUploadSuccess` / `onUpload`,
|
|
|
546
567
|
| --- | --- | --- |
|
|
547
568
|
| `fetchOptions(query, signal, context)` | — | Return an array of items, or a page `{ items, hasMore }` (or `{ items, total }`). `signal` aborts stale requests; `context` is `{ page, pageSize, append, instance }`. |
|
|
548
569
|
| `fetchPageSize` | `0` | Page size handed to `fetchOptions`. `0` keeps the legacy single-request behaviour. |
|
|
570
|
+
| `fetchUrl` | `null` | **Declarative AJAX.** GET this URL and the select builds its own `fetchOptions` — no JavaScript needed. Attribute: `data-zidan-fetch-url`. |
|
|
571
|
+
| `fetchQueryParam` | `'q'` | Query-string parameter that receives the search term (`''` omits it). |
|
|
572
|
+
| `fetchPageParam` | `'page'` | 1-based page number sent with every request (`''` omits it). |
|
|
573
|
+
| `fetchSkipParam` | `null` | Send `skip = page × pageSize` instead of `fetchPageParam`, for APIs that page by offset (dummyjson, Laravel, many REST APIs). |
|
|
574
|
+
| `fetchPageSizeParam` | `'limit'` | Parameter that receives `fetchPageSize`. |
|
|
575
|
+
| `fetchItemsPath` | `null` | Dot path to the array of rows in the JSON body (`products`, `data.items`). Without it the plugin looks for `items`, `data`, `results`, `options`, `rows`, `products` or `records`. |
|
|
576
|
+
| `fetchTotalPath` | `null` | Dot path to the total row count; with `fetchPageSize` it decides `hasMore`. Falls back to a top-level `total`. |
|
|
577
|
+
| `fetchHasMorePath` | `null` | Dot path to a boolean instead of a count. |
|
|
578
|
+
| `fetchMethod`, `fetchHeaders`, `fetchCredentials` | `'GET'`, `null`, `'same-origin'` | Request tuning for `fetchUrl` (JavaScript only). |
|
|
549
579
|
| `autoLoadMore` | `true` | Scrolling near the dropdown bottom fetches the next page automatically. |
|
|
550
580
|
| `loadMoreText` | `Load more` | Label of the footer button rendered while `hasMore` is true. |
|
|
551
581
|
| `cacheResults` | `true` | Cache pages per query + page. Clear with `select.clearCache()`. |
|
|
@@ -582,12 +612,37 @@ users.refreshOptions(); // clears the cache and refetches page 0
|
|
|
582
612
|
users.clearCache(); // drop cached pages only
|
|
583
613
|
```
|
|
584
614
|
|
|
585
|
-
`fetchOptions` may also reject:
|
|
586
|
-
|
|
587
|
-
|
|
615
|
+
`fetchOptions` may also reject: an initial failure shows an error state and
|
|
616
|
+
`getAsyncState().error` keeps the message; call `refreshOptions()` to retry. If an appended page
|
|
617
|
+
fails, the rows already loaded stay visible and the footer shows the error; clicking it retries.
|
|
618
|
+
Appended fetches emit `zidan:load-more` with `{ page, query }`; failures emit the usual
|
|
619
|
+
`zidan:error`.
|
|
588
620
|
|
|
589
621
|
The cache size is global: `ZidanSelect.cacheLimit = 50` pages (least-recently-used eviction).
|
|
590
622
|
|
|
623
|
+
### AJAX from markup only
|
|
624
|
+
|
|
625
|
+
One URL is enough to turn a combobox into a remote search. The plugin sends the query, page
|
|
626
|
+
and page size, reads the rows out of the JSON, and keeps every other behaviour (debounce,
|
|
627
|
+
abort, cache, load-more, errors) identical to a hand-written `fetchOptions`.
|
|
628
|
+
|
|
629
|
+
```html
|
|
630
|
+
<select id="product" name="product"
|
|
631
|
+
data-zidan-select="combobox"
|
|
632
|
+
data-zidan-fetch-url="/api/products/search"
|
|
633
|
+
data-zidan-fetch-items-path="data.items"
|
|
634
|
+
data-zidan-fetch-total-path="data.total"
|
|
635
|
+
data-zidan-fetch-skip-param="skip"
|
|
636
|
+
data-zidan-fetch-page-size="20">
|
|
637
|
+
</select>
|
|
638
|
+
```
|
|
639
|
+
|
|
640
|
+
That markup calls `GET /api/products/search?q=…&limit=20&skip=0`, then `skip=20` for the next
|
|
641
|
+
page, and stops when `skip + limit >= data.total`. Rows map automatically: `value` / `label`, or
|
|
642
|
+
`id` / `slug` / `code` for the value and `name` / `title` / `full_name` for the label. A live page
|
|
643
|
+
with both modes, against a real API and a static JSON file, ships as
|
|
644
|
+
[`ajax.html`](https://akhtar1985.github.io/zidan-select/ajax.html).
|
|
645
|
+
|
|
591
646
|
### Tags
|
|
592
647
|
|
|
593
648
|
| Option | Data attribute | Default |
|
|
@@ -611,16 +666,26 @@ control shows `"…" is not in the list.` through the tag error slot. Leave the
|
|
|
611
666
|
| Option | Signature |
|
|
612
667
|
| --- | --- |
|
|
613
668
|
| `filterOption(item, query)` | return boolean |
|
|
614
|
-
| `renderOption(item,
|
|
615
|
-
| `renderSelected(
|
|
616
|
-
| `renderTag(
|
|
617
|
-
| `validateTag(tag)` | boolean or message string |
|
|
618
|
-
| `formatTag(tag)` | display string |
|
|
669
|
+
| `renderOption(item, context)` | HTML string or element; `context` is `{ index, selected, active, query, instance }`. |
|
|
670
|
+
| `renderSelected(item, context)` | HTML string or element; `context` is `{ index, instance }`. |
|
|
671
|
+
| `renderTag(item, context)` | HTML string or element; `context` is `{ index, instance, disabled }`. |
|
|
672
|
+
| `validateTag(tag, tags, context)` | boolean or message string; `tag` is the formatted string, `tags` is the current tag list. |
|
|
673
|
+
| `formatTag(tag, context)` | display string; `context` is `{ instance, tags }`. |
|
|
619
674
|
|
|
620
675
|
### Select callbacks
|
|
621
676
|
|
|
622
|
-
|
|
623
|
-
|
|
677
|
+
| Callback | Payload |
|
|
678
|
+
| --- | --- |
|
|
679
|
+
| `onInit` | `{ instance, mode, value }` |
|
|
680
|
+
| `onChange` | `{ instance, value, previousValue? }` |
|
|
681
|
+
| `onSelect` | `{ instance, value, item }` |
|
|
682
|
+
| `onOpen` / `onClose` | `{ instance }` |
|
|
683
|
+
| `onTagAdd` | `{ instance, tag, value }` |
|
|
684
|
+
| `onTagRemove` | `{ instance, tag, value }` |
|
|
685
|
+
| `onLoadMore` | `{ instance, page, query }` |
|
|
686
|
+
| `onError` | `{ instance, message, error?, callback? }` |
|
|
687
|
+
|
|
688
|
+
Every callback receives a single payload object.
|
|
624
689
|
|
|
625
690
|
### Every select option in one object
|
|
626
691
|
|
|
@@ -651,6 +716,7 @@ const picker = zidanSelect('#mymov', {
|
|
|
651
716
|
// suggestions: ['Interstellar', 'Oppenheimer'],
|
|
652
717
|
// value: 'inception', // string, or array for multiple/tags
|
|
653
718
|
label: 'Movie',
|
|
719
|
+
ariaLabel: 'Choose a movie',
|
|
654
720
|
placeholder: 'Search a movie…',
|
|
655
721
|
|
|
656
722
|
/* Behaviour */
|
|
@@ -670,6 +736,17 @@ const picker = zidanSelect('#mymov', {
|
|
|
670
736
|
// .then(function (response) { return response.json(); }); // items[] or { items, hasMore }
|
|
671
737
|
// },
|
|
672
738
|
fetchPageSize: 0, // >0 enables paged responses, load-more and scroll auto-load
|
|
739
|
+
fetchUrl: null, // declarative AJAX endpoint; no fetchOptions needed
|
|
740
|
+
fetchQueryParam: 'q', // '' omits the search parameter
|
|
741
|
+
fetchPageParam: 'page', // 1-based; '' omits it
|
|
742
|
+
fetchSkipParam: null, // e.g. 'skip' sends page × fetchPageSize
|
|
743
|
+
fetchPageSizeParam: 'limit', // '' omits the page-size parameter
|
|
744
|
+
fetchItemsPath: null, // e.g. 'data.items'; common array names are auto-detected
|
|
745
|
+
fetchTotalPath: null, // row count used to calculate hasMore
|
|
746
|
+
fetchHasMorePath: null, // boolean path used instead of a total
|
|
747
|
+
fetchMethod: 'GET',
|
|
748
|
+
fetchHeaders: null, // e.g. { Authorization: 'Bearer …' }
|
|
749
|
+
fetchCredentials: 'same-origin', // 'omit' | 'same-origin' | 'include'
|
|
673
750
|
autoLoadMore: true,
|
|
674
751
|
cacheResults: true, // ZidanSelect.cacheLimit = 50 pages, LRU
|
|
675
752
|
loadMoreText: 'Load more',
|
|
@@ -690,15 +767,24 @@ const picker = zidanSelect('#mymov', {
|
|
|
690
767
|
|
|
691
768
|
/* Rendering hooks */
|
|
692
769
|
// filterOption: function (item, query) { return item.label.toLowerCase().includes(query.toLowerCase()); },
|
|
693
|
-
// renderOption: function (item) {
|
|
694
|
-
//
|
|
695
|
-
//
|
|
696
|
-
//
|
|
697
|
-
//
|
|
770
|
+
// renderOption: function (item, context) {
|
|
771
|
+
// return (context.selected ? '✓ ' : '') + item.label;
|
|
772
|
+
// },
|
|
773
|
+
// renderSelected: function (item, context) { return '◉ ' + item.label; },
|
|
774
|
+
// renderTag: function (item, context) { return String(item.label).toUpperCase(); },
|
|
775
|
+
// validateTag: function (tag, tags, context) { return tag.length <= 24 || 'Use 24 characters or fewer'; },
|
|
776
|
+
// formatTag: function (tag, context) { return tag.toUpperCase(); },
|
|
698
777
|
|
|
699
|
-
/* Callbacks
|
|
778
|
+
/* Callbacks */
|
|
700
779
|
onInit: function (event) { console.log('init', event.instance); },
|
|
701
|
-
onChange: function (event) { console.log('value', event.value); }
|
|
780
|
+
onChange: function (event) { console.log('value', event.value); },
|
|
781
|
+
// onSelect: function (event) { console.log('selected', event.item); },
|
|
782
|
+
// onOpen: function (event) { console.log('opened', event.instance); },
|
|
783
|
+
// onClose: function (event) { console.log('closed', event.instance); },
|
|
784
|
+
// onTagAdd: function (event) { console.log('tag added', event.tag); },
|
|
785
|
+
// onTagRemove: function (event) { console.log('tag removed', event.tag); },
|
|
786
|
+
// onLoadMore: function (event) { console.log('loading page', event.page); },
|
|
787
|
+
// onError: function (event) { console.log('error', event.message); }
|
|
702
788
|
});
|
|
703
789
|
```
|
|
704
790
|
|
|
@@ -716,8 +802,12 @@ as JSON.
|
|
|
716
802
|
`data-zidan-multiple`, `data-zidan-searchable`, `data-zidan-clearable`, `data-zidan-disabled`,
|
|
717
803
|
`data-zidan-allow-free-text`, `data-zidan-max-tags`, `data-zidan-min-tag-length`,
|
|
718
804
|
`data-zidan-max-tag-length`, `data-zidan-case-sensitive`, `data-zidan-validation`,
|
|
719
|
-
`data-zidan-scrollbar`,
|
|
720
|
-
|
|
805
|
+
`data-zidan-scrollbar`, `data-zidan-fetch-url`, `data-zidan-fetch-method`,
|
|
806
|
+
`data-zidan-fetch-query-param`, `data-zidan-fetch-page-param`, `data-zidan-fetch-skip-param`,
|
|
807
|
+
`data-zidan-fetch-page-size`, `data-zidan-fetch-page-size-param`, `data-zidan-fetch-items-path`,
|
|
808
|
+
`data-zidan-fetch-total-path`, `data-zidan-fetch-has-more-path`, and the JSON escape hatch
|
|
809
|
+
`data-zidan-options` (any JS option that takes a literal value). Marker classes:
|
|
810
|
+
`zidan-select`, `zidan-field`, `zidan-form`.
|
|
721
811
|
|
|
722
812
|
## Defaults
|
|
723
813
|
|
|
@@ -750,12 +840,17 @@ to any field that should span the row) rather than putting it on a single field.
|
|
|
750
840
|
| `getValue()` | Text/textarea value, checked value, radio value or selected files. |
|
|
751
841
|
| `setValue(v)` | Writes to the native control and re-renders. |
|
|
752
842
|
| `update()` / `refresh()` | Re-read native state (checked, disabled, validity, value). |
|
|
753
|
-
| `
|
|
843
|
+
| `validationTargets()` | Native element(s) whose constraints are mirrored. |
|
|
844
|
+
| `setValidation('valid'\|'invalid'\|null)` | Mirrors state to classes and `aria-invalid`. A public `'invalid'` call survives `update()` / `refresh()` and internal mirrors; user input/change/blur, value helpers that dispatch `change`, a non-empty select value, or another public state call clears/replaces it. |
|
|
754
845
|
| `getValidation()` | Current validation state. |
|
|
846
|
+
| `setError(message)` / `clearError()` | Set or clear the rendered error and invalid state. |
|
|
847
|
+
| `checkAsync()` | Promise resolving to the custom-rule result; runs pending state and stale guards. |
|
|
848
|
+
| `validate()` | Promise resolving to overall validity after native and custom rules. |
|
|
849
|
+
| `isPending()` | Whether an async rule is currently running. |
|
|
755
850
|
| `setTheme(name)`, `setFramework(name)`, `setLayout(name)` | Scoped restyling. |
|
|
756
851
|
| `destroy()` | Restores the original DOM and removes every listener. |
|
|
757
852
|
|
|
758
|
-
Checkbox adds `setIndeterminate(bool)` and `isChecked()`.
|
|
853
|
+
Checkbox adds `setIndeterminate(bool)`, `setChecked(bool)` and `isChecked()`.
|
|
759
854
|
|
|
760
855
|
Text inputs add `stepUp(times?)`, `stepDown(times?)`, `setStepper(bool)`,
|
|
761
856
|
`getPhoneCountry()`, `setPhoneCountry(iso)`, `setPhoneFormat(format)`, `formatPhone(value?)`
|
|
@@ -770,18 +865,26 @@ File adds `getFiles()`, `getUploadState()`, `addFiles()`, `replaceFiles()`, `rem
|
|
|
770
865
|
`open()`, `close()`, `toggle()`, `isOpen()`, `getValue()`, `setValue()`, `clear()`,
|
|
771
866
|
`setOptions(items)`, `addTag()`, `removeTag()`, `getTags()`, `enable()`, `disable()`,
|
|
772
867
|
`setLayout()`, `setFramework()`, `setScrollbar()`, `setValidation()`, `refresh()`,
|
|
868
|
+
`loadMore()`, `hasMoreResults()`, `getAsyncState()`, `refreshOptions()`, `clearCache()`,
|
|
773
869
|
`on(event, handler)`, `off(event, handler)`, `announce(message)`, `destroy()`.
|
|
774
870
|
|
|
775
871
|
## Events
|
|
776
872
|
|
|
777
873
|
| Event | Detail |
|
|
778
874
|
| --- | --- |
|
|
779
|
-
| `zidan:init` | `{ instance, kind \| mode }` |
|
|
780
|
-
| `zidan:change` | `{ instance, value }`, `{ checked }`, `{ files }` |
|
|
875
|
+
| `zidan:init` | `{ instance, kind \| mode, ... }` |
|
|
876
|
+
| `zidan:change` | `{ instance, value, previousValue? }`, `{ checked }`, `{ files }` |
|
|
877
|
+
| `zidan:input` | `{ instance, value }` (text/range) |
|
|
781
878
|
| `zidan:validation` | `{ instance, state, message? }` |
|
|
879
|
+
| `zidan:async-validation` | `{ instance, valid, message, error? }` |
|
|
880
|
+
| `zidan:open` / `zidan:close` | `{ instance }` (select) |
|
|
881
|
+
| `zidan:select` | `{ instance, value, item }` (select) |
|
|
882
|
+
| `zidan:no-results` | `{ instance, query }` (select) |
|
|
883
|
+
| `zidan:tag-add` / `zidan:tag-remove` | `{ instance, tag, value }` (select tags) |
|
|
884
|
+
| `zidan:load-more` | `{ instance, page, query }` (select pagination) |
|
|
885
|
+
| `zidan:reveal` | `{ instance, visible }` (password) |
|
|
782
886
|
| `zidan:remove` | `{ instance, file, index? }` (file upload) |
|
|
783
|
-
| `zidan:
|
|
784
|
-
| `zidan:step` | `{ instance, value, direction }` (number stepper) |
|
|
887
|
+
| `zidan:step` | `{ instance, value, direction, step }` (number stepper) |
|
|
785
888
|
| `zidan:phone-country` | `{ instance, country }` |
|
|
786
889
|
| `zidan:phone-format` | `{ instance, format }` |
|
|
787
890
|
| `zidan:icon-click` | `{ instance, icon, position }` |
|