published fresh until

How do I build a form with TanStack Form and shadcn/ui validation?

Summary As of October 2026, shadcn/ui's TanStack Form guide uses useForm with a Zod schema, a form.Field render prop and the same Field and FieldError pieces, and lets you choose onSubmit, onChange or onBlur validators. An alternative to React Hook Form when you want per-field validators.

Not for React Hook Form validation wiring; see shadcn-field-react-hook-form-zod-form

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

The problem

You prefer TanStack Form to React Hook Form (typed field state, validators per event) and want an agent to wire it to shadcn components without mixing the two libraries' patterns.

What the sources say

shadcn/ui's TanStack Form guide (shadcn-ui/ui, MIT) states its approach: useForm for state, form.Field with a render prop for controlled inputs, Field components for accessible markup, Zod for validation and real-time feedback. The flow is the same three steps: create a schema, call useForm with validators: { onSubmit: schema } and an onSubmit handler that receives the validated value, then build the fields. You can add onChange and onBlur validators next to onSubmit to change when errors appear. The guide's text calls validation real-time, but its basic examples set only validators: { onSubmit } and gate display on isTouched && !isValid, so real-time feedback needs the onChange validator you add yourself. For errors, set data-invalid on Field, aria-invalid on the input, and render FieldError with field.state.meta.errors.

TanStack Form itself (TanStack/form, MIT) has an AGENTS.md aimed at contributors, not at app builders, so it does not teach agents the API.

How to describe it to the agent

Use TanStack Form (not React Hook Form) with shadcn's Field components, following shadcn's TanStack Form guide. Zod schema for the whole form in validators.onSubmit; add onBlur so errors show after leaving a field. Each input uses form.Field with a render prop: isInvalid from the field meta, onBlur={field.handleBlur}, onChange calling field.handleChange, aria-invalid, and a FieldError for field.state.meta.errors. Do not import react-hook-form.

Mistakes to check

  • Mixed libraries: Controller from React Hook Form inside a TanStack form.
  • Handlers that bypass field.handleChange, so state and display drift apart.
  • Errors shown while the field is untouched; check isTouched or only validate on blur.

Limits

Not run by me. If your project already uses React Hook Form, stay with it; the guides are parallel, not better or worse.

Primary source

Primary source: shadcn/ui TanStack Form guide (shadcn). Checked: useForm, form.Field render prop, Field components, Zod, the three steps, validators.onSubmit, optional onChange and onBlur validators, data-invalid, aria-invalid and FieldError with field.state.meta.errors. TanStack Form’s AGENTS.md was also checked on 2026-11-15 and directs contributors to CONTRIBUTING.md.

Started from a post by @shadcn/ui maintainers, packaged by the editor. Original post

Subjects

More in prompting

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# How do I build a form with TanStack Form and shadcn/ui validation?
Summary: As of October 2026, shadcn/ui's TanStack Form guide uses useForm with a Zod schema, a form.Field render prop and the same Field and FieldError pieces, and lets you choose onSubmit, onChange or onBlur validators. An alternative to React Hook Form when you want per-field validators.
Copy for agent
get the whatworks thread tanstack-form-shadcn-field-validation and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread tanstack-form-shadcn-field-validation
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks