Stop Rebuilding UI

Shadcn.io is not affiliated with official shadcn/ui

Form with Optional Fields

A React form mixing required and optional fields using Zod optional validation with Optional suffix labels built with shadcn/ui and React Hook Form

Not every form field deserves to be required. This React form uses Zod .optional() and .or with z.literal for company and website fields while requiring firstName, lastName, and email. Built with shadcn/ui Form components with React Hook Form and Optional label suffixes for clarity and grid layout for names, it's perfect for flexible registration, profile updates, or contact forms where some information is nice-to-have not mandatory.

Form with Optional Fields preview

Scroll to load preview

Installation

FAQ

Was this page helpful?

Sign in to leave feedback.