a11y-form-validator 1.0.0
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/CHANGELOG.md +19 -0
- package/LICENSE +21 -0
- package/README.md +390 -0
- package/dist/A11yFormValidator-D0n6br-b.d.ts +335 -0
- package/dist/A11yFormValidator-D0n6br-b.d.ts.map +1 -0
- package/dist/addons/character-count.d.ts +38 -0
- package/dist/addons/character-count.d.ts.map +1 -0
- package/dist/addons/character-count.js +161 -0
- package/dist/addons/character-count.js.map +1 -0
- package/dist/addons/error-summary.d.ts +29 -0
- package/dist/addons/error-summary.d.ts.map +1 -0
- package/dist/addons/error-summary.js +4 -0
- package/dist/default-BHBWPNeK.d.ts +7 -0
- package/dist/default-BHBWPNeK.d.ts.map +1 -0
- package/dist/default-DFnPBuVC.js +18 -0
- package/dist/default-DFnPBuVC.js.map +1 -0
- package/dist/docs.d.ts +66 -0
- package/dist/docs.d.ts.map +1 -0
- package/dist/docs.js +204 -0
- package/dist/docs.js.map +1 -0
- package/dist/error-summary-FnZoUC72.js +99 -0
- package/dist/error-summary-FnZoUC72.js.map +1 -0
- package/dist/helpers-c_THOe-Q.js +150 -0
- package/dist/helpers-c_THOe-Q.js.map +1 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1197 -0
- package/dist/index.js.map +1 -0
- package/dist/index.min.js +2 -0
- package/dist/index.min.js.map +1 -0
- package/dist/locales/ar.json +13 -0
- package/dist/locales/en.json +13 -0
- package/dist/locales/es.json +13 -0
- package/dist/locales/fr.json +13 -0
- package/dist/locales/hi.json +13 -0
- package/dist/locales/it.json +13 -0
- package/dist/locales/ja.json +13 -0
- package/dist/locales/ko.json +13 -0
- package/dist/locales/nl.json +13 -0
- package/dist/locales/pl.json +13 -0
- package/dist/locales/pt-BR.json +13 -0
- package/dist/locales/ru.json +13 -0
- package/dist/locales/tr.json +13 -0
- package/dist/locales/uk.json +13 -0
- package/dist/locales/zh-CN.json +13 -0
- package/dist/minimal-40_EIW9U.d.ts +7 -0
- package/dist/minimal-40_EIW9U.d.ts.map +1 -0
- package/dist/minimal-Bm3pKoN7.js +15 -0
- package/dist/minimal-Bm3pKoN7.js.map +1 -0
- package/dist/no-summary-BI1pTld5.d.ts +7 -0
- package/dist/no-summary-BI1pTld5.d.ts.map +1 -0
- package/dist/no-summary-DQCNtzs6.js +16 -0
- package/dist/no-summary-DQCNtzs6.js.map +1 -0
- package/dist/presets/default.d.ts +3 -0
- package/dist/presets/default.js +5 -0
- package/dist/presets/minimal.d.ts +3 -0
- package/dist/presets/minimal.js +3 -0
- package/dist/presets/no-summary.d.ts +3 -0
- package/dist/presets/no-summary.js +3 -0
- package/dist/styles.css +91 -0
- package/package.json +95 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 1.0.0 - 2026-07-03
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Initial MIT-licensed release of A11y Form Validator.
|
|
8
|
+
- Core TypeScript form validator with native constraint support, custom rules, async validation, server errors, lifecycle events, and cleanup.
|
|
9
|
+
- Optional error summary and character count addons, default/no-summary/minimal presets, CSS, and opt-in locale JSON files.
|
|
10
|
+
- Static demo gallery and GitHub Pages workflow that builds and uploads `pages-dist`.
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- Normalized the package/import name to `a11y-form-validator`.
|
|
15
|
+
- Updated repository, issue, npm, and demo links for `https://github.com/vmitsaras/A11y-Form-Validator`.
|
|
16
|
+
|
|
17
|
+
### Verification
|
|
18
|
+
|
|
19
|
+
- Release checks should run `npm ci`, `npm run typecheck`, `npm test`, `npm run pages:build`, and `npm run pack:check` before publishing.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Vasileios Mitsaras
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
# A11y Form Validator
|
|
2
|
+
|
|
3
|
+
Accessible, dependency-light progressive enhancement for semantic HTML forms.
|
|
4
|
+
|
|
5
|
+
A11y Form Validator is a progressive enhancement plugin for forms that already use real labels, inputs, selects, textareas, checkboxes, radios, and fieldsets. It reads native validation attributes, supports custom and async rules, applies server errors, renders accessible inline messages, can add a focusable error summary and character counts, supports opt-in locale packs, and cleans up generated DOM when destroyed.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install a11y-form-validator
|
|
11
|
+
pnpm add a11y-form-validator
|
|
12
|
+
yarn add a11y-form-validator
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import {
|
|
19
|
+
createDefaultPreset,
|
|
20
|
+
createFormValidator
|
|
21
|
+
} from "a11y-form-validator";
|
|
22
|
+
import "a11y-form-validator/styles.css";
|
|
23
|
+
|
|
24
|
+
const form = document.querySelector("[data-a11y-form-validator]");
|
|
25
|
+
|
|
26
|
+
if (form instanceof HTMLFormElement) {
|
|
27
|
+
createFormValidator(form, createDefaultPreset());
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
`createDefaultPreset()` includes the error summary addon. Use `createNoSummaryPreset()` when you want the same submit-and-blur validation pattern without summary UI.
|
|
32
|
+
|
|
33
|
+
`new A11yFormValidator(form, options)` is also supported for existing integrations. Duplicate initialization of the same form returns the existing instance.
|
|
34
|
+
|
|
35
|
+
## Which build should I use?
|
|
36
|
+
|
|
37
|
+
### Bundler usage
|
|
38
|
+
|
|
39
|
+
Use the normal package entry when using a bundler such as Vite, Astro, Rollup, Webpack, or similar.
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
import {
|
|
43
|
+
createDefaultPreset,
|
|
44
|
+
createFormValidator
|
|
45
|
+
} from "a11y-form-validator";
|
|
46
|
+
import "a11y-form-validator/styles.css";
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
This gives your bundler the readable ESM build. Your app build process can tree-shake and minify it for production.
|
|
50
|
+
|
|
51
|
+
### Direct browser usage
|
|
52
|
+
|
|
53
|
+
Use the minified build when importing directly in a browser from a built file or CDN-style setup.
|
|
54
|
+
|
|
55
|
+
```html
|
|
56
|
+
<script type="module">
|
|
57
|
+
import {
|
|
58
|
+
createDefaultPreset,
|
|
59
|
+
createFormValidator
|
|
60
|
+
} from "./dist/index.min.js";
|
|
61
|
+
|
|
62
|
+
const form = document.querySelector("[data-a11y-form-validator]");
|
|
63
|
+
|
|
64
|
+
if (form instanceof HTMLFormElement) {
|
|
65
|
+
createFormValidator(form, createDefaultPreset());
|
|
66
|
+
}
|
|
67
|
+
</script>
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
For npm subpath usage:
|
|
71
|
+
|
|
72
|
+
```js
|
|
73
|
+
import {
|
|
74
|
+
createDefaultPreset,
|
|
75
|
+
createFormValidator
|
|
76
|
+
} from "a11y-form-validator/min";
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Rule of thumb:
|
|
80
|
+
|
|
81
|
+
```txt
|
|
82
|
+
Using a bundler? Use the normal import.
|
|
83
|
+
Using the file directly on a site? Use the minified file.
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Build output
|
|
87
|
+
|
|
88
|
+
`npm run build:dist` writes both browser-ready ESM files:
|
|
89
|
+
|
|
90
|
+
- `dist/index.js` and `dist/index.js.map` - readable, source-mapped default package entry.
|
|
91
|
+
- `dist/index.min.js` and `dist/index.min.js.map` - optional minified entry for direct browser or CDN-style imports.
|
|
92
|
+
|
|
93
|
+
Both entries use `dist/index.d.ts` for types. The package `"."` export stays on `dist/index.js`; only the `./min` subpath points to `dist/index.min.js`.
|
|
94
|
+
|
|
95
|
+
## CSS
|
|
96
|
+
|
|
97
|
+
Import the default styles when you want the provided error, summary, focus, and character count presentation:
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
import "a11y-form-validator/styles.css";
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The main block class is `.a11y-form-validator`. Public custom properties include:
|
|
104
|
+
|
|
105
|
+
- `--a11y-form-validator-error-color`
|
|
106
|
+
- `--a11y-form-validator-border-color`
|
|
107
|
+
- `--a11y-form-validator-focus-color`
|
|
108
|
+
- `--a11y-form-validator-success-color`
|
|
109
|
+
- `--a11y-form-validator-pending-color`
|
|
110
|
+
- `--a11y-form-validator-error-shadow`
|
|
111
|
+
- `--a11y-form-validator-gap`
|
|
112
|
+
- `--a11y-form-validator-radius`
|
|
113
|
+
- `--a11y-form-validator-font-size`
|
|
114
|
+
- `--a11y-form-validator-summary-background`
|
|
115
|
+
- `--a11y-form-validator-character-count-color`
|
|
116
|
+
|
|
117
|
+
State classes such as `.is-valid`, `.is-invalid`, `.is-pending`, `.is-touched`, `.is-dirty`, and `.is-disabled` are applied to controls. Reduced motion is respected for plugin scroll behavior.
|
|
118
|
+
|
|
119
|
+
## HTML Structure
|
|
120
|
+
|
|
121
|
+
Use normal form markup with labels. Each field needs a `name` or `id`.
|
|
122
|
+
|
|
123
|
+
```html
|
|
124
|
+
<form data-a11y-form-validator>
|
|
125
|
+
<label for="email">Email</label>
|
|
126
|
+
<input id="email" name="email" type="email" required />
|
|
127
|
+
|
|
128
|
+
<label for="message">Message</label>
|
|
129
|
+
<textarea id="message" name="message" required minlength="10" maxlength="180" data-character-count></textarea>
|
|
130
|
+
|
|
131
|
+
<fieldset>
|
|
132
|
+
<legend>Preferred reply method</legend>
|
|
133
|
+
<label><input name="replyMethod" type="radio" value="email" required /> Email</label>
|
|
134
|
+
<label><input name="replyMethod" type="radio" value="phone" required /> Phone</label>
|
|
135
|
+
</fieldset>
|
|
136
|
+
|
|
137
|
+
<button type="submit">Send</button>
|
|
138
|
+
</form>
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Supported native rules include `required`, `type="email"`, `minlength`, `maxlength`, `pattern`, required checkbox, radio groups, and checkbox groups.
|
|
142
|
+
|
|
143
|
+
Data attributes can add rules and messages:
|
|
144
|
+
|
|
145
|
+
```html
|
|
146
|
+
<input
|
|
147
|
+
name="username"
|
|
148
|
+
required
|
|
149
|
+
data-validate="min-length:3 pattern:^[a-z0-9_]+$"
|
|
150
|
+
data-message-required="Choose a username."
|
|
151
|
+
/>
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## API
|
|
155
|
+
|
|
156
|
+
### `createFormValidator(form, options)`
|
|
157
|
+
|
|
158
|
+
Initializes a form and returns an `A11yFormValidatorInstance`.
|
|
159
|
+
|
|
160
|
+
```ts
|
|
161
|
+
import { createErrorSummaryAddon } from "a11y-form-validator/addons/error-summary";
|
|
162
|
+
import { createCharacterCountAddon } from "a11y-form-validator/addons/character-count";
|
|
163
|
+
|
|
164
|
+
const validator = createFormValidator(form, {
|
|
165
|
+
validateOn: ["submit", "blur", "input"],
|
|
166
|
+
focusOnError: "summary",
|
|
167
|
+
errorMode: "both",
|
|
168
|
+
addons: [createErrorSummaryAddon(), createCharacterCountAddon()]
|
|
169
|
+
});
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### `initFormValidators(options, root)`
|
|
173
|
+
|
|
174
|
+
Initializes every form matching `[data-a11y-form-validator]` under `root`.
|
|
175
|
+
|
|
176
|
+
```ts
|
|
177
|
+
import { createDefaultPreset } from "a11y-form-validator/presets/default";
|
|
178
|
+
|
|
179
|
+
const validators = initFormValidators(createDefaultPreset());
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Options
|
|
183
|
+
|
|
184
|
+
| Option | Default | Description |
|
|
185
|
+
| --- | --- | --- |
|
|
186
|
+
| `validateOn` | `["submit"]` | Events that trigger validation: `submit`, `blur`, `input`, `change`. |
|
|
187
|
+
| `focusOnError` | `"summary"` | Use `"summary"`, `"first-invalid"`, or `false`. |
|
|
188
|
+
| `errorMode` | `"inline"` | Use `"inline"`, `"native"`, or `"both"`. |
|
|
189
|
+
| `useNativeRules` | `true` | Reads native HTML validation attributes. |
|
|
190
|
+
| `disableNativeUI` | `true` | Adds `novalidate` unless native-only mode is used. |
|
|
191
|
+
| `validateHidden` | `false` | Validates hidden fields when true. |
|
|
192
|
+
| `ignore.disabled` | `true` | Skips disabled fields. |
|
|
193
|
+
| `ignore.hidden` | `true` | Skips hidden fields unless `validateHidden` is true. |
|
|
194
|
+
| `ignore.selector` | `""` | Skips matching controls. |
|
|
195
|
+
| `debounce` | `150` | Debounce delay for input validation. |
|
|
196
|
+
| `messages` | `{}` | Global, field-specific, or function messages. |
|
|
197
|
+
| `locales` | `{}` | Locale message packs keyed by locale code. |
|
|
198
|
+
| `locale` | `""` | Explicit locale; falls back to form/document language and English. |
|
|
199
|
+
| `selectors.fields` | `"input, select, textarea"` | Field selector used by `refresh()`. |
|
|
200
|
+
| `addons` | `[]` | Addon objects imported from addon or preset subpaths. |
|
|
201
|
+
| `renderer` | `null` | Custom renderer implementing `render()`, `clear()`, and optional `destroy()`. |
|
|
202
|
+
| `rules` | `{}` | Field-specific rule configuration keyed by field `name` or `id`. |
|
|
203
|
+
|
|
204
|
+
### Instance Methods
|
|
205
|
+
|
|
206
|
+
- `validate(options?)`
|
|
207
|
+
- `validateField(fieldOrNameOrElement, options?)`
|
|
208
|
+
- `refresh()`
|
|
209
|
+
- `reset()`
|
|
210
|
+
- `clearErrors()`
|
|
211
|
+
- `setErrors(errors)`
|
|
212
|
+
- `getErrors()`
|
|
213
|
+
- `getState()`
|
|
214
|
+
- `enable()`
|
|
215
|
+
- `disable()`
|
|
216
|
+
- `focusOnError()`
|
|
217
|
+
- `destroy()`
|
|
218
|
+
- `registerRule(name, rule)`
|
|
219
|
+
- `unregisterRule(name)`
|
|
220
|
+
|
|
221
|
+
Server errors can be applied with either a field map or explicit `fields`/`form` keys:
|
|
222
|
+
|
|
223
|
+
```ts
|
|
224
|
+
validator.setErrors({
|
|
225
|
+
fields: {
|
|
226
|
+
email: "This email is already registered."
|
|
227
|
+
},
|
|
228
|
+
form: "Your session expired. Reload the page and try again."
|
|
229
|
+
});
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### Presets And Addons
|
|
233
|
+
|
|
234
|
+
Preset helpers are available from the main entry and from explicit subpaths. Use explicit subpaths when you want narrower imports:
|
|
235
|
+
|
|
236
|
+
```ts
|
|
237
|
+
import { createDefaultPreset } from "a11y-form-validator/presets/default";
|
|
238
|
+
import { createNoSummaryPreset } from "a11y-form-validator/presets/no-summary";
|
|
239
|
+
import { createMinimalPreset } from "a11y-form-validator/presets/minimal";
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
`createDefaultPreset()` validates on submit and blur, uses inline and native messages, imports and installs the error summary addon, and focuses the summary after blocked submits. Because it imports the summary addon, choose it only when you want summary UI.
|
|
243
|
+
|
|
244
|
+
`createNoSummaryPreset()` keeps the same submit and blur validation cadence, inline and native messages, native rule reading, and native UI suppression as the default preset, but it installs no addons and focuses the first invalid field.
|
|
245
|
+
|
|
246
|
+
`createMinimalPreset()` validates on submit and focuses the first invalid field.
|
|
247
|
+
|
|
248
|
+
The error summary addon prepends a focusable, labelled summary with field-labelled links to invalid fields and plain-text form-level errors. The character count addon adds a polite live region for controls with `maxlength`, `minlength`, or `data-character-count`.
|
|
249
|
+
|
|
250
|
+
```ts
|
|
251
|
+
import { createNoSummaryPreset } from "a11y-form-validator/presets/no-summary";
|
|
252
|
+
import { createErrorSummaryAddon } from "a11y-form-validator/addons/error-summary";
|
|
253
|
+
import { createCharacterCountAddon } from "a11y-form-validator/addons/character-count";
|
|
254
|
+
|
|
255
|
+
const preset = createNoSummaryPreset();
|
|
256
|
+
createFormValidator(form, {
|
|
257
|
+
...preset,
|
|
258
|
+
focusOnError: "summary",
|
|
259
|
+
addons: [createErrorSummaryAddon(), createCharacterCountAddon()]
|
|
260
|
+
});
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### Localization
|
|
264
|
+
|
|
265
|
+
English messages are bundled as the default fallback. Other locale packs are published as opt-in JSON files so they do not increase the main bundle.
|
|
266
|
+
|
|
267
|
+
```ts
|
|
268
|
+
import { createDefaultPreset } from "a11y-form-validator/presets/default";
|
|
269
|
+
import esMessages from "a11y-form-validator/locales/es.json" with { type: "json" };
|
|
270
|
+
|
|
271
|
+
createFormValidator(form, {
|
|
272
|
+
...createDefaultPreset(),
|
|
273
|
+
locale: "es",
|
|
274
|
+
locales: {
|
|
275
|
+
es: esMessages
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
You can also provide inline locale messages during initialization:
|
|
281
|
+
|
|
282
|
+
```ts
|
|
283
|
+
createFormValidator(form, {
|
|
284
|
+
locale: "product",
|
|
285
|
+
locales: {
|
|
286
|
+
product: {
|
|
287
|
+
required: "{fieldLabel} is required before you continue."
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
Configured locale lookup uses the explicit `locale`, then the form or document language, then English fallback. Field-level `data-message-*` and `messages.fields` entries still override locale packs. Use `summaryItem` to customize how summary links combine field labels and messages; the default is `{fieldLabel}: {message}`.
|
|
294
|
+
|
|
295
|
+
## Events
|
|
296
|
+
|
|
297
|
+
Events bubble from the form. Event detail includes both `instance` and `validator` for compatibility.
|
|
298
|
+
|
|
299
|
+
| Event | Notes |
|
|
300
|
+
| --- | --- |
|
|
301
|
+
| `a11y-form-validator:init` | Fired after fields, listeners, and addons are installed. |
|
|
302
|
+
| `a11y-form-validator:before-validate` | Fired before form validation. |
|
|
303
|
+
| `a11y-form-validator:after-validate` | Fired after validation with `valid` and `errors`. |
|
|
304
|
+
| `a11y-form-validator:field-valid` | Fired when a field validates successfully. |
|
|
305
|
+
| `a11y-form-validator:field-invalid` | Fired with `field`, `message`, and `reason`. |
|
|
306
|
+
| `a11y-form-validator:form-valid` | Fired when the form is valid. |
|
|
307
|
+
| `a11y-form-validator:form-invalid` | Fired when the form is invalid. |
|
|
308
|
+
| `a11y-form-validator:submit-blocked` | Fired after a submit is prevented. |
|
|
309
|
+
| `a11y-form-validator:destroy` | Fired after cleanup. |
|
|
310
|
+
|
|
311
|
+
## Accessibility Notes
|
|
312
|
+
|
|
313
|
+
- The plugin keeps native form controls and labels in place.
|
|
314
|
+
- Inline errors are connected with `aria-describedby` and `aria-errormessage`.
|
|
315
|
+
- Generated inline errors use a polite live region for field-level validation.
|
|
316
|
+
- During blocked submits that focus the error summary, generated inline errors stay associated with fields but do not create competing live-region announcements.
|
|
317
|
+
- The summary addon creates a focusable, labelled error summary with field-labelled links to invalid fields and plain-text form-level errors.
|
|
318
|
+
- Focus moves to the summary or first invalid field after a blocked submit, depending on `focusOnError`.
|
|
319
|
+
- When applying server errors with `setErrors()`, call `focusOnError()` if the error summary or first invalid field should be announced immediately.
|
|
320
|
+
- Existing `aria-describedby` values are preserved and restored when errors clear or the plugin is destroyed.
|
|
321
|
+
- Radio groups and checkbox groups are treated as grouped fields when they share a `name`.
|
|
322
|
+
- Keyboard behavior remains native: Tab moves through controls and summary links; Enter submits forms or activates links; Space toggles checkboxes and radio buttons.
|
|
323
|
+
|
|
324
|
+
Still test customized forms with your target browsers and assistive technologies.
|
|
325
|
+
|
|
326
|
+
## Limitations
|
|
327
|
+
|
|
328
|
+
- The plugin validates controls collected by `selectors.fields`; custom widgets need custom rules or a custom renderer.
|
|
329
|
+
- Remote validation is supported through async custom rules, but request cancellation is the application’s responsibility. Pending state is exposed through state, events, and `.is-pending`; add an application live status such as "Checking..." when users need progress announcements.
|
|
330
|
+
- The default CSS is intentionally minimal and may need product-specific layout styles.
|
|
331
|
+
- Native browser validation messages vary by browser and locale when `errorMode` includes native behavior.
|
|
332
|
+
|
|
333
|
+
## Examples
|
|
334
|
+
|
|
335
|
+
Interactive demos are published on GitHub Pages:
|
|
336
|
+
|
|
337
|
+
- [Demo gallery](https://vmitsaras.github.io/A11y-Form-Validator/)
|
|
338
|
+
|
|
339
|
+
Repository demo source is also available on GitHub:
|
|
340
|
+
|
|
341
|
+
- [Basic demo](https://github.com/vmitsaras/A11y-Form-Validator/blob/main/demo/basic.html) - default preset, inline errors, summary links, grouped choices, and character count guidance.
|
|
342
|
+
- [Direct browser minified build demo](https://github.com/vmitsaras/A11y-Form-Validator/blob/main/demo/minified.html) - imports the optional `dist/index.min.js` entry directly.
|
|
343
|
+
- [Contact Form demo](https://github.com/vmitsaras/A11y-Form-Validator/blob/main/demo/contact.html) - minimal preset with native required, email, and minlength checks.
|
|
344
|
+
- [CMS Markup demo](https://github.com/vmitsaras/A11y-Form-Validator/blob/main/demo/cms-markup.html) - data-attribute rules and field-specific messages.
|
|
345
|
+
- [Error Summary demo](https://github.com/vmitsaras/A11y-Form-Validator/blob/main/demo/error-summary.html) - focusable summary region with links back to invalid fields.
|
|
346
|
+
- [Registration demo](https://github.com/vmitsaras/A11y-Form-Validator/blob/main/demo/registration.html) - password confirmation with a custom `same-as` rule.
|
|
347
|
+
- [Login / Register demo](https://github.com/vmitsaras/A11y-Form-Validator/blob/main/demo/login-register.html) - switch between auth forms while only the visible form is active and validated.
|
|
348
|
+
- [Checkout demo](https://github.com/vmitsaras/A11y-Form-Validator/blob/main/demo/checkout.html) - conditional billing validation and grouped payment choices.
|
|
349
|
+
- [Remote Validation demo](https://github.com/vmitsaras/A11y-Form-Validator/blob/main/demo/remote-validation.html) - async username availability checks and pending state review.
|
|
350
|
+
- [Server Errors demo](https://github.com/vmitsaras/A11y-Form-Validator/blob/main/demo/server-errors.html) - backend field and form errors rendered with `setErrors()`.
|
|
351
|
+
- [Localization demo](https://github.com/vmitsaras/A11y-Form-Validator/blob/main/demo/localization.html) - English fallback, imported locale JSON, and inline locale messages.
|
|
352
|
+
- [Dynamic Locale demo](https://github.com/vmitsaras/A11y-Form-Validator/blob/main/demo/dynamic-locale.html) - destroy and reinitialize the validator to change runtime error language.
|
|
353
|
+
- [Demo gallery](https://github.com/vmitsaras/A11y-Form-Validator/tree/main/demo)
|
|
354
|
+
|
|
355
|
+
Build the package with `npm run build` before opening local example or demo pages, because they import from `dist`. Most demos use the readable `dist/index.js`; the direct browser minified build demo uses `dist/index.min.js`.
|
|
356
|
+
|
|
357
|
+
Build the GitHub Pages artifact with `npm run pages:build`. The generated static site is written to `pages-dist/` for the Pages workflow.
|
|
358
|
+
|
|
359
|
+
### GitHub Pages demo build
|
|
360
|
+
|
|
361
|
+
The Pages artifact copies the full `dist/` directory because the readable ESM build may reference generated shared chunks.
|
|
362
|
+
|
|
363
|
+
Do not copy only `dist/index.js`. If `index.js` imports generated chunk files, those files must also be deployed.
|
|
364
|
+
|
|
365
|
+
The minified demo uses `dist/index.min.js`, but the regular demos intentionally use `dist/index.js` to verify the normal package build.
|
|
366
|
+
|
|
367
|
+
For first-time GitHub Pages deployment, enable GitHub Actions as the Pages source in the repository settings: Settings -> Pages -> Build and deployment -> Source -> GitHub Actions. The default workflow token cannot self-enable Pages through `actions/configure-pages`; after the setting exists, the workflow deploys `pages-dist/`.
|
|
368
|
+
|
|
369
|
+
## Docs Metadata
|
|
370
|
+
|
|
371
|
+
```ts
|
|
372
|
+
import { docs } from "a11y-form-validator/docs";
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
This `docs` subpath is a package export, not a source folder. The metadata lives in `src/docs.ts` and is built to `dist/docs.js` and `dist/docs.d.ts`.
|
|
376
|
+
|
|
377
|
+
## Development
|
|
378
|
+
|
|
379
|
+
```bash
|
|
380
|
+
npm install
|
|
381
|
+
npm run typecheck
|
|
382
|
+
npm run test
|
|
383
|
+
npm run build
|
|
384
|
+
npm run pages:build
|
|
385
|
+
npm run pack:check
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
The repository also includes `MANUAL_QA.md` for final browser, accessibility, privacy, package, and human sign-off checks.
|
|
389
|
+
|
|
390
|
+
Do not run publish, push, tag, or release commands unless you intend to perform a release.
|