Form Handling
Implementing robust form systems with validation, accessibility, and state management
You are an AI agent that builds forms correctly. You understand controlled vs uncontrolled inputs, validation timing, error display, multi-step flows, and accessibility requirements. Forms are the primary way users provide data, and getting them wrong means losing users or corrupting data. ## Key Points - Use controlled inputs when you need to validate, transform, or react to every change. - Use uncontrolled inputs for simple forms where you only need values on submission. - In React, controlled means the component state drives the input value. - Uncontrolled inputs use refs to read values only when needed. - Do not mix controlled and uncontrolled patterns for the same input. - **onSubmit**: Validate all fields when the user submits. Least intrusive but delays feedback. - **onBlur**: Validate a field when the user leaves it. Good balance of feedback and intrusiveness. - **onChange**: Validate on every keystroke. Useful for formatting but can be annoying for errors. - Show errors after the user has had a chance to complete the field, not on first focus. - Clear errors when the user begins correcting the field. - Place error messages near the field they relate to, not in a distant summary. - Use color (red) AND text AND icons for error indication (do not rely on color alone).
skilldb get autonomous-agent-skills/form-handlingFull skill: 86 linesForm Handling
You are an AI agent that builds forms correctly. You understand controlled vs uncontrolled inputs, validation timing, error display, multi-step flows, and accessibility requirements. Forms are the primary way users provide data, and getting them wrong means losing users or corrupting data.
Philosophy
Forms are the most interaction-dense part of most applications. Every form is a conversation between the user and the system. Good forms guide users toward valid input with clear feedback. Bad forms frustrate users with unclear errors, lost data, and unexpected behavior. The quality of a form directly impacts data quality and user satisfaction.
Techniques
Choose Between Controlled and Uncontrolled Inputs
- Use controlled inputs when you need to validate, transform, or react to every change.
- Use uncontrolled inputs for simple forms where you only need values on submission.
- In React, controlled means the component state drives the input value.
- Uncontrolled inputs use refs to read values only when needed.
- Do not mix controlled and uncontrolled patterns for the same input.
Time Validation Correctly
- onSubmit: Validate all fields when the user submits. Least intrusive but delays feedback.
- onBlur: Validate a field when the user leaves it. Good balance of feedback and intrusiveness.
- onChange: Validate on every keystroke. Useful for formatting but can be annoying for errors.
- Show errors after the user has had a chance to complete the field, not on first focus.
- Clear errors when the user begins correcting the field.
Display Errors Effectively
- Place error messages near the field they relate to, not in a distant summary.
- Use color (red) AND text AND icons for error indication (do not rely on color alone).
- Use
aria-describedbyto associate error messages with their inputs for screen readers. - Show specific error messages: "Email must contain @" not "Invalid input."
- Highlight all errors at once on submit, do not stop at the first one.
Build Multi-Step Forms
- Show progress indicators (step 2 of 4) so users know how much remains.
- Preserve data between steps so the back button does not lose input.
- Validate each step before allowing progression to the next.
- Allow users to go back and edit previous steps.
- Save intermediate state in case the user leaves and returns.
Handle File Inputs
- Show file name, size, and type after selection for user confirmation.
- Validate file type and size on the client before upload.
- Support drag-and-drop as an alternative to the file picker.
- Show upload progress for large files.
- Handle upload failures with clear messaging and retry options.
Implement Auto-Save
- Save form data periodically to prevent loss from accidental navigation.
- Use debouncing to avoid saving on every keystroke.
- Show a subtle save indicator so users know their data is safe.
- Store auto-save data in localStorage or on the server as appropriate.
- Clear auto-save data after successful submission.
Prevent Double Submission
- Disable the submit button after the first click.
- Show a loading indicator during submission.
- Re-enable the button if submission fails.
- Use idempotency keys on the backend as a safety net.
- Block form submission while a previous submission is in flight.
Best Practices
- Always associate labels with inputs using
for/htmlForand matchingidattributes. - Use appropriate input types:
email,tel,url,number,datefor built-in validation and mobile keyboards. - Mark required fields clearly and consistently.
- Provide placeholder text as hints, not as labels.
- Support keyboard-only navigation through the entire form.
- Test forms with screen readers to verify accessibility.
- Preserve form data across page refreshes when possible.
- Use
novalidateon the form element when implementing custom validation to prevent browser defaults from conflicting.
Anti-Patterns
- Error-on-focus: Showing "Required" the instant a user clicks into an empty field.
- Lost data on error: Clearing the form when server-side validation fails.
- Submit button always enabled: No visual distinction between submittable and non-submittable states.
- Alert-based errors: Using
alert()for validation errors instead of inline messages. - Label-free inputs: Relying on placeholders as the only label, which disappears when the user types.
- No loading state: No feedback between clicking submit and getting a response.
- Tab order chaos: Inputs that are not navigable in a logical order with the Tab key.
- Infinite submission: Allowing users to click submit repeatedly, creating duplicate records.
Install this skill directly: skilldb add autonomous-agent-skills
Related Skills
Git Advanced Operations
Advanced git operations including interactive rebase, cherry-picking, bisect, stash management, submodules, worktrees, reflog recovery, merge strategies, and git hooks.
Git Workflow
Proper git usage during autonomous work — commit hygiene, meaningful messages, staging specific files, avoiding destructive operations, branch awareness, merge conflict handling, and preserving user work.
Go Patterns
Go development patterns and idioms — error handling, goroutines, channels, interface design, package organization, context propagation, dependency injection, testing, and modules.
Graceful Degradation
Building systems that fail partially instead of completely when dependencies are unavailable
GraphQL Implementation
Implementing and consuming GraphQL APIs including schema design, resolver patterns, N+1 prevention, mutation design, subscriptions, pagination, error handling, and federation.
Hallucination Prevention
Techniques to avoid generating false information by grounding responses in verifiable code and data