# Form

- **Section:** Components
- **URL:** https://refast.fastapicloud.dev/docs/components/form
- **Markdown:** https://refast.fastapicloud.dev/docs/components/form.md
- **Source:** https://github.com/idling-mind/refast-docs/blob/main/docs/pages/components/form_inputs/form.py
- **Live examples:** the widgets on this page need a browser; open the URL above to try them.
- **Applies to:** refast 0.12.2

Form wrapper components that intercept the browser submit event and route all data over
the WebSocket to a server callback. Also includes `FormField` for labelled field wrappers
and `Label` for standalone label elements.

```python
from refast.components.shadcn.form import Form, FormField, Label
from refast.components import Input, Button

async def handle_submit(ctx: Context, form_data: dict):
    name = form_data.get("name", "")
    email = form_data.get("email", "")
    # validate and process…
    await ctx.refresh()

Form(
    on_submit=ctx.callback(handle_submit),
    children=[
        FormField(
            label="Name",
            required=True,
            children=[Input(name="name", placeholder="Your name")],
        ),
        FormField(
            label="Email",
            hint="We'll never share your email.",
            required=True,
            children=[Input(name="email", type="email")],
        ),
        Button("Submit", type="submit"),
    ],
)
```

```python
from refast.components.shadcn.form import Form, FormField
from refast.components import Input, Button

async def handle_submit(ctx: Context, form_data: dict):
    name = form_data.get("frm_name", "").strip()
    email = form_data.get("frm_email", "").strip()
    # process submission…
    await ctx.refresh()

Form(
    on_submit=ctx.callback(handle_submit),
    children=[
        FormField(
            label="Full Name",
            required=True,
            hint="First and last name.",
            children=[Input(name="frm_name", placeholder="Jane Smith")],
        ),
        FormField(
            label="Email Address",
            required=True,
            hint="We'll never share your email.",
            children=[Input(name="frm_email", type="email", placeholder="jane@example.com")],
        ),
        Button("Submit", type="submit", class_name="mt-2"),
    ],
)
```

## Form Props

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `children` | `list` | `[]` | Form content — typically `FormField` components and a submit `Button` |
| `on_submit` | `Callback \| None` | `None` | Called with `form_data: dict` when the form is submitted. Keys are `Input` `name` values |
| `id` | `str \| None` | auto | Component ID |
| `class_name` | `str` | `""` | Extra Tailwind classes |

> **Note:** `method` and `enctype` are not configurable — all data is sent over the WebSocket.

## FormField Props

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `children` | `list` | `[]` | The input component(s) to wrap |
| `label` | `str \| None` | `None` | Field label text |
| `hint` | `str \| None` | `None` | Hint text displayed below the label |
| `error` | `str \| None` | `None` | Validation error displayed below the field |
| `required` | `bool` | `False` | Shows required asterisk |
| `id` | `str \| None` | auto | Component ID |
| `class_name` | `str` | `""` | Extra Tailwind classes |

## Label Props

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `text` | `str` | required | Label text content |
| `html_for` | `str \| None` | `None` | Associates label with a control's `id` (rendered as `htmlFor`) |
| `required` | `bool` | `False` | Shows required asterisk |
| `id` | `str \| None` | auto | Component ID |
| `class_name` | `str` | `""` | Extra Tailwind classes |

## InputWrapper Props

`InputWrapper` is a lower-level primitive for wrapping custom controls with label,
description, required indicator, and error message — without the `Form` context.

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `children` | `list` | `[]` | The wrapped control(s) |
| `label` | `str \| None` | `None` | Label text |
| `description` | `str \| None` | `None` | Help text below the label |
| `required` | `bool` | `False` | Shows required asterisk |
| `error` | `str \| None` | `None` | Error message |
| `id` | `str \| None` | auto | Component ID |
| `class_name` | `str` | `""` | Extra Tailwind classes |

---

Part of the Refast documentation: [all pages](https://refast.fastapicloud.dev/llms.txt), [everything on one page](https://refast.fastapicloud.dev/llms-full.txt), [search](https://refast.fastapicloud.dev/api/search?q=save_prop).
