shadcn/ui Form Validation Not Showing— react-hook-form + zod Fix [2026]
Also covers: FormField · FormMessage · zodResolver · Controller · server-side errors · onBlur validation
⚡ The Problem
// Form submitted — validation fails — but no error messages appear
// OR: errors show in console (form.formState.errors) but not in UI
// OR: FormMessage renders but shows nothing✅ Required nesting order
<Form {...form}>
<FormField control={form.control} name="email" render={({ field }) => (
<FormItem>
<FormLabel>Email</FormLabel>
<FormControl><Input {...field} /></FormControl>
<FormMessage /> {/* ← this must be inside FormField */}
</FormItem>
)} />
</Form>Why shadcn/ui Form Errors Don't Appear
shadcn/ui's Form system has a strict component hierarchy: Form → FormField → FormItem → FormControl + FormMessage . Each component reads from react-hook-form context provided by FormField . If FormMessage is placed outside FormField, or FormField is missing entirely, there is no error context to read and nothing renders.
Correct Form + FormField + FormMessage Structure
Most common fix — wrong nesting"use client"
import { useForm } from "react-hook-form"
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form"
import { Input } from "@/components/ui/input"
import { Button } from "@/components/ui/button"
export function ExampleForm() {
const form = useForm({
defaultValues: { email: "", password: "" },
})
function onSubmit(values) {
console.log(values)
}
return (
<Form {...form}> {/* 1. spread form methods into context */}
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
<FormField
control={form.control} {/* 2. pass control */}
name="email" {/* 3. field name matches defaultValues */}
render={({ field }) => (
<FormItem>
<FormLabel>Email</FormLabel>
<FormControl>
<Input placeholder="you@example.com" {...field} />
</FormControl>
<FormMessage /> {/* 4. MUST be inside FormField */}
</FormItem>
)}
/>
<FormField control={form.control} name="password" render={({ field }) => (
<FormItem>
<FormLabel>Password</FormLabel>
<FormControl><Input type="password" {...field} /></FormControl>
<FormMessage />
</FormItem>
)} />
<Button type="submit">Submit</Button>
</form>
</Form>
)
}FormMessage must be INSIDE the FormField render prop. Placing it outside — even one level up — disconnects it from the field error context and it renders nothing.
Connect Zod Schema to react-hook-form
No validation firing at all — missing resolver"use client"
import { useForm } from "react-hook-form"
import { zodResolver } from "@hookform/resolvers/zod"
import { z } from "zod"
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form"
import { Input } from "@/components/ui/input"
import { Button } from "@/components/ui/button"
// 1. Define zod schema
const formSchema = z.object({
email: z.string().email("Please enter a valid email address"),
password: z.string().min(8, "Password must be at least 8 characters"),
name: z.string().min(2, "Name must be at least 2 characters").max(50),
})
type FormValues = z.infer<typeof formSchema>
export function SignupForm() {
const form = useForm<FormValues>({
resolver: zodResolver(formSchema), // 2. connect zod schema
defaultValues: { email: "", password: "", name: "" },
mode: "onBlur", // 3. validate on blur (optional)
})
async function onSubmit(values: FormValues) {
// values are fully typed and validated at this point
await registerUser(values)
}
return (
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
<FormField control={form.control} name="name" render={({ field }) => (
<FormItem>
<FormLabel>Name</FormLabel>
<FormControl><Input placeholder="Alice" {...field} /></FormControl>
<FormMessage /> {/* shows "Name must be at least 2 characters" */}
</FormItem>
)} />
<FormField control={form.control} name="email" render={({ field }) => (
<FormItem>
<FormLabel>Email</FormLabel>
<FormControl><Input type="email" placeholder="you@example.com" {...field} /></FormControl>
<FormMessage /> {/* shows "Please enter a valid email address" */}
</FormItem>
)} />
<Button type="submit" disabled={form.formState.isSubmitting}>
{form.formState.isSubmitting ? "Creating account..." : "Sign up"}
</Button>
</form>
</Form>
)
}
// Install: npm install @hookform/resolvers zodFix Errors Not Showing on First Submit
Errors appear after second submit onlyBy default react-hook-form only validates on submit. Switch to mode: 'onBlur' or mode: 'onChange' to validate as the user interacts, and use reValidateMode to control re-validation after the first submit.
const form = useForm<FormValues>({
resolver: zodResolver(formSchema),
defaultValues: { email: "" },
// Choose ONE:
mode: "onSubmit", // default — only validates on submit
mode: "onBlur", // validates when field loses focus (recommended)
mode: "onChange", // validates on every keystroke
mode: "all", // validates on blur + change
// After first submit, re-validate on:
reValidateMode: "onChange", // default — re-validates on change after submit
})mode: 'onBlur' is the best UX — it doesn't interrupt typing but shows errors as soon as the user leaves the field. Pair with reValidateMode: 'onChange' so errors clear as the user corrects them.
Show Validation on Custom Inputs with Controller
Select, DatePicker, custom components not validatingFor non-native inputs (shadcn Select, DatePicker, custom components), use FormField which wraps react-hook-form's Controller internally — it handles value, onChange, and error state automatically.
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
<FormField
control={form.control}
name="role"
render={({ field }) => (
<FormItem>
<FormLabel>Role</FormLabel>
<Select onValueChange={field.onChange} defaultValue={field.value}>
<FormControl>
<SelectTrigger><SelectValue placeholder="Select a role" /></SelectTrigger>
</FormControl>
<SelectContent>
<SelectItem value="admin">Admin</SelectItem>
<SelectItem value="user">User</SelectItem>
<SelectItem value="viewer">Viewer</SelectItem>
</SelectContent>
</Select>
<FormMessage />
</FormItem>
)}
/>import { Checkbox } from "@/components/ui/checkbox"
<FormField
control={form.control}
name="acceptTerms"
render={({ field }) => (
<FormItem className="flex items-start space-x-2">
<FormControl>
<Checkbox
checked={field.value}
onCheckedChange={field.onChange}
/>
</FormControl>
<div>
<FormLabel>I accept the terms and conditions</FormLabel>
<FormMessage />
</div>
</FormItem>
)}
/>Display Server-Side Validation Errors
API returns errors — show them in the form fields"use client"
async function onSubmit(values: FormValues) {
try {
const result = await registerUser(values)
if (!result.success) {
// Set field-level errors from server response
if (result.errors?.email) {
form.setError("email", {
type: "server",
message: result.errors.email, // "Email already in use"
})
}
if (result.errors?.password) {
form.setError("password", {
type: "server",
message: result.errors.password,
})
}
// Set a root-level error (general form error)
if (result.errors?.general) {
form.setError("root", {
message: result.errors.general,
})
}
return
}
// Success — redirect or close dialog
router.push("/dashboard")
} catch (err) {
form.setError("root", { message: "Something went wrong. Please try again." })
}
}
// Display root error in JSX:
{form.formState.errors.root && (
<p className="text-sm font-medium text-destructive">
{form.formState.errors.root.message}
</p>
)}Prevention
- Always nest FormMessage inside FormField — never outside the render prop
- Always spread {...form} onto the Form component — this provides react-hook-form context
- Use zodResolver from @hookform/resolvers/zod — plain useForm without a resolver has no validation rules
- Set mode: 'onBlur' for best UX — validates on field blur, not on every keystroke
- Use form.setError('fieldName', { message }) to show server-side errors in the correct field
- For custom inputs (Select, Checkbox), always use FormField's render prop — it handles onChange/value wiring
Frequently Asked Questions
Why do shadcn/ui form errors not show up?+−
What is the relationship between shadcn/ui Form and react-hook-form?+−
Why does validation only fire after the first submit, not on typing?+−
How do I integrate zod with shadcn/ui forms?+−
How do I show server-side validation errors in a shadcn/ui form?+−
Can I use shadcn/ui Form without react-hook-form?+−
Need Expert Help?
We Build Forms with shadcn/ui + zod
Softplix engineers implement fully validated forms with shadcn/ui, react-hook-form, zod, and Server Actions. Let us help.
Talk to an Engineer