
useForm
A composable for building reactive forms with validation, field registration, and submission handling. Built on top of the registry system for managing form fields.
Usage
The useForm composable provides a powerful interface for managing form state, validation, and submission. It extends the registry pattern to handle form-specific requirements like validation rules, error states, and field lifecycle management.
import { useForm } from '@vuetify/v0'
const form = useForm()
const email = form.register({
id: 'email',
value: '',
rules: [
(value) => value.includes('@') || 'Must be a valid email',
(value) => value.length > 0 || 'Required'
]
})
console.log(email.value) // ''
console.log(email.errors.value) // []API
| Composable | Description |
|---|---|
| useRegistry→ | Base registry system that useForm extends |
| useProxyModel→ | Two-way binding for forms |
useForm
Type
interface FormTicket extends RegistryTicket { validate: (silent?: boolean) => Promise<boolean> reset: () => void validateOn: 'submit' | 'change' | string disabled: boolean errors: ShallowRef<string[]> rules: FormValidationRule[] isPristine: ShallowRef<boolean> isValid: ShallowRef<boolean | null> isValidating: ShallowRef<boolean> } interface FormContext<Z extends FormTicket = FormTicket> extends RegistryContext<Z> { submit: (id?: ID | ID[]) => Promise<boolean> reset: () => void validateOn: 'submit' | 'change' | string isValid: ShallowRef<boolean | null> isValidating: ShallowRef<boolean> } interface FormOptions extends RegistryOptions { validateOn?: 'submit' | 'change' | string } function useForm< Z extends FormTicket = FormTicket, E extends FormContext<Z> = FormContext<Z>, > (options?: FormOptions): EDetails
register(registration: Partial<Z>): Registers a new form field with validation rules and reactive statevalidate(id?: ID | ID[]): Validates specific fieldssubmit(): Validates all inputsreset(): Resets all form fields to their initial valuesvalidateOn: Global validation trigger setting (‘submit’, ‘change’, or combination)isValid: Overall form validity state (true/false/null for unknown)isValidating: Whether any field is currently validatingOptions
validateOn: When to trigger validation. Defaults to'submit'. Can be'change','submit', or space-separated combination.
Form Field Properties
Each registered field returns a FormTicket with:
value: Reactive field value with getter/settererrors: Array of current validation error messagesisValid: Field validity state (true/false/null)isPristine: Whether field value has changed from initialisValidating: Whether field is currently validatingvalidate(silent?): Manually validate fieldreset(): Reset field to initial valuerules: Array of validation functionsdisabled: Whether field is disabled