Skip to content

InputNumber validation breaks when hidden and subsequently rerendered #48855

Open
@shirkrm

Description

@shirkrm

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When using an InputNumber backed by a non-nullabe value, deleting the value from the field and changing the rendering breaks the validation message.

@page "/example"

<EditForm EditContext="EditContext">

@if (pageIndex == 0)
{
    <InputNumber @bind-Value="Value"/>
    <ValidationMessage For="() => Value" />
    <button @onclick="()=>++pageIndex">Next</button>
}
else if (pageIndex == 1)
{
    <button @onclick="()=>--pageIndex">Back</button>
}
</EditForm>

@code
{
    private EditContext EditContext { get; set;; }
    public int Value { get; set; }

    private int pageIndex;

    protected override void OnInitialized()
    {
        EditContext = new EditContext(Value);
    }

}

Expected Behavior

The validation message is still linked to the field and can be removed by inputting a valid value.

Steps To Reproduce

  1. Delete the value from the InputNumber field and tab out. See the validation message.
  2. Click Next.
  3. Click Back.
  4. See the validation message still exists even though the field has reset to zero.
  5. Delete the value from the InputNumber field and tab out. See a second validation message. The first validation message can not be removed without reloading the page, while the last message can be removed by setting the field to a number.
  6. Repeat.

Exceptions (if any)

No response

.NET Version

7.0.302

Anything else?

Step 1
image

Step 4
image

Step 5
image

Step 6
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Pillar: Technical DebtPriority:1Work that is critical for the release, but we could probably ship withoutarea-blazorIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.feature-blazor-form-validationThis issue is related to forms validation in Blazor

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions