enhance-web-forms — Production-Quality Forms
Degree of freedom: MIXED. Schema and state-machine judgment [HIGH freedom]; a11y probes and playwright walks [LOW freedom — run exactly].
Forms are where users hand you their data and where apps most often feel broken: unlabeled
fields, validation that fires on every keystroke, errors screen readers never announce, a
submit button that does nothing visible for three seconds, and no recovery when the request
fails. This skill fixes all of that on real forms in the repo.
A form is done when it is accessible, validated on both sides, gives feedback for every
state, and recovers from failure. Compile-clean is not done.
Before any browser interaction, read protocol-browser-anti-stall and apply it.
How to reason
- Inventory — forms, library, schema; bow out if none
- Structure — programmatic labels, types, error association
- Parity — one schema both sides; blur + submit, not every keystroke
- States — submitting / success / error / unsaved; recover on failure
Worked example
Inventory: signup uses raw <form> + inline if (!email); API validates with zod.
Structure: htmlFor labels; autocomplete="email"; aria-invalid + summary.
Parity: share the zod schema; validate on blur/submit; map "email taken" to the field.
States: submit disables + aria-busy; values preserved on 500; dirty-nav warn.
Self-critique before reporting
- Labeled — placeholder is never the only name
- Both sides — client and server rules match; error shapes map to fields
- Walked — empty, invalid, valid, and server-error paths in the browser
- Right owner — page/flow UX beyond the form →
enhance-web-ux; WCAG sweep → audit-accessibility
Phase 0 — Detect the stack and inventory forms [HIGH freedom]
cat package.json | grep -iE "react-hook-form|formik|@tanstack/react-form|final-form|zod|yup|valibot|superstruct"
rg -n "<form|onSubmit|useForm|handleSubmit" -g "*.{tsx,jsx,vue,svelte}" -l
Record: form library (or native), validation/schema library, UI/component library, and the
list of forms to enhance (auth, checkout, settings, contact, search, etc.). If there are no
forms, bow out.
Phase 1 — Research + prioritize [HIGH freedom]
Follow /research: Context7 for the detected form/validation library's current API;
Firecrawl for current form UX/a11y guidance dated to now. Prioritize forms by traffic and
risk (auth, payment, destructive actions first).
Phase 2 — Accessible structure (the foundation) [HIGH freedom]
For each form, verify/fix:
- Every input has a programmatic label —
<label htmlFor> or aria-label; placeholder
is not a label.
- Correct input types +
autocomplete — type="email|tel|url|number", inputmode,
autocomplete="email|current-password|cc-number|..." for autofill.
- Grouping — related inputs in
<fieldset> + <legend> (radio groups, address blocks).
- Required + optional — marked in text, not color alone;
required / aria-required.
- Keyboard + focus — logical tab order, visible focus ring, Enter submits, no keyboard traps.
- Error association — each field error linked via
aria-describedby; invalid fields get
aria-invalid="true"; a form-level error summary with links to fields on submit failure.
rg -n "placeholder=" -g "*.{tsx,jsx}" # placeholders masquerading as labels?
rg -n "aria-describedby|aria-invalid|htmlFor|aria-label" -g "*.{tsx,jsx}" -c
Phase 3 — Validation (schema-driven, both sides) [HIGH freedom]
- Single schema as SSOT — define validation once (zod/yup/valibot) and share it
between client and server so rules can't drift. If the backend validates separately,
reconcile the two so error shapes match.
- Timing — validate on blur and on submit, not on every keystroke; re-validate a
field on change after it has errored once (so users see fixes immediately).
- Messages — specific and actionable ("Password needs 8+ characters", not "Invalid").
- Server errors — map field-level server errors back onto the right inputs; show
form-level errors (e.g. "Email already registered") in the summary.
Phase 4 — States & feedback (every one, no gaps) [HIGH freedom]
Wire the full state machine for each form and submit:
| State |
Required behavior |
| Idle |
Clean, submit enabled/disabled per validity policy |
| Validating |
Inline field feedback (see Phase 3 timing) |
| Submitting |
Submit shows spinner/label swap + disabled + aria-busy; prevent double-submit |
| Success |
Confirmation (toast/inline/redirect); reset or lock as appropriate |
| Error |
Preserve entered values; surface the failure; keep the user's place; retry path |
| Empty/optional |
Sensible defaults; empty state for dependent selects |
Also handle:
- Multi-step — progress indicator, per-step validation, back/forward preserves data,
final review before submit.
- Unsaved-changes guard — warn on navigation away from a dirty form.
- Autosave / draft — for long forms, if the app already has a persistence pattern.
- Micro-feedback — subtle transitions on error/success via
design-motion conventions
(reduced-motion safe). Don't animate layout in a way that shifts fields.
Phase 5 — Verify and report [LOW freedom — do not skip]
- playwright-cli: walk each form — tab through it, submit empty (see the error summary +
focus moves to first error), submit invalid, submit valid, force a server error. Check
console. Confirm screen-reader names via the accessibility snapshot.
Screenshots to .playwright-mcp/.
- Build/typecheck/lint: run the repo's commands.
## Forms Enhancement — report
**Stack:** form=[..] · validation=[..] · UI=[..]
**Forms upgraded:** [list]
**Structure:** labels/types/autocomplete/fieldsets fixed on [N] forms
**Validation:** shared schema SSOT · client↔server parity · blur+submit timing
**States:** submitting/success/error/multi-step/unsaved-guard wired
**A11y:** error summary + aria-describedby/aria-invalid + focus management (evidence)
**Verification:** build ✓ · console clean ✓ · flows walked (screenshots [paths])
Related
audit-accessibility — deep WCAG audit (run to verify the a11y work)
audit-ux — form usability heuristics, microcopy, cognitive load
audit-fe-api — validate the submit request/response contract against the backend
backend-error-handling — server-side validation + structured error responses
design-motion — reduced-motion-safe micro-feedback for error/success
enhance-web-ux — broader page/flow UX beyond the form itself
1---2name: enhance-web-forms-23description: Build or upgrade web forms to production quality: accessible structure, schema-driven validation, client↔server parity. Use when "improve this form", "form validation", "accessible form", "multi-step form", "form error handling", or "the form UX is bad".4license: MIT5---67# enhance-web-forms — Production-Quality Forms89**Degree of freedom: MIXED.** Schema and state-machine judgment `[HIGH freedom]`; a11y probes and playwright walks `[LOW freedom — run exactly]`.1011Forms are where users hand you their data and where apps most often feel broken: unlabeled12fields, validation that fires on every keystroke, errors screen readers never announce, a13submit button that does nothing visible for three seconds, and no recovery when the request14fails. This skill fixes all of that on real forms in the repo.1516> **A form is done when it is accessible, validated on both sides, gives feedback for every17> state, and recovers from failure.** Compile-clean is not done.1819**Before any browser interaction, read `protocol-browser-anti-stall` and apply it.**2021## How to reason22231. **Inventory** — forms, library, schema; bow out if none242. **Structure** — programmatic labels, types, error association253. **Parity** — one schema both sides; blur + submit, not every keystroke264. **States** — submitting / success / error / unsaved; recover on failure2728## Worked example2930> **Inventory:** signup uses raw `<form>` + inline `if (!email)`; API validates with zod.31> **Structure:** `htmlFor` labels; `autocomplete="email"`; `aria-invalid` + summary.32> **Parity:** share the zod schema; validate on blur/submit; map "email taken" to the field.33> **States:** submit disables + `aria-busy`; values preserved on 500; dirty-nav warn.3435## Self-critique before reporting3637- **Labeled** — placeholder is never the only name38- **Both sides** — client and server rules match; error shapes map to fields39- **Walked** — empty, invalid, valid, and server-error paths in the browser40- **Right owner** — page/flow UX beyond the form → `enhance-web-ux`; WCAG sweep → `audit-accessibility`4142---4344## Phase 0 — Detect the stack and inventory forms [HIGH freedom]4546```bash47cat package.json | grep -iE "react-hook-form|formik|@tanstack/react-form|final-form|zod|yup|valibot|superstruct"48rg -n "<form|onSubmit|useForm|handleSubmit" -g "*.{tsx,jsx,vue,svelte}" -l49```5051Record: form library (or native), validation/schema library, UI/component library, and the52list of forms to enhance (auth, checkout, settings, contact, search, etc.). If there are no53forms, bow out.5455---5657## Phase 1 — Research + prioritize [HIGH freedom]5859Follow `/research`: Context7 for the detected form/validation library's current API;60Firecrawl for current form UX/a11y guidance dated to now. Prioritize forms by traffic and61risk (auth, payment, destructive actions first).6263---6465## Phase 2 — Accessible structure (the foundation) [HIGH freedom]6667For each form, verify/fix:6869- **Every input has a programmatic label** — `<label htmlFor>` or `aria-label`; placeholder70 is **not** a label.71- **Correct input types + `autocomplete`** — `type="email|tel|url|number"`, `inputmode`,72 `autocomplete="email|current-password|cc-number|..."` for autofill.73- **Grouping** — related inputs in `<fieldset>` + `<legend>` (radio groups, address blocks).74- **Required + optional** — marked in text, not color alone; `required` / `aria-required`.75- **Keyboard + focus** — logical tab order, visible focus ring, Enter submits, no keyboard traps.76- **Error association** — each field error linked via `aria-describedby`; invalid fields get77 `aria-invalid="true"`; a form-level error **summary** with links to fields on submit failure.7879```bash80rg -n "placeholder=" -g "*.{tsx,jsx}" # placeholders masquerading as labels?81rg -n "aria-describedby|aria-invalid|htmlFor|aria-label" -g "*.{tsx,jsx}" -c82```8384---8586## Phase 3 — Validation (schema-driven, both sides) [HIGH freedom]8788- **Single schema as SSOT** — define validation once (zod/yup/valibot) and share it89 between client and server so rules can't drift. If the backend validates separately,90 reconcile the two so error shapes match.91- **Timing** — validate on **blur** and on **submit**, not on every keystroke; re-validate a92 field on change **after** it has errored once (so users see fixes immediately).93- **Messages** — specific and actionable ("Password needs 8+ characters", not "Invalid").94- **Server errors** — map field-level server errors back onto the right inputs; show95 form-level errors (e.g. "Email already registered") in the summary.9697---9899## Phase 4 — States & feedback (every one, no gaps) [HIGH freedom]100101Wire the full state machine for each form and submit:102103| State | Required behavior |104|---|---|105| Idle | Clean, submit enabled/disabled per validity policy |106| Validating | Inline field feedback (see Phase 3 timing) |107| Submitting | Submit shows spinner/label swap + `disabled` + `aria-busy`; prevent double-submit |108| Success | Confirmation (toast/inline/redirect); reset or lock as appropriate |109| Error | Preserve entered values; surface the failure; keep the user's place; retry path |110| Empty/optional | Sensible defaults; empty state for dependent selects |111112Also handle:113- **Multi-step** — progress indicator, per-step validation, back/forward preserves data,114 final review before submit.115- **Unsaved-changes guard** — warn on navigation away from a dirty form.116- **Autosave / draft** — for long forms, if the app already has a persistence pattern.117- **Micro-feedback** — subtle transitions on error/success via `design-motion` conventions118 (reduced-motion safe). Don't animate layout in a way that shifts fields.119120---121122## Phase 5 — Verify and report [LOW freedom — do not skip]123124- **playwright-cli:** walk each form — tab through it, submit empty (see the error summary +125 focus moves to first error), submit invalid, submit valid, force a server error. Check126 `console`. Confirm screen-reader names via the accessibility snapshot.127 Screenshots to `.playwright-mcp/`.128- **Build/typecheck/lint:** run the repo's commands.129130```markdown131## Forms Enhancement — report132**Stack:** form=[..] · validation=[..] · UI=[..]133**Forms upgraded:** [list]134**Structure:** labels/types/autocomplete/fieldsets fixed on [N] forms135**Validation:** shared schema SSOT · client↔server parity · blur+submit timing136**States:** submitting/success/error/multi-step/unsaved-guard wired137**A11y:** error summary + aria-describedby/aria-invalid + focus management (evidence)138**Verification:** build ✓ · console clean ✓ · flows walked (screenshots [paths])139```140141---142143## Related144145- `audit-accessibility` — deep WCAG audit (run to verify the a11y work)146- `audit-ux` — form usability heuristics, microcopy, cognitive load147- `audit-fe-api` — validate the submit request/response contract against the backend148- `backend-error-handling` — server-side validation + structured error responses149- `design-motion` — reduced-motion-safe micro-feedback for error/success150- `enhance-web-ux` — broader page/flow UX beyond the form itself