agentleFS
hi-donwihi-donwi/Donwi-Skills/skills/forms-and-validation/SKILL.md

forms-and-validation

Skill0 starsChanged 12 days agoMITView on GitHub

Build correct, accessible, recoverable forms: native controls first, one schema for client and server, announced errors, submit and pending states, autofill. Use when building or fixing any form or validation rule. Do not use for component structure (frontend-ui- engineering), API contract shape (api-design), or page audits (accessibility-audit).

2 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Files
SKILL.md

Forms and Validation

Overview

Forms concentrate every hard part of a UI in one place: state, async, error handling, accessibility and trust. They are also where the most user effort is at stake — a form that loses what someone typed costs them the whole task, not a click.

When to use

  • Building or changing any form, field, or validation rule
  • Errors are shown but not announced, or not associated with their field
  • A submit can be fired twice, or the user cannot tell whether it worked
  • Validation disagrees between client and server
  • Autofill does not work, or mobile shows the wrong keyboard

Hand off when

NeedSkill
Component decomposition and file layoutfrontend-ui-engineering
Field sizing, wrapping, RTLresponsive-layout
The request and error contractapi-design
Auditing the finished pageaccessibility-audit

Process

  1. Native controls first. <form>, <label>, <input>, <button type="submit">. They bring keyboard behaviour, autofill, mobile keyboards, password managers and Enter-to- submit at no cost. Every custom control re-implements those and usually misses some.
  2. One schema, both sides. Define the rules once and run them on the client for speed and on the server for truth. Two hand-written copies drift, and the drift is a security hole rather than an inconvenience.
  3. Validate on blur and on submit, not on every keystroke. Telling someone their email is invalid while they are typing the third character is noise. After a field has errored once, re-validating as they fix it is helpful — that is the exception.
  4. Attach the error to the field and announce it. Visible text beside the input, aria-describedby pointing at it, aria-invalid on the control. Colour alone reaches nobody using a screen reader and nobody who cannot distinguish the hue.
  5. Summarise on submit. On a failed submit, move focus to a summary listing each error as a link to its field. Without it a keyboard user tabs the whole form hunting.
  6. Make the pending state real. Disable submit while in flight, say what is happening, and guard the server with an idempotency key — a double-click is not a rare event.
  7. Never lose input. Preserve values through a failed submit, keep a draft for long forms, and warn before discarding unsaved changes.
  8. Help the browser help the user. Correct type, inputmode, and autocomplete tokens. This is minutes of work and removes most of the typing on mobile.
  9. Write messages people can act on. Say what is wrong and what to do: "Password needs at least 8 characters", not "Invalid input". Keep them whole sentences for translation, not fragments concatenated in code.
  10. Compose the form. Bound one-column width, group fields under headings, separate labels/helpers/errors, and wrap actions in an explicit action bar; keep lookup search and pagination inside its group. Present noneditable usage values as summaries.
  11. CRUD drawer forms. In consoles and list views, entity creation and quick edits open a right-side drawer sliding over the list, preserving scroll position, filters, and pagination. Header: entity title and subtitle with an explicit accessible close button. Fields: vertical stack, minimum 16px field gap, labels with a required indicator, whisper-soft borders (#e8ecf1), smooth focus ring, and helper text below each field. A sticky footer holds Cancel and Primary Submit with its pending state. A standalone route form renders as a centered, bounded-width card with the identical fieldset structure.

Red flags

  • Placeholder used instead of a label — it disappears exactly when it is needed
  • Validation on every keystroke, or errors shown before the field is touched
  • Errors rendered only as a red border or red text
  • Client-side rules the server does not enforce
  • A submit button outside the <form>, or a div acting as one — Enter stops working
  • preventDefault with no keyboard path to submit
  • Disabling submit until the form is valid, so nothing explains what is missing
  • Clearing the form on a failed submit
  • Custom select, date or combobox where the native control would do
  • autocomplete="off" on fields where it helps nobody but the developer
  • Messages assembled from fragments, which cannot be translated

Verification

  • Usable with the keyboard alone, Enter submits, focus order matches the layout
  • Every field has a visible, associated <label>
  • Errors carry aria-invalid and aria-describedby, and are announced
  • A failed submit moves focus to a summary linking each error to its field
  • Client and server enforce the same schema; server rejection is handled
  • Double-clicking submit produces one result
  • Values survive a failed submit; long forms keep a draft
  • Mobile shows the right keyboard; autofill fills the right fields
  • Messages say what to do, and are translatable as whole strings

References

  • references/schema-and-state.md — one schema on both sides, field state, submit lifecycle
  • references/errors-and-announcement.md — associating, announcing, and summarising errors
  • references/inputs.md — types, inputmode, autocomplete, files, and multi-step forms

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.