shadcn/uiFormsError Fix2026 Updated

shadcn/ui Form Validation Not Showing— react-hook-form + zod Fix [2026]

Also covers: FormField · FormMessage · zodResolver · Controller · server-side errors · onBlur validation

January 20267 min readshadcn/ui · react-hook-form · zod

⚡ The Problem

Error
// 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

Correct shadcn Form structure
<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.

1

Correct Form + FormField + FormMessage Structure

Most common fix — wrong nesting
5 min
Complete shadcn Form structure
"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.

2

Connect Zod Schema to react-hook-form

No validation firing at all — missing resolver
5 min
Full zod + react-hook-form + shadcn setup
"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 zod
3

Fix Errors Not Showing on First Submit

Errors appear after second submit only
2 min

By 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.

Validation mode options
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.

4

Show Validation on Custom Inputs with Controller

Select, DatePicker, custom components not validating
4 min

For 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.

shadcn Select + FormField
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>
  )}
/>
Checkbox with FormField
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>
  )}
/>
5

Display Server-Side Validation Errors

API returns errors — show them in the form fields
3 min
Set server errors with form.setError()
"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

Frequently Asked Questions

Why do shadcn/ui form errors not show up?+
The most common cause is a missing or misplaced FormMessage component. shadcn/ui's Form component integrates with react-hook-form — each field needs Form, FormField, FormItem, FormLabel, FormControl, and FormMessage in the correct nesting order. If FormMessage is missing or outside FormField, errors won't display.
What is the relationship between shadcn/ui Form and react-hook-form?+
shadcn/ui's Form component is a thin wrapper around react-hook-form that provides context. FormField uses react-hook-form's Controller internally. FormMessage reads the field error from the form context and displays it. Without the shadcn Form wrapper, the sub-components have no context to read errors from.
Why does validation only fire after the first submit, not on typing?+
By default, react-hook-form validates on submit (mode: 'onSubmit'). To validate while typing or on blur, set mode: 'onChange' or mode: 'onBlur' in useForm(). You can also use reValidateMode: 'onChange' to re-validate after the first submit attempt.
How do I integrate zod with shadcn/ui forms?+
Install @hookform/resolvers and zod. Define a zod schema, then pass zodResolver(schema) to useForm's resolver option. The types flow automatically — useForm infers field types from the zod schema. Use z.infer<typeof schema> to type your form values.
How do I show server-side validation errors in a shadcn/ui form?+
Use form.setError('fieldName', { message: 'Server error message' }) after receiving an error from your API or Server Action. This registers the error in react-hook-form's state, which FormMessage then displays automatically for that field.
Can I use shadcn/ui Form without react-hook-form?+
Technically yes — you can use the UI components individually without the Form wrapper. But you would lose the integration between FormField, FormMessage, and validation state. For uncontrolled forms, you can use HTML form + Server Actions without react-hook-form at all.

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