HxValidationMessage

Displays a list of validation messages for a specified field within a cascaded HxValidationMessage.EditContext.
Reimplementation of ValidationMessage as Bootstrap 5 validation (using .invalid-tooltip).
Used by HxInputBase and derived components.

<EditForm Model="@model" OnValidSubmit="() => SetValidationStatus(true)" OnInvalidSubmit="() => SetValidationStatus(false)">
    <DataAnnotationsValidator />

    <div>@validationMessage</div>

    <HxInputText @bind-Value="@model.Text" Placeholder="Text" />
    <HxSubmit Color="ThemeColor.Primary" Text="Submit" />

    <HxValidationMessage For="() => model.Text" />
</EditForm>

@code {
    private DemoModel model = new();
    private string validationMessage = string.Empty;

    private void SetValidationStatus(bool validationStatus)
    {
        if (validationStatus)
        {
            validationMessage = "Validation passed!";
            return;
        }

        validationMessage = string.Empty;
    }

    protected class DemoModel
    {
        [Required(ErrorMessage = "A text has to be written.")]
        public string Text { get; set; }
    }
}

API

Parameters

Name Type Description
EditContext EditContext EditContext. For exceptional use where EditContext is not used as a CascadingParameter.
For Expression<> Specifies the field for which validation messages should be displayed. Mutual exclusive with ForFieldName and ForFieldNames.
ForFieldName string Specifies the field for which validation messages should be displayed. Mutual exclusive with For and ForFieldNames.
ForFieldNames string[] Specifies the field for which validation messages should be displayed. Mutual exclusive with For and ForFieldName.
An unhandled error has occurred. Reload 🗙