Skip to content
GitHub11 stars

A component that provides labeling and validation for form controls.

Visible on your profile

<FieldRoot class="field">
    <FieldLabel class="field-label">Name</FieldLabel>
    <FieldControl required placeholder="Required" class="field-input" />

Anatomy

Import the primitives and assemble the parts:

@using Blazix.Primitives

<FieldRoot>
    <FieldLabel />
    <FieldControl />
    <FieldDescription />
    <FieldItem />
    <FieldError />
    <FieldValidity />
</FieldRoot>

A field labels and describes its control, and validates it: with the browser's constraint validation (attributes such as required and pattern), a Validate function, or both. ValidationMode chooses when it validates: on submit, on blur, or on every change. It defaults to the form's mode, or to on submit. FieldError shows its message while the field is invalid, or only for the constraint its Match names.

API Reference

FieldRoot

Renders a <div> element.

ParameterTypeDefault
Name string? -
Disabled

Whether the component should ignore user interaction.

bool false
Invalid bool false
Validate Func<object?, string?>? -
ValidateAsyncFunc Func<object?, Task<string?>>? -
ValidationMode ValidationMode? -
ValidationDebounceTime int 0
Render RenderFragment<FieldRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
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 field's value has changed.

-
data-touched

Present when the field has been touched.

-
data-filled

Present when the field is filled.

-
data-focused

Present when the field control is focused.

-

FieldLabel

Renders a <label> element.

ParameterTypeDefault
Render RenderFragment<FieldRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-disabled

Present when the field is disabled.

-
data-valid

Present when the field is in a valid state.

-
data-invalid

Present when the field is in an invalid state.

-
data-dirty

Present when the field's value has changed.

-
data-touched

Present when the field has been touched.

-
data-filled

Present when the field is filled.

-
data-focused

Present when the field control is focused.

-

FieldControl

Renders a <input> element.

ParameterTypeDefault
Value string? -
ValueChanged

Called with the new value when Value changes, for @bind-Value.

EventCallback<string?> -
OnValueChange

Runs before the value changes, with the reason; call Cancel() to keep it.

EventCallback<ValueChangeEventArgs<string?>> -
Disabled

Whether the component should ignore user interaction.

bool false
Render RenderFragment<FieldRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-disabled

Present when the field is disabled.

-
data-valid

Present when the field is in a valid state.

-
data-invalid

Present when the field is in an invalid state.

-
data-dirty

Present when the field's value has changed.

-
data-touched

Present when the field has been touched.

-
data-filled

Present when the field is filled.

-
data-focused

Present when the field control is focused.

-

FieldDescription

Renders a <p> element.

ParameterTypeDefault
Render RenderFragment<FieldRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-disabled

Present when the field is disabled.

-
data-valid

Present when the field is in a valid state.

-
data-invalid

Present when the field is in an invalid state.

-
data-dirty

Present when the field's value has changed.

-
data-touched

Present when the field has been touched.

-
data-filled

Present when the field is filled.

-
data-focused

Present when the field control is focused.

-

FieldItem

Renders a <div> element.

ParameterTypeDefault
Disabled

Whether the component should ignore user interaction.

bool false
Render RenderFragment<FieldRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-disabled

Present when the field is disabled.

-
data-valid

Present when the field is in a valid state.

-
data-invalid

Present when the field is in an invalid state.

-
data-dirty

Present when the field's value has changed.

-
data-touched

Present when the field has been touched.

-
data-filled

Present when the field is filled.

-
data-focused

Present when the field control is focused.

-

FieldError

Renders a <div> element.

ParameterTypeDefault
Match ValidityKey? -
AlwaysShow bool false
Render RenderFragment<FieldRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-disabled

Present when the field is disabled.

-
data-valid

Present when the field is in a valid state.

-
data-invalid

Present when the field is in an invalid state.

-
data-dirty

Present when the field's value has changed.

-
data-touched

Present when the field has been touched.

-
data-filled

Present when the field is filled.

-
data-focused

Present when the field control is focused.

-
data-starting-style

Present when the error message begins animating in.

-
data-ending-style

Present when the error message is animating out.

-

FieldValidity

Doesn't render its own HTML element.

ParameterTypeDefault
ChildContent

The part's content.

RenderFragment<FieldValidityData>? -