Form
Collect information from your users with native constraint validation, reported through ARIA (aria-describedby, aria-invalid).
<NaviusForm OnSubmit="HandleSubmit">
<NaviusField Name="email">
<NaviusFieldLabel>Email</NaviusFieldLabel>
<NaviusFieldError Match="valueMissing">Please enter your email</NaviusFieldError>
<NaviusFieldError Match="typeMismatch">Enter a valid email address</NaviusFieldError>
<NaviusFieldControl type="email" required placeholder="you@@example.com" />
</NaviusField>
<NaviusFormSubmit>Create account</NaviusFormSubmit>
</NaviusForm>
@code {
private void HandleSubmit() { /* fires only when every field is valid */ }
}Features
- Renders a native
<form>; Enter-to-submit and tab order come for free. - Surfaces the browser's built-in
ValidityState(valueMissing,typeMismatch, …) with zero validation code. - Messages register into
aria-describedbywhile shown and clear when they stop matching. - Server errors via
ServerInvalid, or a form-wideErrorsmap keyed by field name, that auto-clear on the next edit. - An invalid submit is blocked and focus moves to the first invalid control automatically.
Installation
Reference the Navius.Primitives package for the headless primitive, or vendor its source with the CLI: navius add copies the brain files it depends on.
navius add formAnatomy
Import the parts and assemble them.
@using Navius.Primitives.Components.Form
@using Navius.Primitives.Components.Field
<NaviusForm>
<NaviusField Name="...">
<NaviusFieldLabel />
<NaviusFieldControl />
<NaviusFieldError />
<NaviusFieldValidity />
</NaviusField>
<NaviusFormSubmit />
</NaviusForm>API Reference
Root
Wraps the whole form. Renders a native form element and manages the submit, validation and focus flow.
| Prop | Type | Default |
|---|---|---|
| OnSubmit | EventCallback | - |
| Errors | IReadOnlyDictionary<string, string[]>? | - |
| OnClearErrors | EventCallback | - |
| PreventDefault | bool | true |
| ChildContent | RenderFragment? | - |
| Attributes | IDictionary<string, object>? | - |
Field
Groups a label, control and messages under one name. Renders a div.
| Prop | Type | Default |
|---|---|---|
| Name | string | "" |
| Disabled | bool | false |
| Validity | FieldValidity? | - |
| Invalid | bool | false |
| ServerInvalid | bool | false |
| ValidationMode | FieldValidationMode | OnSubmit |
| ChildContent | RenderFragment? | - |
| Attributes | IDictionary<string, object>? | - |
Data attributes
| Data attribute | Values |
|---|---|
| [data-disabled] | Present when the field is disabled |
| [data-valid] | Present when the field is valid |
| [data-invalid] | Present when the field is invalid |
| [data-dirty] | Present when the value differs from the control's initial value |
| [data-touched] | Present once the control has been blurred at least once |
| [data-filled] | Present when the control has a non-empty value |
| [data-focused] | Present while the control has focus |
Label
The field's label. Renders a native label whose for points at the control.
| Prop | Type | Default |
|---|---|---|
| ChildContent | RenderFragment? | - |
| Attributes | IDictionary<string, object>? | - |
Data attributes
| Data attribute | Values |
|---|---|
| [data-disabled] | Present when the field is disabled |
| [data-valid] | Present when the field is valid |
| [data-invalid] | Present when the field is invalid |
| [data-dirty] | Present when the value differs from the control's initial value |
| [data-touched] | Present once the control has been blurred at least once |
| [data-filled] | Present when the control has a non-empty value |
| [data-focused] | Present while the control has focus |
Control
The form control. Renders a native input wired with the field id and aria-* by default, or cascades ControlProps to a custom control via the render-fragment child.
| Prop | Type | Default |
|---|---|---|
| ChildContent | RenderFragment<ControlProps>? | - |
| Attributes | IDictionary<string, object>? | - |
Data attributes
| Data attribute | Values |
|---|---|
| [data-disabled] | Present when the field is disabled |
| [data-valid] | Present when the field is valid |
| [data-invalid] | Present when the field is invalid |
| [data-dirty] | Present when the value differs from the control's initial value |
| [data-touched] | Present once the control has been blurred at least once |
| [data-filled] | Present when the control has a non-empty value |
| [data-focused] | Present while the control has focus |
Error
A validation message tied to a match. Renders a div only while its match fails, and joins aria-describedby while shown.
| Prop | Type | Default |
|---|---|---|
| Match | string? | - |
| ForceMatch | bool | false |
| ChildContent | RenderFragment? | - |
| Attributes | IDictionary<string, object>? | - |
Data attributes
| Data attribute | Values |
|---|---|
| [data-disabled] | Present when the field is disabled |
| [data-valid] | Present when the field is valid |
| [data-invalid] | Present when the field is invalid |
| [data-dirty] | Present when the value differs from the control's initial value |
| [data-touched] | Present once the control has been blurred at least once |
| [data-filled] | Present when the control has a non-empty value |
| [data-focused] | Present while the control has focus |
Validity
Render-prop exposing the field's live FieldValidity. Renders nothing itself.
| Prop | Type | Default |
|---|---|---|
| ChildContent | RenderFragment<FieldValidity>? | - |
Submit
The form's submit button. Renders a native button with type=submit.
| Prop | Type | Default |
|---|---|---|
| ChildContent | RenderFragment? | - |
| Attributes | IDictionary<string, object>? | - |
Data attributes
| Data attribute | Values |
|---|---|
| [data-navius-form-submit] | Present on the submit button |
Accessibility
Built on the native <form>, <label> and form controls, so the browser's own constraint-validation and accessibility semantics apply. The label's for points at the control id; active messages are referenced by aria-describedby; and an invalid control carries aria-invalid="true". A failed submit moves focus to the first invalid control.
Keyboard interactions
| Key | Description |
|---|---|
| Enter | Submits the form. When a field is invalid, submission is blocked and focus moves to the first invalid control. |
| Tab | Moves focus to the next control in the form. |