Forms and inputs · core
Forms with validation (and schema-driven forms)
Keep one values object with errors and touched flags, validate with pure rule functions on blur and on submit, show errors only after a field is touched, and wire every error to its input for screen readers. Be ready to render the whole form from a JSON schema.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- State: values, errors, touched, status ('idle' | 'submitting' | 'success' | 'error'); derive isValid.
- Validate with pure functions or a schema (required, minLength, pattern, custom, cross-field like confirm password); validate on blur and on submit; re-validate a touched field on change.
- Show an error only after touch or submit; on submit, focus the first invalid field (and optionally show an error summary).
- Accessibility: <label htmlFor>, aria-invalid='true', aria-describedby pointing to the error text id, native types (email, tel), autocomplete attributes, never colour alone.
- Submitting: disable the button and prevent double submit while the request runs; map server errors to fields; keep values on failure. React 19 Actions with useActionState are an option.
- Schema-driven (Swiggy 'component kit described by JSON', 'dynamic form from config'): an array of field configs { name, type, label, rules, options, showIf } rendered by a field registry; validation comes from the same config.
- Async validation (username taken): debounce and cancel stale checks.
- Multi-step forms: validate per step, keep values when going back, a review step.
The red pen
Common traps: mistake → fix
Mistake: Show errors while the user is still typing the first character
Fix: noisy; wait for blur.
Mistake: Only disable Submit until valid
Fix: users don't know why; allow submit and show errors (or explain).
Mistake: An email regex that rejects real addresses
Fix: keep it simple and let the server confirm.
Mistake: Lose values when going back a step
Fix: keep one values object for the whole wizard.
Easy to hard
Questions interviewers ask, easy to hard
- Build a signup form with validation.
- When do you show errors? Why?
- How does a screen-reader user find the error?
- Render the same form from a JSON config.
- Add 'username available?' checking as the user types.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.