# Field
> Label, control, description and validation message as one unit.
Source: https://shellui.dev/docs/v0.4/components/form/field
`Field` is **new in v0.4.0**. It wraps one form control with its label, help text and validation message, stacked or side by side, so a form doesn't need the separate [Form](https://shellui.dev/docs/v0.4/components/form/form.md) field parts for the common case.
## Installation
```bash
shellui add field
```
This also installs `form-message`, which shows the messages.
## Usage
### With validation
Inside an `EditForm`, point `For` at the model property and `Field` shows that property's validation messages. `LabelFor` takes the control's `id`, so clicking the label focuses it, and `Required` adds a red asterisk.
```razor
@using System.ComponentModel.DataAnnotations
@if (saved)
{
Saved @model.Email.
}
@code {
private readonly Account model = new();
private bool saved;
private sealed class Account
{
[Required(ErrorMessage = "Enter your email.")]
[EmailAddress(ErrorMessage = "That doesn't look like an email address.")]
public string Email { get; set; } = "";
[Required(ErrorMessage = "Enter a display name.")]
[MinLength(3, ErrorMessage = "Use at least 3 characters.")]
public string Name { get; set; } = "";
}
}
```
Messages appear when the form is submitted. With Blazor's own inputs (`InputText` and the rest), which tell the `EditForm` about each change, they also update as the user types; ShellUI's `Input` doesn't, so its messages change on the next submit.
### Horizontal
`Orientation="horizontal"` puts the label and description beside the control, for switches and checkboxes.
```razor
@code {
private bool digest = true;
private bool updates;
}
```
### Your own error
`Error` shows a message of your own instead of the `EditForm`'s, for checks done outside data annotations.
```razor
@code {
private string username = "admin";
private string? error => username.Trim().ToLowerInvariant() is "admin" or "root" ? "That username is taken." : null;
}
```
## API Reference
| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `Label` | `string?` | `null` | The label text |
| `LabelFor` | `string?` | `null` | The `id` of the control inside, rendered as the label's `for` |
| `Description` | `string?` | `null` | Help text below the control (beside it when horizontal) |
| `Error` | `string?` | `null` | A message shown instead of the `EditForm`'s validation messages |
| `For` | `Expression>?` | `null` | The model property whose validation messages to show, such as `() => model.Email` |
| `Required` | `bool` | `false` | Adds an asterisk after the label (hidden from screen readers) |
| `Orientation` | `string` | `"vertical"` | `vertical`, or `horizontal` for the label beside the control |
| `ChildContent` | `RenderFragment?` | `null` | The control |
| `Class` | `string?` | `null` | Additional CSS classes |
## Accessibility
- The wrapper has `role="group"`
- Set `LabelFor` and give the control the same `id` so the label names it
- `Required` only marks the label. Mark the control itself too (a `required` attribute or a `[Required]` rule) so it is enforced