

<Demo name="form/demos/basic" />

## Installation [#installation]

<CodeBlockTabs defaultValue="npm">
  <CodeBlockTabsList>
    <CodeBlockTabsTrigger value="npm">
      npm
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="pnpm">
      pnpm
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="yarn">
      yarn
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="bun">
      bun
    </CodeBlockTabsTrigger>
  </CodeBlockTabsList>

  <CodeBlockTab value="npm">
    ```bash
    npx shadcn@latest add @dotui/form
    ```
  </CodeBlockTab>

  <CodeBlockTab value="pnpm">
    ```bash
    pnpm dlx shadcn@latest add @dotui/form
    ```
  </CodeBlockTab>

  <CodeBlockTab value="yarn">
    ```bash
    yarn dlx shadcn@latest add @dotui/form
    ```
  </CodeBlockTab>

  <CodeBlockTab value="bun">
    ```bash
    bun x shadcn@latest add @dotui/form
    ```
  </CodeBlockTab>
</CodeBlockTabs>

## Usage [#usage]

Use forms to wrap groups of form elements and handle form submission with validation.

```tsx
import { Form } from '@/components/ui/form'
import { Button } from '@/components/ui/button'
import { TextField } from '@/components/ui/text-field'
import { Label } from '@/components/ui/field'
import { Input } from '@/components/ui/input'
```

```tsx
<Form onSubmit={handleSubmit}>
  <TextField name="email" isRequired>
    <Label>Email</Label>
    <Input />
  </TextField>
  <Button type="submit" variant="primary">
    Submit
  </Button>
</Form>
```

## Examples [#examples]

<Examples>
  <Example name="form/demos/basic" />

  <Example name="form/demos/react-aria" />
</Examples>

## API Reference [#api-reference]

| Prop                 | Type                                                      | Default    | Description                                         |
| -------------------- | --------------------------------------------------------- | ---------- | --------------------------------------------------- |
| `validationBehavior` | `'native' \| 'aria'`                                      | `'native'` | Whether to use native HTML form validation or ARIA. |
| `validationErrors`   | `ValidationErrors`                                        | -          | Validation errors to display on form fields.        |
| `action`             | `string \| FormHTMLAttributes<HTMLFormElement>['action']` | -          | The URL to submit the form to.                      |
| `encType`            | `string`                                                  | -          | The encoding type to use for form submission.       |
| `method`             | `string`                                                  | -          | The HTTP method to use for form submission.         |
| `target`             | `string`                                                  | -          | The target window for form submission.              |
| `autoComplete`       | `string`                                                  | -          | Whether the browser should autocomplete the form.   |
| `autoCapitalize`     | `string`                                                  | -          | Whether text should be auto-capitalized.            |
| `children`           | `ReactNode`                                               | -          | The form content.                                   |

| Event       | Type                                      | Description                                        |
| ----------- | ----------------------------------------- | -------------------------------------------------- |
| `onSubmit`  | `(e: FormEvent<HTMLFormElement>) => void` | Handler that is called when the form is submitted. |
| `onReset`   | `(e: FormEvent<HTMLFormElement>) => void` | Handler that is called when the form is reset.     |
| `onInvalid` | `(e: FormEvent<HTMLFormElement>) => void` | Handler that is called when validation fails.      |
