zidan-select 2.2.4 → 2.3.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 +135 -55
- package/dist/file/plugin-file-core.css +38 -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 +286 -44
- package/dist/file/zidan-file.min.js +11 -0
- package/dist/plugin-core.css +214 -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 +377 -32
- package/dist/select/zidan-select.min.js +11 -0
- package/dist/zidan-form.js +696 -109
- package/dist/zidan-form.min.js +14 -0
- package/docs/build.md +20 -13
- package/docs/comparison.md +11 -6
- package/docs/html-and-wordpress.md +893 -0
- package/docs/index.html +21 -3
- package/docs/options.md +101 -20
- package/docs/validation.md +44 -1
- package/package.json +25 -2
- package/plugin-core.css +214 -15
- package/plugin-theme.css +36 -6
- package/zidan-form.d.ts +431 -0
- package/zidan-form.js +696 -109
package/docs/index.html
CHANGED
|
@@ -46,7 +46,8 @@
|
|
|
46
46
|
<h1>ZidanForm documentation</h1>
|
|
47
47
|
<p class="lead">
|
|
48
48
|
Zero-dependency form enhancement: select, checkbox, switch, radio, file upload, text,
|
|
49
|
-
number, phone, date and range inputs — with input icons, steppers
|
|
49
|
+
number, phone, date and range inputs — with input icons, steppers, upload progress,
|
|
50
|
+
async validation, remote select pagination, RTL support and TypeScript declarations.
|
|
50
51
|
Start with the <a href="../index.html">interactive demo</a> or the
|
|
51
52
|
<a href="../playground.html">field playground</a>, then dive into the reference.
|
|
52
53
|
</p>
|
|
@@ -55,10 +56,26 @@
|
|
|
55
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)">
|
|
56
57
|
</a>
|
|
57
58
|
<ul>
|
|
59
|
+
<li>
|
|
60
|
+
<strong><a href="../advanced.html">Advanced options & API reference</a></strong>
|
|
61
|
+
<span>Initialization and option precedence, async select pagination, tags, Promise validation, uploads, events, lifecycle, RTL, TypeScript and copyable HTML/JavaScript examples.</span>
|
|
62
|
+
</li>
|
|
58
63
|
<li>
|
|
59
64
|
<strong><a href="../playground.html">Field playground</a></strong>
|
|
60
65
|
<span>Pick one control, toggle its options, preview it live and copy the matching HTML attributes or vanilla JavaScript call.</span>
|
|
61
66
|
</li>
|
|
67
|
+
<li>
|
|
68
|
+
<strong><a href="../index.html#controls">Controls & options reference</a></strong>
|
|
69
|
+
<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
|
+
</li>
|
|
71
|
+
<li>
|
|
72
|
+
<strong><a href="https://github.com/akhtar1985/zidan-select/blob/main/docs/html-and-wordpress.md">Static HTML & WordPress cookbook</a></strong>
|
|
73
|
+
<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
|
+
</li>
|
|
75
|
+
<li>
|
|
76
|
+
<strong><a href="../shopify.html">Shopify product-page demo</a></strong>
|
|
77
|
+
<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
|
+
</li>
|
|
62
79
|
<li>
|
|
63
80
|
<strong><a href="https://github.com/akhtar1985/zidan-select#which-files-should-you-load">Which files should I load?</a></strong>
|
|
64
81
|
<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>
|
|
@@ -69,7 +86,7 @@
|
|
|
69
86
|
</li>
|
|
70
87
|
<li>
|
|
71
88
|
<strong><a href="https://github.com/akhtar1985/zidan-select/blob/main/docs/options.md">Options & data attributes</a></strong>
|
|
72
|
-
<span>Every JS option, data attribute, callback, event and instance method —
|
|
89
|
+
<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>
|
|
73
90
|
</li>
|
|
74
91
|
<li>
|
|
75
92
|
<strong><a href="https://github.com/akhtar1985/zidan-select/blob/main/docs/validation.md">Validation compatibility</a></strong>
|
|
@@ -94,7 +111,8 @@
|
|
|
94
111
|
</ul>
|
|
95
112
|
<footer>
|
|
96
113
|
Markdown guides open rendered on GitHub; <a href="../index.html">the demo</a>, the
|
|
97
|
-
<a href="../playground.html">field playground</a
|
|
114
|
+
<a href="../playground.html">field playground</a>, the
|
|
115
|
+
<a href="../shopify.html">Shopify product-page demo</a> and the
|
|
98
116
|
<a href="validation.html">validation bench</a> run here on GitHub Pages.
|
|
99
117
|
Source: <a href="https://github.com/akhtar1985/zidan-select">github.com/akhtar1985/zidan-select</a>.
|
|
100
118
|
</footer>
|
package/docs/options.md
CHANGED
|
@@ -14,7 +14,9 @@ passed to `initZidanSelects()` / `initZidanForms()` / `zidanSelect()` / `zidanFi
|
|
|
14
14
|
## Direct init by ID or class
|
|
15
15
|
|
|
16
16
|
The first argument of `zidanSelect()` accepts a CSS selector, an element, or a NodeList. Plain
|
|
17
|
-
selects are not auto-initialised, so you can enhance exactly the field you want
|
|
17
|
+
selects are not auto-initialised, so you can enhance exactly the field you want. For complete
|
|
18
|
+
copy-paste pages (static HTML, WordPress, page builders) see the
|
|
19
|
+
[static HTML & WordPress cookbook](html-and-wordpress.md).
|
|
18
20
|
|
|
19
21
|
```html
|
|
20
22
|
<select id="mymov">…</select>
|
|
@@ -133,9 +135,9 @@ Applies to `ZidanCheckbox`, `ZidanRadioGroup`, `ZidanFileUpload`, `ZidanTextFiel
|
|
|
133
135
|
| `layout` | `data-zidan-layout` | string | `stacked` | `stacked`, `inline`, `compact`, `floating`, `outlined`, `card`. |
|
|
134
136
|
| `theme` | `data-zidan-theme`, `data-zs-theme` | string | `default` | `default`, `modern`, `minimal`, `dark`, `glass`. Resolves element → ancestor → `<html>`. |
|
|
135
137
|
| `framework` | `data-zidan-framework`, `data-zs-framework` | string | `none` | `none`, `bootstrap`, `tailwind`, `bulma`, `foundation`, `vanilla`. |
|
|
136
|
-
| `label` | `data-zidan-label` | string | — | Used when the markup has no `<label>`; a generated label is `<label for>`. |
|
|
138
|
+
| `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()`. |
|
|
137
139
|
| `hint` | `data-zidan-hint` | string | — | Rendered under the control and linked via `aria-describedby`. |
|
|
138
|
-
| `validation` | `data-zidan-validation` | `valid` \| `invalid` | — | Initial state; later states come from validity or `setValidation()`. |
|
|
140
|
+
| `validation` | `data-zidan-validation` | `valid` \| `invalid` | — | Initial state; later states come from validity or `setValidation()`. A preset `invalid` is pinned: it survives initialisation and programmatic `update()`/`refresh()`/`setValue()` until the user edits the control or you pass `setValidation(null)`. |
|
|
139
141
|
| `alwaysValidate` | — | boolean | `false` | Mark invalid as soon as native validity fails instead of on blur. |
|
|
140
142
|
| `indeterminate` | `data-zidan-indeterminate` | boolean | `false` | Checkbox starts mixed. |
|
|
141
143
|
| `clearable` | `data-zidan-clear` | boolean | `search` only | Clear button for text inputs and textarea. |
|
|
@@ -143,7 +145,7 @@ Applies to `ZidanCheckbox`, `ZidanRadioGroup`, `ZidanFileUpload`, `ZidanTextFiel
|
|
|
143
145
|
| `prefix` | `data-zidan-prefix` | string | — | Static text before the input. |
|
|
144
146
|
| `suffix` | `data-zidan-suffix` | string | — | Static text after the input. |
|
|
145
147
|
| `counter` | `data-zidan-counter` | number | `maxlength` | Counter maximum; wins over the `maxlength` default. |
|
|
146
|
-
| `output` | `data-zidan-output` | selector | — | Range value is mirrored into this element. |
|
|
148
|
+
| `output` | `data-zidan-output` | selector | — | Range display value (formatted when `rangeFormat` is set) is mirrored into this element. |
|
|
147
149
|
| `title` | `data-zidan-title` | string | `Choose a file` | Dropzone headline. |
|
|
148
150
|
| `dropHint` | `data-zidan-drop-hint` | string | — | Dropzone subtitle. |
|
|
149
151
|
| `accept` | native `accept` | string | — | Validated on top of the native picker filter and shown in the dropzone hint. |
|
|
@@ -289,13 +291,17 @@ national `0` is dropped in international/E.164 output.
|
|
|
289
291
|
| JS option | Data attribute | Type | Default | Notes |
|
|
290
292
|
| --- | --- | --- | --- | --- |
|
|
291
293
|
| `rangeVariant` | `data-zidan-range-variant` | `default` \| `gradient` \| `stepped` \| `minimal` | `default` | Visual skin. |
|
|
292
|
-
| `rangeBubble` | `data-zidan-range-bubble` | boolean | `true` |
|
|
293
|
-
| `
|
|
294
|
-
| `
|
|
295
|
-
| `
|
|
294
|
+
| `rangeBubble` | `data-zidan-range-bubble` | boolean | `true` | Master switch for the floating value bubble. |
|
|
295
|
+
| `rangeBubbleMode` | `data-zidan-range-bubble-mode` | `always` \| `active` \| `never` | `always` | `active` shows the bubble only on hover, focus or drag. |
|
|
296
|
+
| `rangeBubblePosition` | `data-zidan-range-bubble-position` | `top` \| `bottom` | `top` | Bubble above the track or below the ticks/scale. |
|
|
297
|
+
| `rangeFill` | `data-zidan-range-fill` | boolean | `true` | Coloured progress fill; `false` keeps the neutral track (gradient skin keeps its gradient). |
|
|
298
|
+
| `rangeMinMax` | `data-zidan-range-minmax` | boolean | `true` | Min/max scale under the track. Hidden automatically when labeled ticks cover both ends, so 0 and the max print once. |
|
|
299
|
+
| `rangeMinLabel` / `rangeMaxLabel` | `data-zidan-range-min-label` / `-range-max-label` | string | — | Custom text for the scale ends (e.g. `Low` / `High`); `rangeFormat` is used when unset. |
|
|
300
|
+
| `rangeTicks` | `data-zidan-range-ticks` | number \| array \| string | `0` | Count, JS array, JSON array or comma list (`0,250,500`). Values are absolute and out-of-range ones sit at the nearest end. |
|
|
301
|
+
| `rangeTickLabels` | `data-zidan-range-tick-labels` | boolean | `false` | Text labels on ticks. Labels at both ends replace the min/max scale. |
|
|
296
302
|
| `rangeLabels` | — | object | — | Map `{ value: 'Label' }` used with labeled ticks. |
|
|
297
303
|
| `rangeFormat` | `data-zidan-range-format` | string \| function | — | Template with `{value}`, `{min}`, `{max}` (or `%s`), or `function(value, field)` in JS. |
|
|
298
|
-
| `output` | `data-zidan-output` | selector | — | Mirrors the
|
|
304
|
+
| `output` | `data-zidan-output` | selector | — | Mirrors the display value (formatted when `rangeFormat` is set) into a `<output>`/element; `input.value` keeps the raw value. |
|
|
299
305
|
|
|
300
306
|
```html
|
|
301
307
|
<input type="range" min="0" max="1000" step="50" value="400"
|
|
@@ -311,12 +317,36 @@ zidanField('#price', {
|
|
|
311
317
|
rangeLabels: { 0: 'Free', 1000: 'Top' },
|
|
312
318
|
rangeFormat: value => '€' + Number(value).toLocaleString('en-US')
|
|
313
319
|
});
|
|
320
|
+
|
|
321
|
+
zidanField('#delivery', {
|
|
322
|
+
rangeBubbleMode: 'active', // 'always' | 'active' | 'never'
|
|
323
|
+
rangeBubblePosition: 'bottom', // 'top' | 'bottom'
|
|
324
|
+
rangeFill: false, // neutral track, no progress colour
|
|
325
|
+
rangeTicks: '0,10,20,30', // count, array, JSON or comma list
|
|
326
|
+
rangeTickLabels: true,
|
|
327
|
+
rangeMinLabel: 'Low',
|
|
328
|
+
rangeMaxLabel: 'High'
|
|
329
|
+
});
|
|
314
330
|
```
|
|
315
331
|
|
|
316
332
|
The range keeps `input.value` native; only the visual chrome and bubble are added. Instance
|
|
317
333
|
properties `range`, `rangeBubble`, `rangeTicksEl` and `rangeScale` are exposed if you need to
|
|
318
334
|
re-render custom ticks.
|
|
319
335
|
|
|
336
|
+
Labeled ticks and the scale do not stack: when `rangeTickLabels` is on and the tick values
|
|
337
|
+
include both `min` and `max`, the scale row (`.zs-range-scale`) gets `zs-range-scale--hidden`
|
|
338
|
+
and the tick labels are the single endpoint readout. `rangeLabels` entries win over
|
|
339
|
+
`rangeFormat` for that value. Endpoint labels carry `zs-range-tick--start` / `--end` and the
|
|
340
|
+
bubble gets `zs-range-bubble--start` / `--end`, so both stay inside the track at 0 and max,
|
|
341
|
+
including in RTL. Without a scale row (`.zs-range--labels-no-scale`) the label height is
|
|
342
|
+
reserved so labels cannot overlap the next element.
|
|
343
|
+
|
|
344
|
+
Bubble behaviour is controlled by `rangeBubbleMode` (`always` / `active` / `never`) and
|
|
345
|
+
`rangeBubblePosition` (`top` / `bottom`), the coloured progress by `rangeFill`, and the scale
|
|
346
|
+
ends by `rangeMinLabel` / `rangeMaxLabel`. `rangeFill: false` keeps the neutral track but not
|
|
347
|
+
the gradient skin, and `rangeFormat` also feeds `aria-valuetext` so assistive tech reads the
|
|
348
|
+
formatted value.
|
|
349
|
+
|
|
320
350
|
## Date & time pickers
|
|
321
351
|
|
|
322
352
|
| JS option | Data attribute | Type | Default | Notes |
|
|
@@ -402,7 +432,7 @@ const upload = zidanField('#files', {
|
|
|
402
432
|
replaceTitle: 'Change image',
|
|
403
433
|
|
|
404
434
|
/* Upload pipeline */
|
|
405
|
-
// upload: function (context) { … },
|
|
435
|
+
// upload: function (file, context) { … }, // custom uploader, contract below
|
|
406
436
|
// uploadUrl: '/api/files', // or XHR endpoint
|
|
407
437
|
uploadField: 'file',
|
|
408
438
|
// uploadData: function (file, field) { return { folder: 'avatars' }; },
|
|
@@ -434,7 +464,8 @@ Custom uploader contract:
|
|
|
434
464
|
|
|
435
465
|
```js
|
|
436
466
|
zidanField('#files', {
|
|
437
|
-
upload(context) {
|
|
467
|
+
upload(file, context) {
|
|
468
|
+
// file: the File being uploaded
|
|
438
469
|
// context: { file, field, formData, signal, onProgress, complete, fail }
|
|
439
470
|
const xhr = new XMLHttpRequest();
|
|
440
471
|
// ...or return a promise / call context.complete(result) / context.fail(error)
|
|
@@ -492,7 +523,7 @@ Callbacks: `onUploadStart`, `onUploadProgress`, `onUploadSuccess` / `onUpload`,
|
|
|
492
523
|
| `options` | — | Array of strings or `{value,label,disabled,group}`. |
|
|
493
524
|
| `suggestions` | — | Tags suggestions. |
|
|
494
525
|
| `value` | — | Initial value(s). |
|
|
495
|
-
| `label` | `data-zidan-label` | Floating label text. |
|
|
526
|
+
| `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()`. |
|
|
496
527
|
| `placeholder` | `data-zidan-placeholder` | Trigger placeholder. |
|
|
497
528
|
|
|
498
529
|
### Behaviour
|
|
@@ -500,7 +531,7 @@ Callbacks: `onUploadStart`, `onUploadProgress`, `onUploadSuccess` / `onUpload`,
|
|
|
500
531
|
| Option | Data attribute | Default | Description |
|
|
501
532
|
| --- | --- | --- | --- |
|
|
502
533
|
| `multiple` | `data-zidan-multiple` | from `multiple` | Multi-select. |
|
|
503
|
-
| `searchable` | `data-zidan-searchable` | `true` except plain select | Type-to-filter. |
|
|
534
|
+
| `searchable` | `data-zidan-searchable` | `true` except plain select | Type-to-filter. With `searchable: false` in `select` mode the text field is `readOnly`, so typing can never filter or hide the list — open it with a click, `Space`, `Enter` or `↓`. |
|
|
504
535
|
| `clearable` | `data-zidan-clearable` | `false` | Clear button. |
|
|
505
536
|
| `closeOnSelect` | — | single: `true` | Close after choosing. |
|
|
506
537
|
| `maxDropdownHeight` | — | `280` | Listbox max height in px. |
|
|
@@ -513,12 +544,50 @@ Callbacks: `onUploadStart`, `onUploadProgress`, `onUploadSuccess` / `onUpload`,
|
|
|
513
544
|
|
|
514
545
|
| Option | Default | Description |
|
|
515
546
|
| --- | --- | --- |
|
|
516
|
-
| `fetchOptions(query, signal)` | — | Return
|
|
547
|
+
| `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
|
+
| `fetchPageSize` | `0` | Page size handed to `fetchOptions`. `0` keeps the legacy single-request behaviour. |
|
|
549
|
+
| `autoLoadMore` | `true` | Scrolling near the dropdown bottom fetches the next page automatically. |
|
|
550
|
+
| `loadMoreText` | `Load more` | Label of the footer button rendered while `hasMore` is true. |
|
|
551
|
+
| `cacheResults` | `true` | Cache pages per query + page. Clear with `select.clearCache()`. |
|
|
552
|
+
| `onLoadMore` | — | Called when a follow-up page starts loading: `{ page, query, instance }`. |
|
|
517
553
|
| `debounce` | `250` | Async debounce in ms. |
|
|
518
554
|
| `minChars` | `0` | Characters before fetching. |
|
|
519
555
|
| `allowFreeText` | tags only | Allow values not in the list. |
|
|
520
556
|
| `searchValues` | `true` | Match against values as well as labels. |
|
|
521
557
|
|
|
558
|
+
Remote results are **not** filtered again on the client, so a server that already applied
|
|
559
|
+
the query is never double-filtered. Use `renderOption` for custom rows; keep values stable
|
|
560
|
+
across pages so the merge can de-duplicate them.
|
|
561
|
+
|
|
562
|
+
```js
|
|
563
|
+
const users = zidanSelect('#owner', {
|
|
564
|
+
mode: 'combobox',
|
|
565
|
+
fetchPageSize: 20,
|
|
566
|
+
fetchOptions: async (query, signal, { page, pageSize }) => {
|
|
567
|
+
const res = await fetch('/api/users?q=' + encodeURIComponent(query)
|
|
568
|
+
+ '&page=' + page + '&size=' + pageSize, { signal });
|
|
569
|
+
const data = await res.json();
|
|
570
|
+
return {
|
|
571
|
+
items: data.rows.map(u => ({ value: u.id, label: u.name })),
|
|
572
|
+
hasMore: data.page + 1 < data.pages
|
|
573
|
+
};
|
|
574
|
+
},
|
|
575
|
+
onLoadMore: ({ page }) => console.log('loaded page', page)
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
users.loadMore(); // manual next page
|
|
579
|
+
users.hasMoreResults(); // boolean
|
|
580
|
+
users.getAsyncState(); // { query, page, hasMore, loading, fetchingMore, error }
|
|
581
|
+
users.refreshOptions(); // clears the cache and refetches page 0
|
|
582
|
+
users.clearCache(); // drop cached pages only
|
|
583
|
+
```
|
|
584
|
+
|
|
585
|
+
`fetchOptions` may also reject: the current list stays on screen, the footer shows the error
|
|
586
|
+
and clicking it retries. Appended fetches emit `zidan:load-more` with `{ page, query }`;
|
|
587
|
+
failures emit the usual `zidan:error`.
|
|
588
|
+
|
|
589
|
+
The cache size is global: `ZidanSelect.cacheLimit = 50` pages (least-recently-used eviction).
|
|
590
|
+
|
|
522
591
|
### Tags
|
|
523
592
|
|
|
524
593
|
| Option | Data attribute | Default |
|
|
@@ -532,6 +601,11 @@ Callbacks: `onUploadStart`, `onUploadProgress`, `onUploadSuccess` / `onUpload`,
|
|
|
532
601
|
| `commitOnTab` / `commitOnBlur` | — | `false` |
|
|
533
602
|
| `valueDelimiter` | — | `,` |
|
|
534
603
|
|
|
604
|
+
With `allowFreeText: false` a tag you type must match an option or a `suggestions` entry by
|
|
605
|
+
value or label (`caseSensitive` respected). Anything else is rejected: no tag is added and the
|
|
606
|
+
control shows `"…" is not in the list.` through the tag error slot. Leave the option at its
|
|
607
|
+
`true` default for free-form tags.
|
|
608
|
+
|
|
535
609
|
### Rendering hooks
|
|
536
610
|
|
|
537
611
|
| Option | Signature |
|
|
@@ -545,7 +619,7 @@ Callbacks: `onUploadStart`, `onUploadProgress`, `onUploadSuccess` / `onUpload`,
|
|
|
545
619
|
|
|
546
620
|
### Select callbacks
|
|
547
621
|
|
|
548
|
-
`onInit`, `onChange`, `onSelect`, `onOpen`, `onClose`, `onTagAdd`, `onTagRemove`, `onError`.
|
|
622
|
+
`onInit`, `onChange`, `onSelect`, `onOpen`, `onClose`, `onTagAdd`, `onTagRemove`, `onLoadMore`, `onError`.
|
|
549
623
|
Every callback receives a single payload object with `instance` and the relevant value(s).
|
|
550
624
|
|
|
551
625
|
### Every select option in one object
|
|
@@ -591,10 +665,14 @@ const picker = zidanSelect('#mymov', {
|
|
|
591
665
|
clearText: 'Clear selection',
|
|
592
666
|
|
|
593
667
|
/* Combobox / async */
|
|
594
|
-
// fetchOptions: function (query, signal) {
|
|
595
|
-
// return fetch('/api/movies?q=' + encodeURIComponent(query), { signal: signal })
|
|
596
|
-
// .then(function (response) { return response.json(); });
|
|
668
|
+
// fetchOptions: function (query, signal, context) {
|
|
669
|
+
// return fetch('/api/movies?q=' + encodeURIComponent(query) + '&page=' + context.page, { signal: signal })
|
|
670
|
+
// .then(function (response) { return response.json(); }); // items[] or { items, hasMore }
|
|
597
671
|
// },
|
|
672
|
+
fetchPageSize: 0, // >0 enables paged responses, load-more and scroll auto-load
|
|
673
|
+
autoLoadMore: true,
|
|
674
|
+
cacheResults: true, // ZidanSelect.cacheLimit = 50 pages, LRU
|
|
675
|
+
loadMoreText: 'Load more',
|
|
598
676
|
debounce: 250, // ms
|
|
599
677
|
minChars: 0,
|
|
600
678
|
searchValues: true, // match labels and values
|
|
@@ -618,12 +696,15 @@ const picker = zidanSelect('#mymov', {
|
|
|
618
696
|
// validateTag: function (tag) { return tag.length <= 24 || 'Use 24 characters or fewer'; },
|
|
619
697
|
// formatTag: function (tag) { return tag.toUpperCase(); },
|
|
620
698
|
|
|
621
|
-
/* Callbacks — also: onSelect, onOpen, onClose, onTagAdd, onTagRemove, onError */
|
|
699
|
+
/* Callbacks — also: onSelect, onOpen, onClose, onTagAdd, onTagRemove, onLoadMore, onError */
|
|
622
700
|
onInit: function (event) { console.log('init', event.instance); },
|
|
623
701
|
onChange: function (event) { console.log('value', event.value); }
|
|
624
702
|
});
|
|
625
703
|
```
|
|
626
704
|
|
|
705
|
+
Methods for paged data: `loadMore()`, `hasMoreResults()`, `getAsyncState()`,
|
|
706
|
+
`refreshOptions()`, `clearCache()`.
|
|
707
|
+
|
|
627
708
|
Data attributes remain available as a 1:1 fallback; the tables above list the matching
|
|
628
709
|
`data-zidan-*` name for each option, and `data-zidan-options` accepts any literal-value subset
|
|
629
710
|
as JSON.
|
|
@@ -669,7 +750,7 @@ to any field that should span the row) rather than putting it on a single field.
|
|
|
669
750
|
| `getValue()` | Text/textarea value, checked value, radio value or selected files. |
|
|
670
751
|
| `setValue(v)` | Writes to the native control and re-renders. |
|
|
671
752
|
| `update()` / `refresh()` | Re-read native state (checked, disabled, validity, value). |
|
|
672
|
-
| `setValidation('valid'\|'invalid'\|null)` | Mirrors state to classes and `aria-invalid`. |
|
|
753
|
+
| `setValidation('valid'\|'invalid'\|null)` | Mirrors state to classes and `aria-invalid`. A public `'invalid'` call pins the state, so `update()`/`refresh()`/`setValue()` keep it until the user edits the control or you clear it. |
|
|
673
754
|
| `getValidation()` | Current validation state. |
|
|
674
755
|
| `setTheme(name)`, `setFramework(name)`, `setLayout(name)` | Scoped restyling. |
|
|
675
756
|
| `destroy()` | Restores the original DOM and removes every listener. |
|
package/docs/validation.md
CHANGED
|
@@ -16,7 +16,8 @@ native validation, `FormData` and third-party validators keep working.
|
|
|
16
16
|
| `input.setCustomValidity()` | plugin | phone length, weekends, blocked dates, custom `validate`, file limits |
|
|
17
17
|
| `aria-invalid` | plugin (`setValidation`) or your validator | screen readers and CSS |
|
|
18
18
|
| `.zs-field--invalid` / `.zs-field--valid` | plugin | theme states |
|
|
19
|
-
|
|
|
19
|
+
| `.zs-field--pending` / `aria-busy` | plugin | in-flight async rule |
|
|
20
|
+
| `data-zs-validation="valid\|invalid\|pending"` | plugin | attribute-based styling |
|
|
20
21
|
|
|
21
22
|
The plugin marks a field invalid when:
|
|
22
23
|
|
|
@@ -28,6 +29,14 @@ It clears the state on `input`/`change` once validity passes, on `form.reset()`,
|
|
|
28
29
|
`setValidation(null)` is called. `data-zidan-validation="invalid"` forces the state without
|
|
29
30
|
native validity.
|
|
30
31
|
|
|
32
|
+
A state set through the public `setValidation('invalid')` (and a preset
|
|
33
|
+
`data-zidan-validation="invalid"`) is **pinned**: re-rendering the field — `update()`,
|
|
34
|
+
`refresh()`, `setValue()`, an option chosen in a select, an async rule that resolves clean —
|
|
35
|
+
will not clear it. That is what makes a server-side error survive until the user actually
|
|
36
|
+
touches the control. The pin is released by the next `input`, `change` or `blur` from the user,
|
|
37
|
+
or by `setValidation(null)` / `setValidation('valid')`. Internal mirrors pass a second argument
|
|
38
|
+
(`setValidation(state, true)`) so they never pin a state themselves.
|
|
39
|
+
|
|
31
40
|
## Built-in rules (written into native validity)
|
|
32
41
|
|
|
33
42
|
These rules call `input.setCustomValidity(message)`, so `form.checkValidity()`,
|
|
@@ -63,6 +72,40 @@ Object.assign(ZidanForm.messages, {
|
|
|
63
72
|
});
|
|
64
73
|
```
|
|
65
74
|
|
|
75
|
+
## Async rules
|
|
76
|
+
|
|
77
|
+
`validate` and `validateDate` may return a Promise. The field then:
|
|
78
|
+
|
|
79
|
+
1. shows a `.zs-field--pending` spinner and `aria-busy="true"`,
|
|
80
|
+
2. writes `messages.pending` (`Checking…`) into native validity, so `form.checkValidity()`
|
|
81
|
+
and any submit handler wait for the answer,
|
|
82
|
+
3. aborts the previous request when the value changes and ignores stale resolutions,
|
|
83
|
+
4. resolves `validate()` to `true`/`false` instead of a boolean,
|
|
84
|
+
5. emits `zidan:async-validation` with `{ valid, message }`.
|
|
85
|
+
|
|
86
|
+
Validators receive an `AbortSignal` as their third argument (after `value`/`checked` and the
|
|
87
|
+
field) and may reject — the rejection message is shown as the error.
|
|
88
|
+
|
|
89
|
+
```js
|
|
90
|
+
const email = zidanField('#email', {
|
|
91
|
+
alwaysValidate: true,
|
|
92
|
+
showValidState: true,
|
|
93
|
+
validate: async (value, field, { signal }) => {
|
|
94
|
+
if (!value) return true;
|
|
95
|
+
const res = await fetch('/api/check-email?e=' + encodeURIComponent(value), { signal });
|
|
96
|
+
const { taken } = await res.json();
|
|
97
|
+
return taken ? 'This address is already registered.' : true;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
await email.validate(); // Promise<boolean>
|
|
102
|
+
email.isPending(); // true while the request is in flight
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Submission is blocked while pending because the native control carries the pending message;
|
|
106
|
+
listen for `zidan:async-validation` if you need your own spinner or toast. `destroy()` aborts
|
|
107
|
+
any in-flight check, and `field.reset()` clears the pending state.
|
|
108
|
+
|
|
66
109
|
## The hidden-input trap
|
|
67
110
|
|
|
68
111
|
jQuery Validation's default `ignore: ":hidden"` checks `offsetWidth`/`offsetHeight`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zidan-select",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.1",
|
|
4
4
|
"description": "Zero-dependency form enhancement library: select/combobox/tags, checkboxes, switches, radio groups, drag & drop file upload with progress, text/number/phone/date/range inputs and textarea with input icons and steppers. Split core/theme CSS, 5 themes, 11 layouts, framework adapters. Load only the select-only or file-only build if that is all you need, or the full form bundle to enhance every input at once.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"select",
|
|
@@ -36,31 +36,44 @@
|
|
|
36
36
|
},
|
|
37
37
|
"main": "zidan-form.js",
|
|
38
38
|
"module": "zidan-form.mjs",
|
|
39
|
+
"types": "zidan-form.d.ts",
|
|
39
40
|
"unpkg": "zidan-form.js",
|
|
40
41
|
"jsdelivr": "zidan-form.js",
|
|
41
42
|
"style": "plugin-theme.css",
|
|
42
43
|
"exports": {
|
|
43
44
|
".": {
|
|
45
|
+
"types": "./zidan-form.d.ts",
|
|
44
46
|
"import": "./zidan-form.mjs",
|
|
45
47
|
"require": "./zidan-form.js",
|
|
46
48
|
"default": "./zidan-form.js"
|
|
47
49
|
},
|
|
48
50
|
"./select": {
|
|
51
|
+
"types": "./dist/select/zidan-select.d.ts",
|
|
49
52
|
"import": "./dist/select/zidan-select.mjs",
|
|
50
53
|
"require": "./dist/select/zidan-select.js",
|
|
51
54
|
"default": "./dist/select/zidan-select.js"
|
|
52
55
|
},
|
|
56
|
+
"./select/min": "./dist/select/zidan-select.min.js",
|
|
53
57
|
"./select/css/core": "./dist/select/plugin-select-core.css",
|
|
54
58
|
"./select/css/theme": "./dist/select/plugin-select-theme.css",
|
|
59
|
+
"./select/css/core.min": "./dist/select/plugin-select-core.min.css",
|
|
60
|
+
"./select/css/theme.min": "./dist/select/plugin-select-theme.min.css",
|
|
55
61
|
"./file": {
|
|
62
|
+
"types": "./dist/file/zidan-file.d.ts",
|
|
56
63
|
"import": "./dist/file/zidan-file.mjs",
|
|
57
64
|
"require": "./dist/file/zidan-file.js",
|
|
58
65
|
"default": "./dist/file/zidan-file.js"
|
|
59
66
|
},
|
|
67
|
+
"./file/min": "./dist/file/zidan-file.min.js",
|
|
60
68
|
"./file/css/core": "./dist/file/plugin-file-core.css",
|
|
61
69
|
"./file/css/theme": "./dist/file/plugin-file-theme.css",
|
|
70
|
+
"./file/css/core.min": "./dist/file/plugin-file-core.min.css",
|
|
71
|
+
"./file/css/theme.min": "./dist/file/plugin-file-theme.min.css",
|
|
72
|
+
"./min": "./dist/zidan-form.min.js",
|
|
62
73
|
"./css/core": "./plugin-core.css",
|
|
63
74
|
"./css/theme": "./plugin-theme.css",
|
|
75
|
+
"./css/core.min": "./dist/plugin-core.min.css",
|
|
76
|
+
"./css/theme.min": "./dist/plugin-theme.min.css",
|
|
64
77
|
"./core.css": "./plugin-core.css",
|
|
65
78
|
"./theme.css": "./plugin-theme.css",
|
|
66
79
|
"./package.json": "./package.json"
|
|
@@ -68,6 +81,7 @@
|
|
|
68
81
|
"files": [
|
|
69
82
|
"zidan-form.js",
|
|
70
83
|
"zidan-form.mjs",
|
|
84
|
+
"zidan-form.d.ts",
|
|
71
85
|
"plugin-core.css",
|
|
72
86
|
"plugin-theme.css",
|
|
73
87
|
"dist",
|
|
@@ -86,12 +100,21 @@
|
|
|
86
100
|
"dev": "node scripts/serve.mjs",
|
|
87
101
|
"build": "node scripts/build.mjs",
|
|
88
102
|
"test": "node scripts/test.mjs",
|
|
89
|
-
"
|
|
103
|
+
"types": "tsc -p tsconfig.types.json",
|
|
104
|
+
"prepublishOnly": "npm run types && npm run build && npm test",
|
|
105
|
+
"lint": "node --check zidan-form.js && node --check demo.js && node --check advanced.js && node --check playground.js && node --check nav.js && node --check zidan-form.mjs",
|
|
106
|
+
"search": "node scripts/exa-search.mjs"
|
|
90
107
|
},
|
|
91
108
|
"engines": {
|
|
92
109
|
"node": ">=18"
|
|
93
110
|
},
|
|
94
111
|
"publishConfig": {
|
|
95
112
|
"access": "public"
|
|
113
|
+
},
|
|
114
|
+
"devDependencies": {
|
|
115
|
+
"esbuild": "^0.21.5",
|
|
116
|
+
"exa-js": "2.29.0",
|
|
117
|
+
"jsdom": "^24.1.3",
|
|
118
|
+
"typescript": "^5.9.3"
|
|
96
119
|
}
|
|
97
120
|
}
|