FieldFrame
The label, hint and errors around a control of your own.
JavaScript off: what the HTML and CSS do on their own.
The shared frame around every field: label, control, hint, errors. Field components use it; custom fields can too, to match the built-in ones.
Usage
<FieldFrame Id="due" Label="Due date" Hint="A weekday." HintId="due-hint">
<input id="due" type="date" name="due" aria-describedby="due-hint" />
</FieldFrame>A control of your own
Use FieldFrame to give your own control the label, hint, required mark and messages of the built-in fields; the control points at the hint and messages with aria-describedby.
Preview
Code
System.ComponentModel.DataAnnotations
@* NativeValidation="false" skips the browser's check, so the server's message shows. The form takes
an EditContext so the frame can show the field's messages and the input can point at them. *@
<Form EditContext="_edit" FormName="field-frame-custom" OnValidSubmit="Save" NativeValidation="false" MaxWidth="20.Rem" Grow>
<FieldFrame Class="ib-field" Id="due-date" Label="Due date" Required Hint="Reminders go out the day before." HintId="due-date-hint"
Errors="Errors" ErrorId="due-date-error">
<div class="ib-field-control">
<InputDate @bind-Value="Model!.Due" id="due-date" class="ib-field-input" required
aria-invalid="(Errors.Count > 0 ? "true" : null)"
aria-describedby="(Errors.Count > 0 ? "due-date-hint due-date-error" : "due-date-hint")" />
</div>
</FieldFrame>
<Row><Button Submit>Set due date</Button></Row>
if (_saved)
{
<Alert Status="Status.Success">Due (Model!.Due?.ToString("MMMM d")).</Alert>
}
</Form>
{
[SupplyParameterFromForm(FormName = "field-frame-custom")]
private Assignment? Model { get; set; }
private EditContext _edit = null!;
private bool _saved;
private IReadOnlyList<string> Errors => _edit.GetValidationMessages(new FieldIdentifier(Model!, nameof(Assignment.Due))).ToList();
protected override void OnInitialized()
{
Model ??= new();
_edit = new EditContext(Model);
}
private void Save() => _saved = true;
public sealed class Assignment
{
[Required(ErrorMessage = "Pick a due date")]
public DateOnly? Due { get; set; }
}
}Add-ons
Use FieldAddons to attach text or a button to the start or end of your own control.
Preview
https://
.acme.app
Lowercase letters, numbers and dashes.
Code
<Box MaxWidth="26.Rem" Grow>
<FieldFrame Class="ib-field" Id="subdomain" Label="Workspace address" Hint="Lowercase letters, numbers and dashes." HintId="subdomain-hint">
<FieldAddons>
<StartAddon>https://</StartAddon>
<EndAddon>.acme.app</EndAddon>
<ChildContent>
<div class="ib-field-control">
<input id="subdomain" class="ib-field-input" name="subdomain" value="design-team" autocomplete="off" aria-describedby="subdomain-hint" />
</div>
</ChildContent>
</FieldAddons>
</FieldFrame>
</Box>Parts
Written inside FieldFrame. The API page lists their parameters.
FieldAddons: attaches add-ons to the start or end of a field's control: text such as "https://" or "kg", a button, or another field such as a currency Select.FieldError<TValue>: validation messages for one model property, for fields that are not IzzyBlazor fields.
Mode support
| Feature | Off | Static | Live |
|---|---|---|---|
| Everything | Yes | Yes | Yes |
Off: JavaScript disabled. Static: a static SSR page with IzzyBlazor's script. Live: an interactive page (Server, WebAssembly or Auto).
Accessibility
- It renders a
labelwhoseforisId, so the control needs that id; withGroup, afieldsetwhoselegendnames the group. - It renders the hint and errors with
HintIdandErrorId; a custom control links them witharia-describedby(withGroup, thefieldsetcarries it) and setsaria-invaliditself. HideLabelkeeps the label for screen readers;LabelIdlets a control that isn't a native input take its name witharia-labelledby.- The required asterisk is hidden from screen readers, so mark the control
requiredtoo; where it can't be (a group of checkboxes),AnnounceRequiredadds "(required)" for them after the label. - Add-on text from
FieldAddonsisn't part of the control's name. FieldError's messages are linked through itsId: point the control'saria-describedbyat it. An IzzyBlazor field links its own.
Parameters
| Prop | Type | Default |
|---|---|---|
ClassClasses for the wrapper. | string? | |
StyleInline style for the wrapper. | string? | |
IdThe control's id, for the label's for. | string? | |
LabelIdAn id for the label, for controls that point to it with aria-labelledby. | string? | |
LabelThe label text. | string? | |
HideLabelKeeps the label for screen readers but doesn't show it. | bool | false |
RequiredWhether the field is required: an asterisk, or no "(optional)", depending on the form's RequiredMark. | bool | false |
AnnounceRequiredSays "(required)" to screen readers after the label of a required field (Required), for controls that can't be marked required themselves, such as a group of checkboxes. | bool | false |
HintHelp text. | string? | |
HintIdThe hint element's id. | string? | |
ErrorsValidation messages. | IReadOnlyList<string>? | |
ErrorIdThe error element's id. | string? | |
GroupRenders a fieldset with a legend, for groups of controls such as radios. | bool | false |
LabelInControlThe control renders its own label (checkboxes and switches). | bool | false |
ChildContentThe control. | RenderFragment? |