shadcn.io is not affiliated with official shadcn/ui
Form examples · Patterns
Settings Form for React
An app settings form with language and theme selects, three notification switches and a two-factor authentication switch.
A preferences page in one form: language and theme selects under a Preferences heading, then Notifications and Security sections whose switches sit on bordered rows. Each control is wired to React Hook Form by a Controller, sections are FieldSets with a FieldLegend, and every value starts from defaultValues. Use it for app, account or notification settings.
Preview
Installation
FAQ
What is selected when the form opens?
defaultValues sets the language to en, the theme to system, email notifications and security alerts on, and marketing emails and two-factor authentication off.
How do language and theme write back to the form?
Each is a Controller with a Select and a FieldDescription: "Choose your preferred language." and "Select your preferred theme." Select takes items, value={field.value || null}, and onValueChange stores the next value.
How is each switch connected?
The three notification rows come from one notifications array mapped to a Controller each; Two-Factor Authentication has its own. Switch takes checked and onCheckedChange={field.onChange}.
What does the schema actually reject?
Almost nothing: language and theme are z.string() and the four switches z.boolean(), and every control always holds a valid value, so there are no FieldErrors. Narrow the selects with z.enum if the server needs it.
Related
- Form with SwitchThree notification switches, email, push
- Profile Edit FormA profile form prefilled with a username
- Form with Multiple SelectsA name input and three required selects
- Default SwitchA switch in its default off state, with
- Spacious Form with SectionsA spacious form split into Personal
- Checkout FormA checkout form with a contact email