TanStack Form Registry

Start Building

Installation

pnpm dlx shadcn@canary add https://tancn.dev/r/react/tanstack-form.json

Add the tanstack-form component to your project using the shadcn CLI.

Usage

This tanstack-form registry component provides a comprehensive set of hooks and components for building forms with TanStack Form. It includes form validation, field management, and UI components.

Here's a basic example of how to use it:

Example Usage
import { draftFormSchema } from './schema'
import { useAppForm } from "@/components/ui/tanstack-form"
import { revalidateLogic } from "@tanstack/react-form"
import { toast } from "sonner"
import * as z from "zod"
import { FieldDescription , FieldLegend} from "@/components/ui/field"
import { Input } from "@/components/ui/input"

export function DraftForm() {
  const draftForm = useAppForm({
    defaultValues: {
      email: ""
    } as z.input < typeof draftFormSchema > ,
    validationLogic: revalidateLogic(),
    validators: {
      onDynamic: draftFormSchema,
      onDynamicAsyncDebounceMs: 300
    },
    onSubmit: ({ value }) => {
      toast.success("success");
    },
  });
  return (
  <div>
    <draftForm.AppForm>
      <draftForm.Form>
          <h1 className="text-3xl font-bold">Waitlist</h1>
 <FieldDescription>"Join our waitlist to get early access"</FieldDescription>;
 <draftForm.AppField name={"email"}>
                {(field) => (
                    <field.FieldSet className="w-full">
                      <field.Field>
                        <field.FieldLabel htmlFor={"email"}>Your Email *</field.FieldLabel>
                        <Input
                          name={"email"}
                          placeholder="Enter your Email"
                          type="email"

                          value={(field.state.value as string | undefined) ?? ""}
                          onBlur={field.handleBlur}
                          onChange={(e) => field.handleChange(e.target.value)}
                          aria-invalid={!!field.state.meta.errors.length && field.state.meta.isTouched}
                        />
                      </field.Field>

                      <field.FieldError />
                    </field.FieldSet>
                  )}
              </draftForm.AppField>

          <div className="flex justify-end items-center w-full pt-3">
          <draftForm.SubmitButton label="Submit" />
        </div>
      </draftForm.Form>
    </draftForm.AppForm>
  </div>
  )}

Anatomy

The tanstack-form has Super Cool Form Composition Feature that allow Breaking Large and Complex Form into Composable Field, The Registry Uses Form Composition + ShadCN Field Components to Allow Ultimate Flexibiity

anotomy-of-form
  • AppForm: The main form instance created with useAppForm, providing form state and methods.
  • Form: The root form element that handles submission and provides form context.
  • AppField: A field component that integrates with the form instance for validation and state management.
  • FieldSet: Groups related form fields together.
  • Field: Wraps individual form fields with validation, error handling, and accessibility attributes.
  • FieldLabel: Provides accessible labels for form fields.
  • FieldError: Displays validation errors for the field.
  • FieldDescription: Provides additional descriptive text for form fields.
  • FieldLegend: Provides legends for fieldsets.
  • SubmitButton: A button component that submits the form and shows loading state during submission.
  • InputGroup, InputGroupInput, InputGroupAddon: Components for grouping inputs with addons.

Field Examples

By clicking continue, you agree to our Terms of Service and Privacy Policy.

A basic text input field.

A password input with visibility toggle.

One-time password input.

A multi-line text input.

A group of radio buttons.

A group of toggle buttons.

A toggle switch.

A range slider.

A dropdown select.

A multi-select dropdown.

A date picker component.

Form Examples

Waitlist

Join our waitlist to get early access

Feedback Form

Please provide your feedback

Contact us

Please fill the form below to contact us

Sign Up

You need an account to get started

Customer Support Request

We're here to help! Please describe your issue below.

Place Your Order

Fill out the details below to complete your order

Event Registration

Register for our upcoming event

Job Application

Please fill out the form below to apply for this position

Survey Form

Multi-Step Form Examples

Step 1 of 3
Personal Details

Please provide your personal details

Purchase Order

Create a purchase order with multiple items

Adjust the range by sliding.