# Form

> Native form wrapper built on Base UI Form with integrated client and server-side error mapping to Field controls.

Canonical URL: https://taut-ui.com/docs/components/form

```tsx
"use client";

import { Button } from "@/components/ui/button";
import {
  Field,
  FieldDescription,
  FieldError,
  FieldLabel,
} from "@/components/ui/field";
import { Form } from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { Textarea } from "@/components/ui/textarea";
import { toastManager } from "@/components/ui/toast";

export default function Particle() {
  return (
    <Form
      onSubmit={(event) => {
        event.preventDefault();
        const data = new FormData(event.currentTarget);
        const name = String(data.get("name") ?? "");
        toastManager.add({
          description: `Project "${name}" has been created.`,
          title: "Project created",
          type: "success",
        });
      }}
    >
      <Field name="name">
        <FieldLabel>Project name</FieldLabel>
        <Input placeholder="taut-ui" required />
        <FieldError match="valueMissing">Project name is required.</FieldError>
      </Field>
      <Field name="notes">
        <FieldLabel>Description</FieldLabel>
        <Textarea placeholder="Short summary of the project..." size="sm" />
        <FieldDescription>
          Optional internal notes for your team.
        </FieldDescription>
      </Field>
      <Button className="self-end" type="submit">
        Create project
      </Button>
    </Form>
  );
}
```

## Installation [#installation]

**CLI**

```bash
npx shadcn@latest add https://taut-ui.com/r/form.json
```

**Manual**

- Install the following dependencies:

```bash
npm install @base-ui/react
```

- Copy and paste the following code into your project.

```tsx title="components/ui/form.tsx"
"use client";

import { Form as FormPrimitive } from "@base-ui/react/form";
import type React from "react";
import { cn } from "@/lib/utils";

export function Form({
  className,
  ...props
}: FormPrimitive.Props): React.ReactElement {
  return (
    <FormPrimitive
      className={cn("flex w-full flex-col gap-4", className)}
      data-slot="form"
      {...props}
    />
  );
}

export { FormPrimitive };
```

- Update the import paths to match your project setup.

## Usage [#usage]

```tsx
import { Button } from "@/components/ui/button"
import { Field, FieldError, FieldLabel } from "@/components/ui/field"
import { Form } from "@/components/ui/form"
import { Input } from "@/components/ui/input"
```

```tsx
<Form onSubmit={(e) => e.preventDefault()}>
  <Field name="email">
    <FieldLabel>Email</FieldLabel>
    <Input required type="email" />
    <FieldError />
  </Field>
  <Button type="submit">Submit</Button>
</Form>
```

## Examples [#examples]

### Controlled Errors [#controlled-errors]

```tsx
"use client";

import { useState } from "react";
import { Button } from "@/components/ui/button";
import { Field, FieldError, FieldLabel } from "@/components/ui/field";
import { Form } from "@/components/ui/form";
import { Input } from "@/components/ui/input";

export default function Particle() {
  const [errors, setErrors] = useState<Record<string, string>>({
    domain: "This custom domain is already linked to another project.",
  });

  return (
    <Form
      errors={errors}
      onFormSubmit={(formValues) => {
        const domain = String(formValues.domain ?? "").trim();
        if (!domain.includes(".")) {
          setErrors({
            domain: "Enter a valid hostname (e.g. docs.taut.app).",
          });
          return;
        }
        setErrors({});
      }}
    >
      <Field name="domain">
        <FieldLabel>Custom domain</FieldLabel>
        <Input defaultValue="app.taut.dev" placeholder="docs.taut.app" />
        <FieldError />
      </Field>
      <Button className="w-full" type="submit">
        Verify domain
      </Button>
    </Form>
  );
}
```

## API Reference [#api-reference]

### Form [#form]

Wraps Base UI `Form` (`<form>`).

| Prop             | Type                                                         | Default      | Description                                        |
| ---------------- | ------------------------------------------------------------ | ------------ | -------------------------------------------------- |
| `errors`         | `Record<string, string \| string[]>`                         | -            | External/server validation errors keyed by `name`  |
| `validationMode` | `"onSubmit" \| "onBlur" \| "onChange"`                       | `"onSubmit"` | Controls when field validation triggers            |
| `onFormSubmit`   | `(formValues: Record<string, unknown>, details) => void`     | -            | Called on valid submission (`preventDefault` built-in) |
| `actionsRef`     | `React.RefObject<Form.Actions \| null>`                      | -            | Imperative handle exposing `validate(fieldName?)`  |
| `className`      | `string`                                                     | -            | Additional CSS classes                             |
