form() creates a type-safe form instance bound to a generated SDK mutation method. It provides reactive field state, schema validation, progressive enhancement attributes (action, method), and per-field error tracking.
The SDK method carries the validation schema in its metadata, so form() picks it up automatically — the Result type is handled internally. When the mutation returns { ok: false }, field errors are extracted and mapped to the form fields.
form()
Signature
FormInstance
The returned instance has two kinds of properties: reserved form properties and per-field accessors.Form properties
| Property | Type | Description |
|---|---|---|
action | string | URL for the form’s action attribute (progressive enhancement) |
method | string | HTTP method for the form’s method attribute |
onSubmit | (e: Event) => Promise<void> | Submit handler — validates, then calls the SDK method |
submitting | boolean | true while the submission is in flight |
dirty | boolean | true if any field has been modified |
valid | boolean | true if all fields pass validation |
reset() | () => void | Reset all fields to initial values |
submit() | (formData?: FormData) => Promise<void> | Programmatic submit |
setFieldError() | (field: string, message: string) => void | Set a custom error on a field |
Per-field accessors
Access any field by name on the form instance (e.g.,taskForm.title). Each field is a FieldState:
| Property | Type | Description |
|---|---|---|
value | T | Current field value |
error | string | undefined | Validation error message |
dirty | boolean | true if the field has been modified |
touched | boolean | true if the field has been focused and blurred |
setValue() | (value: T) => void | Update value and mark dirty |
reset() | () => void | Reset to initial value, clear error/dirty/touched |
FormOptions
| Option | Type | Default | Description |
|---|---|---|---|
schema | FormSchema<TBody> | — | Validation schema (auto-inferred from SDK metadata when available) |
initial | Partial<TBody> | () => Partial<TBody> | — | Initial field values |
onSuccess | (result: TResult) => void | — | Callback after successful submission |
onError | (errors: Record<string, string>) => void | — | Callback on validation or submission error |
resetOnSuccess | boolean | false | Reset fields after successful submission |
revalidateOn | 'blur' | 'change' | 'submit' | 'blur' | When to re-validate fields with errors after first submission |
Progressive enhancement
Theaction and method properties enable the form to work without JavaScript. When JS is available, onSubmit intercepts the submission and handles it client-side with validation.