zidan-select 0.0.0-stage → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +581 -2
- package/dist/plugin-core.css +1073 -0
- package/dist/plugin-theme.css +1277 -0
- package/dist/zidan-form.cjs +2 -0
- package/dist/zidan-form.js +3047 -0
- package/dist/zidan-form.mjs +31 -0
- package/docs/build.md +145 -0
- package/docs/comparison.md +76 -0
- package/docs/frameworks.md +234 -0
- package/docs/index.html +76 -0
- package/docs/options.md +193 -0
- package/docs/theming.md +225 -0
- package/docs/validation.html +200 -0
- package/docs/validation.md +215 -0
- package/package.json +69 -4
- package/plugin-core.css +1073 -0
- package/plugin-theme.css +1277 -0
- package/zidan-form.js +3047 -0
- package/zidan-form.mjs +31 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
# Validation compatibility
|
|
2
|
+
|
|
3
|
+
ZidanForm wraps controls but never removes them. The native input keeps its
|
|
4
|
+
`name`, `value`, `checked`, `files`, `required`, `disabled` and validity state, which is why
|
|
5
|
+
native validation, `FormData` and third-party validators keep working.
|
|
6
|
+
|
|
7
|
+
> **Runnable test bench:** [`validation.html`](validation.html) loads jQuery Validation,
|
|
8
|
+
> JustValidate and Parsley from a CDN next to a native form and the same plugin markup. Open
|
|
9
|
+
> it via a local server (`npm run dev` → `/docs/validation.html`) and submit each empty form.
|
|
10
|
+
|
|
11
|
+
## How state is mirrored
|
|
12
|
+
|
|
13
|
+
| Signal | Written by | Used for |
|
|
14
|
+
| --- | --- | --- |
|
|
15
|
+
| `input.validity` | the browser | source of truth |
|
|
16
|
+
| `aria-invalid` | plugin (`setValidation`) or your validator | screen readers and CSS |
|
|
17
|
+
| `.zs-field--invalid` / `.zs-field--valid` | plugin | theme states |
|
|
18
|
+
| `data-zs-validation="valid\|invalid"` | plugin | attribute-based styling |
|
|
19
|
+
|
|
20
|
+
The plugin marks a field invalid when:
|
|
21
|
+
|
|
22
|
+
1. `invalid` fires on the native control, or
|
|
23
|
+
2. the control is blurred with `validity.valid === false`, or
|
|
24
|
+
3. you call `field.setValidation('invalid')`.
|
|
25
|
+
|
|
26
|
+
It clears the state on `input`/`change` once validity passes, on `form.reset()`, and whenever
|
|
27
|
+
`setValidation(null)` is called. `data-zidan-validation="invalid"` forces the state without
|
|
28
|
+
native validity.
|
|
29
|
+
|
|
30
|
+
## The hidden-input trap
|
|
31
|
+
|
|
32
|
+
jQuery Validation's default `ignore: ":hidden"` checks `offsetWidth`/`offsetHeight`.
|
|
33
|
+
The plugin's native controls are positioned at 1×1 px with `opacity: 0` and `clip-path`, never
|
|
34
|
+
`display: none`, so they stay measurable and are validated. If your configuration or a
|
|
35
|
+
wrapper still hides them, use an explicit ignore list:
|
|
36
|
+
|
|
37
|
+
```js
|
|
38
|
+
$('#form').validate({
|
|
39
|
+
ignore: ':hidden:not(.zs-native-input)', // or simply: ignore: []
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Native HTML5
|
|
44
|
+
|
|
45
|
+
```html
|
|
46
|
+
<form id="native-form" novalidate>
|
|
47
|
+
<input required minlength="3" data-zidan="input" data-zidan-label="Name">
|
|
48
|
+
<input type="email" required data-zidan="input" data-zidan-label="Email">
|
|
49
|
+
<fieldset data-zidan="radio-group" data-zidan-variant="inline">
|
|
50
|
+
<legend>Plan</legend>
|
|
51
|
+
<label><input type="radio" name="plan" value="pro" required> Pro</label>
|
|
52
|
+
<label><input type="radio" name="plan" value="basic"> Basic</label>
|
|
53
|
+
</fieldset>
|
|
54
|
+
<input type="file" required data-zidan="file">
|
|
55
|
+
<button>Send</button>
|
|
56
|
+
</form>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
```js
|
|
60
|
+
const form = document.getElementById('native-form');
|
|
61
|
+
|
|
62
|
+
form.addEventListener('submit', event => {
|
|
63
|
+
event.preventDefault();
|
|
64
|
+
form.querySelectorAll('[data-zidan], [data-zidan-select]').forEach(node => {
|
|
65
|
+
const field = node.__zidanField || node.__zidanSelect;
|
|
66
|
+
if (field) field.update();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
if (!form.checkValidity()) {
|
|
70
|
+
form.querySelector(':invalid')?.focus();
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
submit(new FormData(form));
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Radio groups: validity belongs to the radios. `field.setValidation('invalid')` marks every
|
|
78
|
+
radio, which paints the group border through the theme.
|
|
79
|
+
|
|
80
|
+
## jQuery Validation
|
|
81
|
+
|
|
82
|
+
```html
|
|
83
|
+
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
|
|
84
|
+
<script src="https://cdn.jsdelivr.net/npm/jquery-validation@1.20.0/dist/jquery.validate.min.js"></script>
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
```js
|
|
88
|
+
$('#form').validate({
|
|
89
|
+
ignore: [],
|
|
90
|
+
rules: {
|
|
91
|
+
email: { required: true, email: true }
|
|
92
|
+
},
|
|
93
|
+
errorPlacement(error, element) {
|
|
94
|
+
const field = element.closest('.zs-field');
|
|
95
|
+
if (field) field.appendChild(error);
|
|
96
|
+
else element.after(error);
|
|
97
|
+
},
|
|
98
|
+
highlight(element) {
|
|
99
|
+
element.attr('aria-invalid', 'true');
|
|
100
|
+
element.closest('.zs-field')?.classList.add('zs-field--invalid');
|
|
101
|
+
},
|
|
102
|
+
unhighlight(element) {
|
|
103
|
+
element.removeAttr('aria-invalid');
|
|
104
|
+
element.closest('.zs-field')?.classList.remove('zs-field--invalid');
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
- Put the plugin's native controls where jQuery can see them (default markup does).
|
|
110
|
+
- Do not call `field.destroy()` inside validation callbacks; the field keeps working while
|
|
111
|
+
jQuery toggles classes.
|
|
112
|
+
- `$('form').valid()` works unchanged.
|
|
113
|
+
|
|
114
|
+
## JustValidate
|
|
115
|
+
|
|
116
|
+
```js
|
|
117
|
+
import JustValidate from 'just-validate';
|
|
118
|
+
|
|
119
|
+
const validator = new JustValidate('#form', {
|
|
120
|
+
errorFieldCssClass: 'zs-field--invalid',
|
|
121
|
+
errorLabelStyle: { fontSize: '0.75rem', color: 'var(--zs-border-color-invalid)' },
|
|
122
|
+
errorsContainer: '#form-errors'
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
validator
|
|
126
|
+
.addField('#email', [{ rule: 'required' }, { rule: 'email' }])
|
|
127
|
+
.addField('#notes', [{ rule: 'maxLength', value: 240 }])
|
|
128
|
+
.onSuccess(event => {
|
|
129
|
+
event.preventDefault();
|
|
130
|
+
console.log(Object.fromEntries(new FormData(event.target)));
|
|
131
|
+
});
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
JustValidate adds its class to the native control; give your theme a matching rule if you want
|
|
135
|
+
the wrapper painted:
|
|
136
|
+
|
|
137
|
+
```css
|
|
138
|
+
.zs-field:has(> .zs-input-shell > .zs-field--invalid) .zs-input-shell { border-color: red; }
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
(The built-in `data-zs-validation` state from `onValidation` is usually enough.)
|
|
142
|
+
|
|
143
|
+
## Parsley
|
|
144
|
+
|
|
145
|
+
```html
|
|
146
|
+
<input name="email" type="email" required
|
|
147
|
+
data-zidan="input" data-zidan-label="Email"
|
|
148
|
+
data-parsley-required data-parsley-type="email">
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
```js
|
|
152
|
+
$('#form').parsley({
|
|
153
|
+
errorsContainer(parsleyField) {
|
|
154
|
+
return parsleyField.$element.closest('.zs-field');
|
|
155
|
+
},
|
|
156
|
+
errorClass: 'zs-field--invalid',
|
|
157
|
+
successClass: 'zs-field--valid'
|
|
158
|
+
});
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Parsley appends error `<ul>` elements after the input. When the input is wrapped by the plugin,
|
|
162
|
+
they land inside `.zs-input-shell`; the `errorsContainer` override above places them under the
|
|
163
|
+
field instead.
|
|
164
|
+
|
|
165
|
+
## Preventing double submits
|
|
166
|
+
|
|
167
|
+
The plugin deliberately does not submit or block forms. Use an idempotent guard:
|
|
168
|
+
|
|
169
|
+
```js
|
|
170
|
+
const form = document.getElementById('form');
|
|
171
|
+
form.addEventListener('submit', async event => {
|
|
172
|
+
event.preventDefault();
|
|
173
|
+
if (form.dataset.busy === '1') return;
|
|
174
|
+
form.dataset.busy = '1';
|
|
175
|
+
try {
|
|
176
|
+
await fetch(form.action, { method: form.method, body: new FormData(form) });
|
|
177
|
+
} finally {
|
|
178
|
+
delete form.dataset.busy;
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
For buttons, also set `disabled` while pending — the plugin mirrors `disabled` onto every
|
|
184
|
+
control after `field.update()`.
|
|
185
|
+
|
|
186
|
+
## Reset and dynamic content
|
|
187
|
+
|
|
188
|
+
`form.reset()` restores native values; every field listens for `reset` and re-renders one tick
|
|
189
|
+
later, clearing validation classes. When you replace form markup (framework re-render):
|
|
190
|
+
|
|
191
|
+
```js
|
|
192
|
+
ZidanForm.observe(form); // initialise added nodes automatically
|
|
193
|
+
ZidanForm.refresh(form); // re-sync existing fields without recreating them
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Manual validation API
|
|
197
|
+
|
|
198
|
+
```js
|
|
199
|
+
const field = ZidanForm.get(document.getElementById('email'));
|
|
200
|
+
field.setValidation('invalid'); // classes + aria-invalid
|
|
201
|
+
field.setValidation('valid');
|
|
202
|
+
field.setValidation(null); // clean
|
|
203
|
+
field.getValidation(); // 'valid' | 'invalid' | null
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
`zidan:validation` bubbles from the wrapper for analytics or summary lists.
|
|
207
|
+
|
|
208
|
+
## Checklist
|
|
209
|
+
|
|
210
|
+
- [ ] Core control still has `name` and appears in `new FormData(form)`.
|
|
211
|
+
- [ ] `form.checkValidity()` returns `false` with an empty required field.
|
|
212
|
+
- [ ] Submitting invalid does not double-fire (busy guard).
|
|
213
|
+
- [ ] `aria-invalid` is present on the native input, not only on the wrapper.
|
|
214
|
+
- [ ] After `form.reset()`, values and error classes are cleared.
|
|
215
|
+
- [ ] `destroy()` leaves a working plain form.
|
package/package.json
CHANGED
|
@@ -1,6 +1,71 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zidan-select",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "2.0.2",
|
|
4
|
+
"description": "Zero-dependency form enhancement library: select/combobox/tags, checkboxes, switches, radio groups, drag & drop file upload and text inputs with split core/theme CSS, 5 themes, 5 layouts and framework adapters.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"select",
|
|
7
|
+
"combobox",
|
|
8
|
+
"tags",
|
|
9
|
+
"checkbox",
|
|
10
|
+
"switch",
|
|
11
|
+
"radio",
|
|
12
|
+
"file-upload",
|
|
13
|
+
"form",
|
|
14
|
+
"vanilla-js",
|
|
15
|
+
"zero-dependency",
|
|
16
|
+
"accessible",
|
|
17
|
+
"bootstrap",
|
|
18
|
+
"tailwind"
|
|
19
|
+
],
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"author": "akhtar1985",
|
|
22
|
+
"homepage": "https://akhtar1985.github.io/zidan-select/",
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/akhtar1985/zidan-select.git"
|
|
26
|
+
},
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/akhtar1985/zidan-select/issues"
|
|
29
|
+
},
|
|
30
|
+
"main": "zidan-form.js",
|
|
31
|
+
"module": "zidan-form.mjs",
|
|
32
|
+
"unpkg": "zidan-form.js",
|
|
33
|
+
"jsdelivr": "zidan-form.js",
|
|
34
|
+
"style": "plugin-theme.css",
|
|
35
|
+
"exports": {
|
|
36
|
+
".": {
|
|
37
|
+
"import": "./zidan-form.mjs",
|
|
38
|
+
"require": "./zidan-form.js",
|
|
39
|
+
"default": "./zidan-form.js"
|
|
40
|
+
},
|
|
41
|
+
"./css/core": "./plugin-core.css",
|
|
42
|
+
"./css/theme": "./plugin-theme.css",
|
|
43
|
+
"./core.css": "./plugin-core.css",
|
|
44
|
+
"./theme.css": "./plugin-theme.css",
|
|
45
|
+
"./package.json": "./package.json"
|
|
46
|
+
},
|
|
47
|
+
"files": [
|
|
48
|
+
"zidan-form.js",
|
|
49
|
+
"zidan-form.mjs",
|
|
50
|
+
"plugin-core.css",
|
|
51
|
+
"plugin-theme.css",
|
|
52
|
+
"dist",
|
|
53
|
+
"docs",
|
|
54
|
+
"README.md",
|
|
55
|
+
"LICENSE"
|
|
56
|
+
],
|
|
57
|
+
"sideEffects": [
|
|
58
|
+
"*.css",
|
|
59
|
+
"zidan-form.js",
|
|
60
|
+
"zidan-form.mjs"
|
|
61
|
+
],
|
|
62
|
+
"scripts": {
|
|
63
|
+
"dev": "node scripts/serve.mjs",
|
|
64
|
+
"build": "node scripts/build.mjs",
|
|
65
|
+
"test": "node scripts/test.mjs",
|
|
66
|
+
"lint": "node --check zidan-form.js && node --check demo.js && node --check zidan-form.mjs"
|
|
67
|
+
},
|
|
68
|
+
"engines": {
|
|
69
|
+
"node": ">=18"
|
|
70
|
+
}
|
|
71
|
+
}
|