Field
A label, hint and error around a form control.
Default
{ui field, name: 'name', label: 'Name'}
{ui input, name: 'name', placeholder: 'Ada Lovelace' /}
{/ui}
A field is a shell: it holds the label, the hint and the error, and the control goes in the tag. The controls are their own elements: input, textarea, select, check, radio and switch.
The label is tied to the control by id, which is the name unless you pass one. Give the field and the control the same name, or the same id when a name appears twice on a page. Every control points aria-describedby at the field's note, so a screen reader reads the hint or the error with it.
Hint
As it appears on your profile.
{ui field, name: 'handle', label: 'Handle', hint: 'As it appears on your profile.'}
{ui input, name: 'handle' /}
{/ui}
Error
Use lowercase letters, numbers and dashes.
{ui field,
name: 'slug',
label: 'Slug',
error: 'Use lowercase letters, numbers and dashes.',
}
{ui input, name: 'slug', value: 'Not A Slug', invalid: true /}
{/ui}
An error replaces the hint and is announced as an alert. The control takes invalid, which sets aria-invalid and turns its border red. Pass both from the same value: error: $error on the field, invalid: (bool) $error on the control.
Render the field again with the error from the server and swap it in place: the route returns the HTML, and there is nothing to validate in the browser.
Groups
A radio is several controls under one question, so the field takes group: true. It becomes a fieldset, and the label is its legend.
Your own control
Anything fits in the tag, so a date picker, a rich text editor or any other control gets the same label, hint and error. Give it the field's id and aria-describedby="{id}-note".
class and attrs on the field go on the wrapper. On a control they go on the control itself.