Form
react-hook-form bindings for the field primitives.
Installation
npx shadcn@latest add @blank/formUsage
import {
Form,
FormControl,
FormDescription,
FormField,
FormItem,
FormLabel,
FormMessage,
} from "@/components/ui/form"<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)}>
<FormField
control={form.control}
name="username"
render={({ field }) => (
<FormItem>
<FormLabel>Username</FormLabel>
<FormControl>
<Input {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</form>
</Form>Form wires React Hook Form into the ids and aria-* attributes a field needs. For new forms, Field with your form library's own hooks does the same with less indirection; Form stays for code that already uses it.
Examples
Switches
Any control works inside FormControl as long as you map its value and change handler onto the field.