Documentation Index
Fetch the complete documentation index at: https://mintlify.com/RtlZeroMemory/Rezi/llms.txt
Use this file to discover all available pages before exploring further.
Form Handling & Validation
Building forms with validation, error handling, and submission logic in Rezi applications.Problem
You need to create forms that:- Manage input state and validation
- Display errors only after the user touches fields
- Handle synchronous and asynchronous validation
- Support dynamic field arrays
- Implement multi-step wizard flows
Solution
Rezi provides two approaches:- Manual controlled inputs - Full control, more boilerplate
useFormhook - Declarative, auto-wired, feature-rich
Manual Approach: Controlled Inputs
For simple forms, use controlled inputs with validation in update handlers.- Inputs are controlled:
valuecomes from state,onInputupdates state - Validation runs inside update function (deterministic, no render-time side effects)
touchedis set ononBlurso errors display only after user leaves field- Use
ui.field()wrapper for consistent label + error layout
useForm Hook: Declarative Form Management
For complex forms, use theuseForm hook from @rezi-ui/core/forms.
Basic Example
Field Binding
form.field() creates a complete field with label, input, and error. For custom layouts, use form.bind():
Async Validation
Debounced async validation (e.g., checking username availability):Dynamic Field Arrays
Manage repeating fields (e.g., multiple email addresses):emails.append(item)- Add item to endemails.remove(index)- Remove item at indexemails.move(from, to)- Reorder itemsemails.keys- Stable keys for React-style keyed rendering
Multi-Step Wizard
Build multi-step forms with validation gates:form.nextStep()- Advance if current step validatesform.previousStep()- Go back without validationform.goToStep(index)- Jump to step (validates forward moves)form.currentStep- Current step indexform.isFirstStep/form.isLastStep- Boundary checks
Form-Level Disabled/ReadOnly
Control editability at form or field level:- Disabled: Field is not editable and excluded from validation
- ReadOnly: Field is not editable but still validated
Form State Management
Validation Timing
Manual Validation
Form State
Resetting
Common Patterns
Dependent Field Validation
Conditional Fields
Server-Side Validation
Best Practices
- Use
ui.form()wrapper - Provides consistent spacing and semantics - Use
ui.field()for labeled inputs - Automatic label, hint, error layout - Validate in update handlers - Keep validation deterministic
- Only show errors after touch - Use
touchedto gate error display - Disable submit during submission - Prevent double-submit
- Use
useFormfor complex forms - Reduces boilerplate significantly - Prefer sync validation - Async validation adds latency
- Use field arrays for repeating fields - Stable keys prevent state loss
- Gate wizard steps with validation -
nextStep()only advances if valid
Related
- Input Widget - Text input component
- Field Widget - Form field wrapper
- Checkbox Widget - Boolean input
- Select Widget - Dropdown selection
- Button Widget - Form actions