# TanStack Form + Zod

> form.Field wires the combobox; Zod onSubmit validator surfaces FieldError when touched.

A shadcn/ui block from the [@flx](https://ui.flexnative.com) registry, listed on [shadcn.exchange](https://shadcn.exchange/r/flx/command-13).

- Page, with a live preview: https://shadcn.exchange/r/flx/command-13
- Screenshot: https://abzjhwgwpdpz7ua5.public.blob.vercel-storage.com/shots/flx/command-13-light-57391b4b807383ac.png
- Registry item: https://ui.flexnative.com/r/command-13.json
- Listed: 2026-10-13, source last changed 2026-10-13

## Install

```bash
npx shadcn@latest add https://ui.flexnative.com/r/command-13.json
```

Run it in a project that has shadcn/ui set up. It adds the files below and installs what they depend on.

## Dependencies

- npm packages: `@tanstack/react-form`, `sonner`, `zod`
- Registry items: `popover`, `command`, `button`, `field`

## Files

### `registry/patterns/command/command-13.tsx`

```tsx
'use client'

import { useForm } from '@tanstack/react-form'
import { toast } from 'sonner'
import * as z from 'zod'

import { Button } from '@/components/ui/button'
import {
  Command,
  CommandEmpty,
  CommandGroup,
  CommandInput,
  CommandItem,
  CommandList,
} from '@/components/ui/command'
import {
  Field,
  FieldError,
  FieldGroup,
  FieldLabel,
} from '@/components/ui/field'
import {
  Popover,
  PopoverContent,
  PopoverTrigger,
} from '@/components/ui/popover'
import { cn } from '@/lib/utils'
import { ChevronsUpDownIcon } from 'lucide-react'
import { useState } from 'react'

const frameworks = [
  { value: 'next', label: 'Next.js' },
  { value: 'sveltekit', label: 'SvelteKit' },
  { value: 'nuxt', label: 'Nuxt' },
  { value: 'remix', label: 'Remix' },
  { value: 'astro', label: 'Astro' },
] as const

const formSchema = z.object({
  framework: z.string().min(1, 'Select a framework.'),
})

export function Command13() {
  const [open, setOpen] = useState(false)
  const form = useForm({
    defaultValues: {
      framework: '',
    },
    validators: {
      onSubmit: formSchema,
    },
    onSubmit: async ({ value }) => {
      toast.success('Submitted', {
        description: frameworks.find((item) => item.value === value.framework)
          ?.label,
      })
    },
  })

  return (
    <form
      id="command-tanstack-form"
      onSubmit={(event) => {
        event.preventDefault()
        form.handleSubmit()
      }}
      className="flex w-full max-w-sm flex-col gap-4"
    >
      <FieldGroup>
        <form.Field name="framework">
          {(field) => {
            const isInvalid =
              field.state.meta.isTouched && !field.state.meta.isValid

            return (
              <Field data-invalid={isInvalid}>
                <FieldLabel htmlFor={field.name}>Framework</FieldLabel>
                <Popover open={open} onOpenChange={setOpen}>
                  <PopoverTrigger
                    render={
                      <Button
                        id={field.name}
                        type="button"
                        variant="outline"
                        role="combobox"
                        aria-expanded={open}
                        aria-invalid={isInvalid}
                        className="w-full justify-between font-normal"
                      >
                        <span
                          className={cn(
                            !field.state.value && 'text-muted-foreground',
                          )}
                        >
                          {field.state.value
                            ? frameworks.find(
                                (item) => item.value === field.state.value,
                              )?.label
                            : 'Select framework'}
                        </span>
                        <ChevronsUpDownIcon className="text-muted-foreground" />
                      </Button>
                    }
                  />
                  <PopoverContent
                    className="w-(--anchor-width) p-0"
                    align="start"
                  >
                    <Command>
                      <CommandInput placeholder="Search framework..." />
                      <CommandList>
                        <CommandEmpty>No framework found.</CommandEmpty>
                        <CommandGroup>
                          {frameworks.map((item) => (
                            <CommandItem
                              key={item.value}
                              value={item.value}
                              data-checked={field.state.value === item.value}
                              onSelect={(current) => {
                                field.handleChange(
                                  current === field.state.value ? '' : current,
                                )
                                field.handleBlur()
                                setOpen(false)
                              }}
                            >
                              {item.label}
                            </CommandItem>
                          ))}
                        </CommandGroup>
                      </CommandList>
                    </Command>
                  </PopoverContent>
                </Popover>
                {isInvalid && <FieldError errors={field.state.meta.errors} />}
              </Field>
            )
          }}
        </form.Field>
      </FieldGroup>
      <Button type="submit" size="sm">
        Submit
      </Button>
    </form>
  )
}
```
