Default
react-hook-form with a zod schema. Press Save with the fields empty: the labels and boxes turn red pencil and each message is written under its field with a wavy underline. Fix one and its message goes on the next change.
react-hook-form wired to the drawn controls, exactly like shadcn's Form. FormControl gives the control its id, aria-describedby and aria-invalid, so an Input, Select, Checkbox or Switch turns red pencil when the field has an error, its label follows, and FormMessage writes the message under it with a wavy red underline.
npx shadcn@latest add @wobko/form第一次使用?先把 registry 加进 components.json。 如何安装
react-hook-form with a zod schema. Press Save with the fields empty: the labels and boxes turn red pencil and each message is written under its field with a wavy underline. Fix one and its message goes on the next change.
FormControl hands its id, aria-describedby and aria-invalid to whatever it wraps, so a Select, a Radio Group, a Checkbox, a Switch and a Slider go red the same way an Input does. A slider is not a labelable element: its FormLabel gets an id and the Slider points at it with aria-labelledby.
An error does not have to come from the schema: after a pretend request `setError` puts "already taken" on the field, and the same label, box and underline appear. Change the text and it clears itself.
shadcn's `form-rhf-demo`, the Field way to wire a form: `Controller` hands `field` and `fieldState` to a render prop, `data-invalid` on the Field and `aria-invalid` on the control turn it red, and `FieldError` prints the zod message. Submit it empty, then fill it in.
shadcn's `form-rhf-input`: one text field with a zod length and pattern rule. The error is announced as an alert and written under the field in red pencil.
shadcn's `form-rhf-select`: a Radix Select is not a native input, so `name`, `value` and `onValueChange` are passed by hand and `aria-invalid` goes on the trigger. "Auto" is a value the schema refuses.
shadcn's `form-rhf-checkbox`: a single boolean box (here disabled and ticked) and a group that collects an array. Untick both notification types and submit to see the group's own error.
shadcn's `form-rhf-switch`: a boolean switch that the schema insists on. Submit with it off and the switch turns red pencil with its message in the text column.
shadcn's `form-rhf-textarea`: a ruled textarea with a length rule on both ends. Too short and too long each get their own sentence.
shadcn's `form-rhf-radiogroup`: choice cards (a FieldLabel around each Field) in a controlled RadioGroup. `aria-invalid` on the group and on each item paints the whole set red when nothing is chosen.
shadcn's `form-rhf-array`: `useFieldArray` for a list of emails, each an InputGroup with a remove button inside its box. Add up to five; the array's own min and max errors are printed under the list.
shadcn's `form-rhf-complex`: a radio card set, a select, a checkbox group and a switch in one form, four kinds of state and four `Controller`s. The schema wants a billing period and at least one add-on.
shadcn's `form-rhf-password`: `useWatch` feeds a strength meter and a live checklist while the schema guards the submit. The bar is a marker pass that changes ink as the password improves; a met rule is a pencilled tick, an open one a cross, and each says so in words for a screen reader.
The field's error (or your own children), drawn with a wavy red pencil underline. Renders nothing when there is nothing to say.
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| seed | string | number | - | Pins the hand of the underline. Default: from useId(). |
CLI 会复制进你项目的文件。
正在加载源码