zidan-select 2.4.0 → 2.4.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/README.md +61 -52
- 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 +2 -2
- package/dist/select/zidan-select.min.js +2 -2
- package/dist/zidan-form.js +2 -2
- package/dist/zidan-form.min.js +2 -2
- package/docs/build.md +23 -15
- package/docs/comparison.md +3 -3
- package/docs/frameworks.md +19 -13
- package/docs/html-and-wordpress.md +20 -20
- package/docs/index.html +143 -87
- package/docs/options.md +106 -35
- package/docs/validation.html +96 -56
- package/docs/validation.md +7 -7
- package/package.json +2 -2
- package/plugin-core.css +1 -1
- package/plugin-theme.css +1 -1
- package/zidan-form.d.ts +27 -21
- package/zidan-form.js +2 -2
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
|
|
@@ -591,9 +612,11 @@ users.refreshOptions(); // clears the cache and refetches page 0
|
|
|
591
612
|
users.clearCache(); // drop cached pages only
|
|
592
613
|
```
|
|
593
614
|
|
|
594
|
-
`fetchOptions` may also reject:
|
|
595
|
-
|
|
596
|
-
|
|
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`.
|
|
597
620
|
|
|
598
621
|
The cache size is global: `ZidanSelect.cacheLimit = 50` pages (least-recently-used eviction).
|
|
599
622
|
|
|
@@ -643,16 +666,26 @@ control shows `"…" is not in the list.` through the tag error slot. Leave the
|
|
|
643
666
|
| Option | Signature |
|
|
644
667
|
| --- | --- |
|
|
645
668
|
| `filterOption(item, query)` | return boolean |
|
|
646
|
-
| `renderOption(item,
|
|
647
|
-
| `renderSelected(
|
|
648
|
-
| `renderTag(
|
|
649
|
-
| `validateTag(tag)` | boolean or message string |
|
|
650
|
-
| `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 }`. |
|
|
651
674
|
|
|
652
675
|
### Select callbacks
|
|
653
676
|
|
|
654
|
-
|
|
655
|
-
|
|
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.
|
|
656
689
|
|
|
657
690
|
### Every select option in one object
|
|
658
691
|
|
|
@@ -683,6 +716,7 @@ const picker = zidanSelect('#mymov', {
|
|
|
683
716
|
// suggestions: ['Interstellar', 'Oppenheimer'],
|
|
684
717
|
// value: 'inception', // string, or array for multiple/tags
|
|
685
718
|
label: 'Movie',
|
|
719
|
+
ariaLabel: 'Choose a movie',
|
|
686
720
|
placeholder: 'Search a movie…',
|
|
687
721
|
|
|
688
722
|
/* Behaviour */
|
|
@@ -702,6 +736,17 @@ const picker = zidanSelect('#mymov', {
|
|
|
702
736
|
// .then(function (response) { return response.json(); }); // items[] or { items, hasMore }
|
|
703
737
|
// },
|
|
704
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'
|
|
705
750
|
autoLoadMore: true,
|
|
706
751
|
cacheResults: true, // ZidanSelect.cacheLimit = 50 pages, LRU
|
|
707
752
|
loadMoreText: 'Load more',
|
|
@@ -722,15 +767,24 @@ const picker = zidanSelect('#mymov', {
|
|
|
722
767
|
|
|
723
768
|
/* Rendering hooks */
|
|
724
769
|
// filterOption: function (item, query) { return item.label.toLowerCase().includes(query.toLowerCase()); },
|
|
725
|
-
// renderOption: function (item) {
|
|
726
|
-
//
|
|
727
|
-
//
|
|
728
|
-
//
|
|
729
|
-
//
|
|
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(); },
|
|
730
777
|
|
|
731
|
-
/* Callbacks
|
|
778
|
+
/* Callbacks */
|
|
732
779
|
onInit: function (event) { console.log('init', event.instance); },
|
|
733
|
-
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); }
|
|
734
788
|
});
|
|
735
789
|
```
|
|
736
790
|
|
|
@@ -748,8 +802,12 @@ as JSON.
|
|
|
748
802
|
`data-zidan-multiple`, `data-zidan-searchable`, `data-zidan-clearable`, `data-zidan-disabled`,
|
|
749
803
|
`data-zidan-allow-free-text`, `data-zidan-max-tags`, `data-zidan-min-tag-length`,
|
|
750
804
|
`data-zidan-max-tag-length`, `data-zidan-case-sensitive`, `data-zidan-validation`,
|
|
751
|
-
`data-zidan-scrollbar`,
|
|
752
|
-
|
|
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`.
|
|
753
811
|
|
|
754
812
|
## Defaults
|
|
755
813
|
|
|
@@ -782,12 +840,17 @@ to any field that should span the row) rather than putting it on a single field.
|
|
|
782
840
|
| `getValue()` | Text/textarea value, checked value, radio value or selected files. |
|
|
783
841
|
| `setValue(v)` | Writes to the native control and re-renders. |
|
|
784
842
|
| `update()` / `refresh()` | Re-read native state (checked, disabled, validity, value). |
|
|
785
|
-
| `
|
|
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. |
|
|
786
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. |
|
|
787
850
|
| `setTheme(name)`, `setFramework(name)`, `setLayout(name)` | Scoped restyling. |
|
|
788
851
|
| `destroy()` | Restores the original DOM and removes every listener. |
|
|
789
852
|
|
|
790
|
-
Checkbox adds `setIndeterminate(bool)` and `isChecked()`.
|
|
853
|
+
Checkbox adds `setIndeterminate(bool)`, `setChecked(bool)` and `isChecked()`.
|
|
791
854
|
|
|
792
855
|
Text inputs add `stepUp(times?)`, `stepDown(times?)`, `setStepper(bool)`,
|
|
793
856
|
`getPhoneCountry()`, `setPhoneCountry(iso)`, `setPhoneFormat(format)`, `formatPhone(value?)`
|
|
@@ -802,18 +865,26 @@ File adds `getFiles()`, `getUploadState()`, `addFiles()`, `replaceFiles()`, `rem
|
|
|
802
865
|
`open()`, `close()`, `toggle()`, `isOpen()`, `getValue()`, `setValue()`, `clear()`,
|
|
803
866
|
`setOptions(items)`, `addTag()`, `removeTag()`, `getTags()`, `enable()`, `disable()`,
|
|
804
867
|
`setLayout()`, `setFramework()`, `setScrollbar()`, `setValidation()`, `refresh()`,
|
|
868
|
+
`loadMore()`, `hasMoreResults()`, `getAsyncState()`, `refreshOptions()`, `clearCache()`,
|
|
805
869
|
`on(event, handler)`, `off(event, handler)`, `announce(message)`, `destroy()`.
|
|
806
870
|
|
|
807
871
|
## Events
|
|
808
872
|
|
|
809
873
|
| Event | Detail |
|
|
810
874
|
| --- | --- |
|
|
811
|
-
| `zidan:init` | `{ instance, kind \| mode }` |
|
|
812
|
-
| `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) |
|
|
813
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) |
|
|
814
886
|
| `zidan:remove` | `{ instance, file, index? }` (file upload) |
|
|
815
|
-
| `zidan:
|
|
816
|
-
| `zidan:step` | `{ instance, value, direction }` (number stepper) |
|
|
887
|
+
| `zidan:step` | `{ instance, value, direction, step }` (number stepper) |
|
|
817
888
|
| `zidan:phone-country` | `{ instance, country }` |
|
|
818
889
|
| `zidan:phone-format` | `{ instance, format }` |
|
|
819
890
|
| `zidan:icon-click` | `{ instance, icon, position }` |
|
package/docs/validation.html
CHANGED
|
@@ -12,70 +12,91 @@
|
|
|
12
12
|
<meta property="og:url" content="https://akhtar1985.github.io/zidan-select/docs/validation.html">
|
|
13
13
|
<meta property="og:image" content="https://akhtar1985.github.io/zidan-select/docs/demo-inputs.png">
|
|
14
14
|
<meta name="twitter:card" content="summary_large_image">
|
|
15
|
+
<meta name="theme-color" content="#4f6bed">
|
|
16
|
+
<meta property="og:site_name" content="ZidanForm">
|
|
17
|
+
<meta property="og:image" content="https://akhtar1985.github.io/zidan-select/docs/demo-inputs.png">
|
|
18
|
+
<meta name="twitter:card" content="summary_large_image">
|
|
15
19
|
<link rel="stylesheet" href="../plugin-core.css">
|
|
16
20
|
<link rel="stylesheet" href="../plugin-theme.css">
|
|
17
|
-
<
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
margin: 0;
|
|
21
|
-
padding: 40px 22px 70px;
|
|
22
|
-
font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
|
|
23
|
-
color: #101324;
|
|
24
|
-
background: #f5f6fb;
|
|
25
|
-
line-height: 1.55;
|
|
26
|
-
}
|
|
27
|
-
main { max-width: 900px; margin: 0 auto; }
|
|
28
|
-
h1 { margin: 0 0 6px; font-size: 1.9rem; letter-spacing: -0.02em; }
|
|
29
|
-
.lead { margin: 0 0 26px; color: #525a70; }
|
|
30
|
-
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: 16px; }
|
|
31
|
-
.card {
|
|
32
|
-
background: #fff;
|
|
33
|
-
border: 1px solid #e4e8f1;
|
|
34
|
-
border-radius: 16px;
|
|
35
|
-
padding: 20px;
|
|
36
|
-
box-shadow: 0 1px 2px rgba(16, 19, 36, 0.05);
|
|
37
|
-
}
|
|
38
|
-
.card h2 { margin: 0 0 2px; font-size: 1rem; }
|
|
39
|
-
.card p { margin: 0 0 16px; font-size: 0.8125rem; color: #6b7385; }
|
|
40
|
-
.card form { display: flex; flex-direction: column; gap: 14px; }
|
|
41
|
-
.status { margin-top: 12px; font-size: 0.8125rem; color: #067647; min-height: 20px; }
|
|
42
|
-
.status[data-state="error"] { color: #b42318; }
|
|
43
|
-
.status[data-state="missing"] { color: #b45309; }
|
|
44
|
-
button.submit {
|
|
45
|
-
align-self: flex-start;
|
|
46
|
-
font: inherit;
|
|
47
|
-
font-size: 0.85rem;
|
|
48
|
-
font-weight: 600;
|
|
49
|
-
padding: 9px 16px;
|
|
50
|
-
border-radius: 999px;
|
|
51
|
-
border: 0;
|
|
52
|
-
color: #fff;
|
|
53
|
-
background: linear-gradient(140deg, #4f6bed, #6f5cf0);
|
|
54
|
-
cursor: pointer;
|
|
55
|
-
}
|
|
56
|
-
label.error { color: #b42318; font-size: 0.75rem; }
|
|
57
|
-
.just-validate-error-label { color: #b42318; font-size: 0.75rem; margin-top: 4px; }
|
|
58
|
-
.parsley-errors-list { color: #b42318; font-size: 0.75rem; list-style: none; padding: 0; margin: 4px 0 0; }
|
|
59
|
-
.back { display: inline-block; margin-bottom: 18px; font-size: 0.85rem; color: #4f6bed; }
|
|
60
|
-
</style>
|
|
21
|
+
<link rel="stylesheet" href="../demo.css">
|
|
22
|
+
<link rel="stylesheet" href="../nav.css">
|
|
23
|
+
<link rel="stylesheet" href="../docs.css">
|
|
61
24
|
</head>
|
|
62
25
|
<body>
|
|
63
|
-
<main>
|
|
64
|
-
|
|
65
|
-
<h1>Validation-library test bench</h1>
|
|
66
|
-
<p class="lead">
|
|
67
|
-
The same plugin markup under four validators. Everything is loaded from a CDN, so this
|
|
68
|
-
page also works as a smoke test: submit each empty form, then fill it in.
|
|
69
|
-
</p>
|
|
26
|
+
<a class="skip-link" href="#docs-main">Skip to content</a>
|
|
27
|
+
<div class="bg-orbs" aria-hidden="true"><span class="orb"></span></div>
|
|
70
28
|
|
|
71
|
-
|
|
29
|
+
<header class="site-header">
|
|
30
|
+
<a class="brand" href="../index.html">
|
|
31
|
+
<span class="logo-mark" aria-hidden="true">Z</span>
|
|
32
|
+
<span>
|
|
33
|
+
<span class="brand-name">ZidanForm</span>
|
|
34
|
+
<span class="brand-sub">v2.4.2 · zero dependencies</span>
|
|
35
|
+
</span>
|
|
36
|
+
</a>
|
|
37
|
+
<button class="nav-toggle" type="button" aria-expanded="false" aria-controls="site-nav">
|
|
38
|
+
<span class="nav-toggle-bars" aria-hidden="true"><span></span><span></span><span></span></span>
|
|
39
|
+
<span>Menu</span>
|
|
40
|
+
</button>
|
|
41
|
+
<nav class="header-nav" id="site-nav" aria-label="Project links">
|
|
42
|
+
<a href="../index.html">Demo</a>
|
|
43
|
+
<a href="../advanced.html">Advanced</a>
|
|
44
|
+
<a href="../playground.html">Playground</a>
|
|
45
|
+
<a href="../ajax.html">AJAX</a>
|
|
46
|
+
<a href="../shopify.html">Shopify</a>
|
|
47
|
+
<a href="../index.html#compare">Compare</a>
|
|
48
|
+
<a href="../index.html#faq">FAQ</a>
|
|
49
|
+
<details class="nav-docs">
|
|
50
|
+
<summary>Docs</summary>
|
|
51
|
+
<div class="nav-docs-panel">
|
|
52
|
+
<a href="index.html">Documentation index</a>
|
|
53
|
+
<a href="options.html">Options & data attributes</a>
|
|
54
|
+
<a href="comparison.html">Why & comparison</a>
|
|
55
|
+
<a href="frameworks.html">Frameworks</a>
|
|
56
|
+
<a href="html-and-wordpress.html">HTML & WordPress</a>
|
|
57
|
+
<a href="validation-guide.html">Validation</a>
|
|
58
|
+
<a href="validation.html" aria-current="page">Validation test bench</a>
|
|
59
|
+
<a href="theming.html">Theming</a>
|
|
60
|
+
<a href="build.html">Build & publish</a>
|
|
61
|
+
</div>
|
|
62
|
+
</details>
|
|
63
|
+
<a href="https://github.com/akhtar1985/zidan-select">GitHub</a>
|
|
64
|
+
<a href="https://www.npmjs.com/package/zidan-select">npm</a>
|
|
65
|
+
<label class="sr-only" for="quick-theme">Page theme</label>
|
|
66
|
+
<select id="quick-theme" aria-label="Page theme">
|
|
67
|
+
<option value="default">Default theme</option>
|
|
68
|
+
<option value="modern">Modern</option>
|
|
69
|
+
<option value="minimal">Minimal</option>
|
|
70
|
+
<option value="dark">Dark</option>
|
|
71
|
+
<option value="glass">Glass</option>
|
|
72
|
+
</select>
|
|
73
|
+
</nav>
|
|
74
|
+
</header>
|
|
75
|
+
|
|
76
|
+
<main id="docs-main" class="wrap docs-main">
|
|
77
|
+
<section class="hero docs-hero" aria-labelledby="docs-title">
|
|
78
|
+
<p class="eyebrow"><span class="eyebrow-dot" aria-hidden="true"></span> Validation · live test bench</p>
|
|
79
|
+
<h1 id="docs-title">One form, <span>four validators.</span></h1>
|
|
80
|
+
<p class="doc-blurb">
|
|
81
|
+
The same plugin markup under native HTML5, jQuery Validation, JustValidate and Parsley.
|
|
82
|
+
Everything is loaded from a CDN, so this page also works as a smoke test: submit each
|
|
83
|
+
empty form, then fill it in.
|
|
84
|
+
</p>
|
|
85
|
+
<div class="hero-actions">
|
|
86
|
+
<a class="btn btn-primary" href="validation-guide.html">Read the validation guide</a>
|
|
87
|
+
<a class="btn" href="index.html">All documentation</a>
|
|
88
|
+
<a class="btn" href="../playground.html">Field playground</a>
|
|
89
|
+
</div>
|
|
90
|
+
</section>
|
|
91
|
+
|
|
92
|
+
<div class="validation-grid">
|
|
72
93
|
<section class="card">
|
|
73
94
|
<h2>Native HTML5</h2>
|
|
74
95
|
<p>Constraint validation and <code>aria-invalid</code> mirroring.</p>
|
|
75
96
|
<form id="form-native" novalidate>
|
|
76
97
|
<input name="email" type="email" required data-zidan="input" data-zidan-label="Email">
|
|
77
98
|
<label><input type="checkbox" name="terms" required data-zidan="checkbox" data-zidan-label="Accept terms"> Accept terms</label>
|
|
78
|
-
<button class="
|
|
99
|
+
<button class="btn btn-primary" type="submit">Submit</button>
|
|
79
100
|
</form>
|
|
80
101
|
<p class="status" id="native-status" role="status"></p>
|
|
81
102
|
</section>
|
|
@@ -86,7 +107,7 @@
|
|
|
86
107
|
<form id="form-jquery">
|
|
87
108
|
<input name="email" id="jq-email" type="email" required data-zidan="input" data-zidan-label="Email">
|
|
88
109
|
<input name="name" id="jq-name" required minlength="3" data-zidan="input" data-zidan-label="Name">
|
|
89
|
-
<button class="
|
|
110
|
+
<button class="btn btn-primary" type="submit">Submit</button>
|
|
90
111
|
</form>
|
|
91
112
|
<p class="status" id="jquery-status" role="status"></p>
|
|
92
113
|
</section>
|
|
@@ -97,7 +118,7 @@
|
|
|
97
118
|
<form id="form-justvalidate">
|
|
98
119
|
<input name="email" id="jv-email" data-zidan="input" data-zidan-label="Email">
|
|
99
120
|
<input name="name" id="jv-name" data-zidan="input" data-zidan-label="Name">
|
|
100
|
-
<button class="
|
|
121
|
+
<button class="btn btn-primary" type="submit">Submit</button>
|
|
101
122
|
</form>
|
|
102
123
|
<p class="status" id="justvalidate-status" role="status"></p>
|
|
103
124
|
</section>
|
|
@@ -110,13 +131,32 @@
|
|
|
110
131
|
data-zidan="input" data-zidan-label="Email">
|
|
111
132
|
<input name="name" id="parsley-name" data-parsley-required data-parsley-minlength="3"
|
|
112
133
|
data-zidan="input" data-zidan-label="Name">
|
|
113
|
-
<button class="
|
|
134
|
+
<button class="btn btn-primary" type="submit">Submit</button>
|
|
114
135
|
</form>
|
|
115
136
|
<p class="status" id="parsley-status" role="status"></p>
|
|
116
137
|
</section>
|
|
117
138
|
</div>
|
|
139
|
+
|
|
140
|
+
<p class="doc-source-note">
|
|
141
|
+
The native controls stay reachable for each validator. Read the
|
|
142
|
+
<a href="validation-guide.html">validation compatibility guide</a> for configuration and
|
|
143
|
+
double-submit patterns.
|
|
144
|
+
</p>
|
|
118
145
|
</main>
|
|
119
146
|
|
|
147
|
+
<footer class="site-footer">
|
|
148
|
+
<div class="wrap">
|
|
149
|
+
<p>
|
|
150
|
+
<strong>ZidanForm</strong> — MIT licensed, no dependencies.
|
|
151
|
+
<a href="../index.html">Demo</a> ·
|
|
152
|
+
<a href="../playground.html">Playground</a> ·
|
|
153
|
+
<a href="index.html">Documentation</a> ·
|
|
154
|
+
<a href="https://github.com/akhtar1985/zidan-select">GitHub</a>
|
|
155
|
+
</p>
|
|
156
|
+
</div>
|
|
157
|
+
</footer>
|
|
158
|
+
|
|
159
|
+
<script src="../nav.js"></script>
|
|
120
160
|
<script src="../zidan-form.js"></script>
|
|
121
161
|
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
|
|
122
162
|
<script src="https://cdn.jsdelivr.net/npm/jquery-validation@1.20.0/dist/jquery.validate.min.js"></script>
|
package/docs/validation.md
CHANGED
|
@@ -30,12 +30,12 @@ It clears the state on `input`/`change` once validity passes, on `form.reset()`,
|
|
|
30
30
|
native validity.
|
|
31
31
|
|
|
32
32
|
A state set through the public `setValidation('invalid')` (and a preset
|
|
33
|
-
`data-zidan-validation="invalid"`) is **pinned
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
(`setValidation(state, true)`) so they never pin a state
|
|
33
|
+
`data-zidan-validation="invalid"`) is **pinned against re-renders**: `update()`, `refresh()`
|
|
34
|
+
and internal validity mirrors or async re-checks do not clear it. The pin is released by the
|
|
35
|
+
next `input`, `change` or `blur`, or by `setValidation(null)` / `setValidation('valid')`.
|
|
36
|
+
Programmatic value helpers can release it too: field `setValue()` / `setChecked()` dispatch
|
|
37
|
+
`change`, and applying a non-empty select value clears the select's invalid option. Internal
|
|
38
|
+
mirrors pass a second argument (`setValidation(state, true)`) so they never pin a state.
|
|
39
39
|
|
|
40
40
|
## Built-in rules (written into native validity)
|
|
41
41
|
|
|
@@ -104,7 +104,7 @@ email.isPending(); // true while the request is in flight
|
|
|
104
104
|
|
|
105
105
|
Submission is blocked while pending because the native control carries the pending message;
|
|
106
106
|
listen for `zidan:async-validation` if you need your own spinner or toast. `destroy()` aborts
|
|
107
|
-
any in-flight check, and `
|
|
107
|
+
any in-flight check, and `form.reset()` clears the pending state.
|
|
108
108
|
|
|
109
109
|
## The hidden-input trap
|
|
110
110
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zidan-select",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.2",
|
|
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",
|
|
@@ -102,7 +102,7 @@
|
|
|
102
102
|
"test": "node scripts/test.mjs",
|
|
103
103
|
"types": "tsc -p tsconfig.types.json",
|
|
104
104
|
"prepublishOnly": "npm run build && npm run types && 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",
|
|
105
|
+
"lint": "node --check zidan-form.js && node --check demo.js && node --check lab.js && node --check advanced.js && node --check ajax.js && node --check playground.js && node --check nav.js && node --check scripts/docs.mjs && node --check zidan-form.mjs",
|
|
106
106
|
"release": "node scripts/release.mjs",
|
|
107
107
|
"search": "node scripts/exa-search.mjs"
|
|
108
108
|
},
|
package/plugin-core.css
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* ZidanForm v2.4.
|
|
2
|
+
* ZidanForm v2.4.2 — plugin-core.css
|
|
3
3
|
* Structure and mechanics only: layout, positioning, visibility, focus
|
|
4
4
|
* plumbing and accessible native-input handling. No colours, borders colours,
|
|
5
5
|
* shadows or decorative skin — load plugin-theme.css (or your own theme) for
|
package/plugin-theme.css
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* ZidanForm v2.4.
|
|
2
|
+
* ZidanForm v2.4.2 — plugin-theme.css
|
|
3
3
|
* Design tokens, paint, state colours, preset themes (default, modern,
|
|
4
4
|
* minimal, dark, glass), the five select layouts and framework adapters
|
|
5
5
|
* (bootstrap, tailwind, bulma, foundation).
|
package/zidan-form.d.ts
CHANGED
|
@@ -59,19 +59,19 @@ export type FetchOptions = (
|
|
|
59
59
|
export interface SelectCallbacks {
|
|
60
60
|
filterOption?(item: SelectItem, query: string, context: { instance: ZidanSelect; mode: SelectMode; caseSensitive: boolean; selected: boolean }): boolean;
|
|
61
61
|
renderOption?(item: SelectItem, context: { index: number; selected: boolean; active: boolean; query: string; instance: ZidanSelect }): string | Node | null | undefined;
|
|
62
|
-
renderSelected?(item: SelectItem, instance: ZidanSelect): string | Node | null | undefined;
|
|
63
|
-
renderTag?(item: SelectItem, instance: ZidanSelect): string | Node | null | undefined;
|
|
64
|
-
validateTag?(tag: string, tags:
|
|
65
|
-
formatTag?(tag: string, instance: ZidanSelect): string;
|
|
62
|
+
renderSelected?(item: Pick<SelectItem, 'value' | 'label'>, context: { index: number; instance: ZidanSelect }): string | Node | null | undefined;
|
|
63
|
+
renderTag?(item: Pick<SelectItem, 'value' | 'label'>, context: { index: number; instance: ZidanSelect; disabled: boolean }): string | Node | null | undefined;
|
|
64
|
+
validateTag?(tag: string, tags: SelectItem[], context: { instance: ZidanSelect }): boolean | string | void;
|
|
65
|
+
formatTag?(tag: string, context: { instance: ZidanSelect; tags: SelectItem[] }): string;
|
|
66
66
|
onInit?(detail: { instance: ZidanSelect; mode: SelectMode; value: unknown }): void;
|
|
67
|
-
onChange?(detail: { value:
|
|
68
|
-
onSelect?(detail: { value:
|
|
67
|
+
onChange?(detail: { value: unknown; previousValue?: unknown; item?: SelectItem; instance: ZidanSelect }): void;
|
|
68
|
+
onSelect?(detail: { value: unknown; item: SelectItem; instance: ZidanSelect }): void;
|
|
69
69
|
onOpen?(detail: { instance: ZidanSelect }): void;
|
|
70
70
|
onClose?(detail: { instance: ZidanSelect }): void;
|
|
71
|
-
onTagAdd?(detail: { tag: string;
|
|
72
|
-
onTagRemove?(detail: { tag: string;
|
|
71
|
+
onTagAdd?(detail: { tag: string; value: SelectItem[]; instance: ZidanSelect }): void;
|
|
72
|
+
onTagRemove?(detail: { tag: string; value: SelectItem[]; instance: ZidanSelect }): void;
|
|
73
73
|
onLoadMore?(detail: { page: number; query: string; instance: ZidanSelect }): void;
|
|
74
|
-
onError?(detail: { error
|
|
74
|
+
onError?(detail: { error?: unknown; message: string; instance: ZidanSelect }): void;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
export interface SelectOptions extends SelectCallbacks {
|
|
@@ -86,6 +86,7 @@ export interface SelectOptions extends SelectCallbacks {
|
|
|
86
86
|
options?: SelectItemInput[] | null;
|
|
87
87
|
value?: string | string[] | null;
|
|
88
88
|
label?: string | null;
|
|
89
|
+
ariaLabel?: string;
|
|
89
90
|
placeholder?: string | null;
|
|
90
91
|
multiple?: boolean;
|
|
91
92
|
searchable?: boolean;
|
|
@@ -226,16 +227,21 @@ export interface FileFieldOptions extends FieldOptions {
|
|
|
226
227
|
|
|
227
228
|
export interface TextFieldOptions extends FieldOptions {
|
|
228
229
|
icon?: string;
|
|
229
|
-
iconPosition?: '
|
|
230
|
+
iconPosition?: 'left' | 'right';
|
|
230
231
|
prefix?: string;
|
|
231
232
|
suffix?: string;
|
|
232
233
|
clearable?: boolean;
|
|
233
|
-
counter?:
|
|
234
|
-
counterMax?: number;
|
|
234
|
+
counter?: number;
|
|
235
235
|
output?: HTMLOutputElement | string;
|
|
236
|
-
stepper?: boolean;
|
|
237
|
-
|
|
238
|
-
phone?: boolean
|
|
236
|
+
stepper?: boolean | string;
|
|
237
|
+
stepperStep?: number;
|
|
238
|
+
phone?: boolean | {
|
|
239
|
+
country?: string;
|
|
240
|
+
format?: PhoneFormat;
|
|
241
|
+
showCountry?: boolean;
|
|
242
|
+
countries?: string[];
|
|
243
|
+
validate?: boolean;
|
|
244
|
+
};
|
|
239
245
|
phoneCountry?: string;
|
|
240
246
|
phoneFormat?: PhoneFormat;
|
|
241
247
|
rangeVariant?: 'default' | 'gradient' | 'stepped' | 'minimal';
|
|
@@ -308,8 +314,8 @@ export class ZidanSelect {
|
|
|
308
314
|
setValue(value: string | number | Array<string | number> | null, options?: { silent?: boolean }): this;
|
|
309
315
|
clear(): this;
|
|
310
316
|
setOptions(options: SelectItemInput[] | null): this;
|
|
311
|
-
addTag(label: string, data?: unknown):
|
|
312
|
-
removeTag(
|
|
317
|
+
addTag(label: string, data?: unknown): boolean;
|
|
318
|
+
removeTag(tagOrIndex: string | number): boolean;
|
|
313
319
|
getTags(): SelectItem[];
|
|
314
320
|
enable(): this;
|
|
315
321
|
disable(): this;
|
|
@@ -361,7 +367,7 @@ export class ZidanFileUpload extends ZidanFieldBase {
|
|
|
361
367
|
getUploadState(): UploadState[];
|
|
362
368
|
addFiles(files: File[] | FileList): this;
|
|
363
369
|
replaceFiles(files: File[] | FileList): this;
|
|
364
|
-
removeFile(index: number): this;
|
|
370
|
+
removeFile(index: number | File): this;
|
|
365
371
|
clear(): this;
|
|
366
372
|
uploadAll(): this | Promise<boolean>;
|
|
367
373
|
uploadFile(file: File): this | Promise<unknown>;
|
|
@@ -369,7 +375,7 @@ export class ZidanFileUpload extends ZidanFieldBase {
|
|
|
369
375
|
cancelAll(): this;
|
|
370
376
|
retryUpload(file: File): this;
|
|
371
377
|
setVariant(variant: string): this;
|
|
372
|
-
setUploader(handler: UploadHandler | null): this;
|
|
378
|
+
setUploader(handler: UploadHandler | string | null): this;
|
|
373
379
|
}
|
|
374
380
|
|
|
375
381
|
export class ZidanTextField extends ZidanFieldBase {
|
|
@@ -378,8 +384,8 @@ export class ZidanTextField extends ZidanFieldBase {
|
|
|
378
384
|
stepUp(times?: number): this;
|
|
379
385
|
stepDown(times?: number): this;
|
|
380
386
|
setStepper(enabled: boolean): this;
|
|
381
|
-
openPicker():
|
|
382
|
-
showPicker():
|
|
387
|
+
openPicker(): this;
|
|
388
|
+
showPicker(): this;
|
|
383
389
|
getPhoneCountry(): string;
|
|
384
390
|
setPhoneCountry(iso: string): this;
|
|
385
391
|
setPhoneFormat(format: PhoneFormat): this;
|