# `LedgerUI.Components.Form`
[🔗](https://github.com/devaction-labs/ledger_ui/blob/v0.2.0/lib/ledger_ui/components/form.ex#L1)

The pieces Ledger UI's forms are made of: a caption (`label/1`), a help line (`help_text/1`),
an error line (`error/1`) and the `field/1` wrapper that puts them around any control.

    <.label for="email">Email</.label>
    <.help_text>We never share it.</.help_text>
    <.error>can't be blank</.error>

    <.field label="Country" help="Where you live" errors={@form[:country].errors}>
      <select>…</select>
    </.field>

`input/1`, `textarea/1`, `otp_input/1`, `phone_input/1` and the groups already render their own
field, so `field/1` is for the controls Ledger UI does not draw (a native `<select>`, a
third-party widget).

# `error`

A validation message in the small red text. It has `role="alert"`.
## Attributes

* `class` (`:any`) - Defaults to `nil`.
* Global attributes are accepted.
## Slots

* `inner_block` (required)

# `field`

Wraps a control with its caption, help line and errors.

With `as="label"` (default) the whole block is a `<label>`, so a click on the caption focuses
the control. When there are errors they replace the help line.

## Attributes

* `field` (`Phoenix.HTML.FormField`) - Takes the errors from a form field. Defaults to `nil`.
* `id` (`:string`) - The id of the control, for the caption's `for`. Defaults to `nil`.
* `label` (`:string`) - Defaults to `nil`.
* `label_class` (`:any`) - Defaults to `nil`.
* `label_hint` (`:string`) - Defaults to `nil`.
* `help` (`:string`) - Defaults to `nil`.
* `errors` (`:list`) - Defaults to `[]`.
* `state` (`:string`) - Defaults to `nil`.Must be one of `nil`, `""`, `"success"`, or `"error"`.
* `as` (`:string`) - Defaults to `"label"`. Must be one of `"label"`, or `"div"`.
* `layout` (`:string`) - Defaults to `"stacked"`. Must be one of `"stacked"`, or `"inline"`.
* `required` (`:boolean`) - Adds the red asterisk to the caption. Defaults to `false`.
* `label_id` (`:string`) - Id of the caption (for `aria-labelledby`). Defaults to `nil`.
* `msg_id` (`:string`) - Id of the first help/error line (`aria-describedby`). Defaults to `nil`.
* `class` (`:any`) - Defaults to `nil`.
* `bare` (`:boolean`) - With nothing to show around the control (no caption, help, errors) render it alone. Defaults to `false`.
* Global attributes are accepted.
## Slots

* `aside` - At the right of the help/error line (a character counter).
* `below` - Between the control and the help line (strength bars).
* `inner_block` (required)
* `label_aside` - At the right of the caption (a "Forgot?" link): the caption and this sit in a `lu-row`.

# `help_text`

The small line under a control. `state="success"` paints it green (with a check-circle icon)
and `state="error"` red.

## Attributes

* `state` (`:string`) - Defaults to `nil`.Must be one of `nil`, `""`, `"success"`, or `"error"`.
* `class` (`:any`) - Defaults to `nil`.
* Global attributes are accepted.
## Slots

* `inner_block` (required)

# `label`

A caption for the control with the id `for`.
## Attributes

* `for` (`:string`) - Defaults to `nil`.
* `class` (`:any`) - Defaults to `nil`.
* Global attributes are accepted.
## Slots

* `inner_block` (required)

---

*Consult [api-reference.md](api-reference.md) for complete listing*
