shadcn.io is not affiliated with official shadcn/ui
Form examples · Advanced
Form with Multiple Selects for React
A name input and three required selects for country, timezone and language, validated together before the settings save.
Settings forms often pair a text input with several dropdowns, and every one of them has to be filled. This form has a Name Input and three Selects for country, timezone and language, each in a Field with its FieldLabel and FieldError, wired to React Hook Form by a Controller. The three selects come from one static list, so adding a fourth is one more entry. Use it for profile, localization or registration settings.
Preview
Installation
FAQ
What does each field check?
name is .min(2) with "Name must be at least 2 characters." country, timezone and language each start as "" and must pass .min(1), with "Please select a country.", "Please select a timezone." and "Please select a language."
How is each select wired?
The selects are one selects array mapped to a Controller each, with its label, placeholder and options. Select takes items, value={field.value || null}, and onValueChange stores the next value or "".
What values do the three lists use?
Country uses us, uk, ca and au. Timezone uses est, cst, mst and pst. Language uses en, es, fr and de. The form stores that value, not the visible label.
What shows before anything is picked?
All four values start as "", so the triggers show their placeholders: "Select country", "Select timezone" and "Select language". The Name input's placeholder is John Doe.
Related
- Form with SelectA required country select with a
- Form with Mixed ControlsA support request form that mixes a text
- Multiple Selects FieldLanguage and currency selects stacked in
- Vertical Layout (Default) FieldTwo stacked fields, each with its label
- Settings FormAn app settings form with language and
- Form with CheckboxA form with three checkboxes and their