Validation message does not appear when Enter key used (FluentValidation & Blazored.FluentValidation)

I am testing FluentValidation & Blazored.FluentValidation with ValueChanged and have found that the validation message works correctly when using Tab or clicking away from the field. However, when Enter key is used the validation message does not appear (flashes briefly).


@using Blazored.FluentValidation

@using FluentValidation


    <EditForm Model="@_annotation">

        <FluentValidationValidator @ref="_testFluentValidationValidator" />

        <SfTextBox

            Value="@_annotation.Name"

            ValueChanged="ChangeValue"></SfTextBox>

        <ValidationMessage For="@(() => _annotation.Name)" />

    </EditForm>


@code {

    private FluentValidationValidator? _testFluentValidationValidator;

    private Annotation _annotation = new();


    protected async Task ChangeValue(string newValue)

    {

        _annotation.Name = newValue;

        var result = (await _testFluentValidationValidator!.ValidateAsync(options => options.IncludeRuleSets("TestNames")));

        if (result)

        {

            await Task.Delay(100);

        }

        else

        {

            await Task.Delay(100);

        }

    }


    public class AnnotationValidator: AbstractValidator<Annotation>

    {

        public AnnotationValidator()

        {

            RuleSet("TestNames", () =>

            {

                RuleFor(e => e.Name)

                    .NotEmpty().WithMessage("Please enter a name.")

                    .MinimumLength(3).WithMessage($"Name must be longer than 2 characters.");

            });


        }

    }


    public class Annotation

    {

        public string Name { get; set; }

    }

}



1 Reply

UD UdhayaKumar Duraisamy Syncfusion Team February 26, 2025 08:11 AM UTC

We have validated the reported scenario and observed that when pressing the Enter key, the validation is triggered, but the validation message disappears immediately. To further analyze this behavior, we tested the same scenario using the InputText component and found that the issue persists there as well.


Based on our findings, this behavior is specific to Blazored.FluentValidation. We have reported the issue in the Blazored.FluentValidation GitHub repository and provided the link below for your reference. You can follow the issue thread for further updates and discussions regarding this scenario.


GitHub Issue Link: https://github.com/Blazored/FluentValidation/issues/249


Loader.
Up arrow icon