# AIForm

Forms with fields that appear as needed, validation and confirmed submission.

- **Use it for**: Controlled forms with conditional fields, validation and receipts.
- **Not for**: One short question. Try [ClarificationRequest](https://unseenui.com/components/clarification-request/).

## Installation

```bash
npm install @stackunseen/ui
```

## Usage

```tsx
import { AIForm } from '@stackunseen/ui';
import '@stackunseen/ui/styles.css';

<AIForm variant="stacked" fields={fields} values={values} onValueChange={setValues} onSubmit={submitForm} />
```

## All props

| Prop | Type | Description |
| --- | --- | --- |
| `arrayErrors` | `AIArrayErrors` |  |
| `arrays` | `readonly AIFieldArray[]` |  |
| `arrayValues` | `AIArrayValues` |  |
| `className` | `string` | Added to the root element, after the component's own classes. |
| `errors` | `Record<string, string>` |  |
| `fields` (required) | `readonly AIField[]` |  |
| `identity` | `AIFormIdentity` |  |
| `onArrayChange` | `((request: AIArrayChange) => void)` |  |
| `onStepChange` | `((step: string) => void)` |  |
| `onSubmit` (required) | `(values: FormValues, submission?: AIFormSubmission) => void` |  |
| `onValueChange` (required) | `(values: FormValues) => void` |  |
| `receipt` | `string \| AIFormReceipt` |  |
| `status` | `"pending" \| "ready" \| "loading" \| "denied" \| "unavailable" \| "error" \| "stale" \| "complete"` |  |
| `step` | `string` |  |
| `steps` | `readonly AIFormStep[]` |  |
| `title` | `string` |  |
| `values` (required) | `FormValues` |  |
| `variant` | `"compact" \| "stacked" \| "grid"` |  |

## Keyboard

Tab reaches controls; Enter or Space activates buttons. Accordions use arrow keys, Home and End. Select menus support arrows and typeahead; Escape closes menus and dialogs and restores focus.

## Works with

[GeneratedUI](https://unseenui.com/components/generated-ui/), [DataGrid](https://unseenui.com/components/data-grid/), [Chart](https://unseenui.com/components/chart/), [ClarificationRequest](https://unseenui.com/components/clarification-request/)

Page: https://unseenui.com/components/ai-form/
