Skip to content
This repository was archived by the owner on Dec 26, 2025. It is now read-only.
This repository was archived by the owner on Dec 26, 2025. It is now read-only.

The validation message does not appear correctly when the Enter key is used (FluentValidation & Blazored.FluentValidation). #249

@UdhayaKumarDuraisamy

Description

@UdhayaKumarDuraisamy

Description
While testing FluentValidation and Blazored.FluentValidation with the InputText component's ValueChanged event, observed that the validation message works correctly when using the Tab key or clicking away from the field. However, when the Enter key is used, the validation message does not appear and only flashes briefly.

@using Blazored.FluentValidation
@using FluentValidation

<div style="margin: 150px auto; width: 50%">

    <EditForm Model="@_annotation">
        <FluentValidationValidator @ref="_testFluentValidationValidator" />
        <InputText class="form-control"
                   Value="@_annotation.Name"
                   ValueChanged="ChangeValue"
                   ValueExpression="@(() => _annotation.Name)"></InputText>
        <ValidationMessage For="@(() => _annotation.Name)" />
    </EditForm>
</div>
@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; }
    }
}

To Reproduce
Steps to reproduce the behavior:

  1. Run the code snippet provided above.
  2. Focus on the input field and type "A".
  3. Press the Enter key.

Expected behavior
The validation message needs to be displayed properly.

Video of the issue:

1436.mp4

Hosting Model (is this issue happening with a certain hosting model?):

  • Blazor Server
  • Blazor WebAssembly

Additional context
While testing the same scenario with Jeremy FluentValidation, it worked well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't workingTriageIssue needs to be triaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions