form-validation-error-handling
Skill2 starsChanged 4 months agoMITView on GitHub
Build forms with robust client+server validation, accessible error messaging, and consistent error handling across the stack. Use whenever the user builds any form (signup, checkout, settings, multi-step), asks about form validation, React Hook Form, Zod schemas, or error/loading state UX.
In this repository22 other files it gives its agents.
- accessibility-a11ySkill
- design-system-tailwindSkill
- motion-design-toolkitSkill
- nextjs-architectureSkill
- react-component-engineeringSkill
- react-three-fiber-3dSkill
- responsive-mobile-firstSkill
- auth-authorizationSkill
- database-schema-designSkill
- mern-stack-architectureSkill
- rest-api-integrationSkill
- state-managementSkill
- landing-page-conversionSkill
- payment-gateway-integrationSkill
- saas-dashboard-adminSkill
- startup-mvp-developmentSkill
- ux-research-flow-designSkill
- visual-design-languageSkill
- ai-assisted-frontend-workflowSkill
- deployment-vercel-productionSkill
- performance-seo-optimizationSkill
- project-architecture-clean-codeSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 32
Use useActionState (React 19/Next.js) to wire the action's returned error state back into the form UI, including pending state for the …
- Distinctive: line 38
Never clear the user's valid input on a failed submission — only surface what's wrong.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Form Validation & Error Handling Skill
Stack: React Hook Form + Zod
const schema = z.object({
email: z.string().email('Enter a valid email'),
password: z.string().min(8, 'At least 8 characters'),
});
type FormValues = z.infer<typeof schema>;
const form = useForm<FormValues>({ resolver: zodResolver(schema), mode: 'onBlur' });- Define the schema once, use it for both client-side validation and server-side validation (Server Action re-parses the same schema) — never trust client validation alone; the server is the source of truth.
mode: 'onBlur'(validate on blur, not on every keystroke) for a less naggy UX; re-validate on change only after the first error on that field.
Server Action validation pattern
'use server';
export async function createAccount(prevState: unknown, formData: FormData) {
const parsed = schema.safeParse(Object.fromEntries(formData));
if (!parsed.success) {
return { errors: parsed.error.flatten().fieldErrors };
}
// proceed with parsed.data
}Use useActionState (React 19/Next.js) to wire the action's returned error state back into the form UI, including pending state for the submit button.
Accessible error UX
- Associate every error with its input via
aria-describedby; announce withrole="alert"on the error text so screen readers pick it up. - Focus the first invalid field on submit failure.
- Show errors near the field they belong to, not only in a summary banner at the top (do both for long forms).
- Never clear the user's valid input on a failed submission — only surface what's wrong.
Error handling layers
- Field-level: inline validation message (Zod schema message).
- Form-level: a submission-wide error (e.g. "email already registered") shown in a banner, not attached to a specific field unless it maps to one.
- Network/unexpected errors: a generic, non-technical message ("Something went wrong, please try again") — never surface raw error objects/stack traces to the user; log the real error server-side.
Multi-step forms
- Validate each step's schema independently (
schema.pick({...})) before allowing "Next," but re-validate the full combined schema on final submit. - Persist in-progress state (URL step param or local state) so back/forward doesn't lose data.
Anti-patterns to flag
- Client-only validation with no matching server-side re-validation
- Generic "Invalid input" errors instead of field-specific, actionable messages
- Disabling the submit button silently with no visible reason why
- Losing all form input on a failed submit (forcing the user to retype everything)
- Raw error/exception text shown directly in the UI
Example prompt this skill should trigger on
"Build a signup form with email/password validation and proper error states."
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
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.

