dotnet / dotnet/aspnetcore

InputNumber validation breaks when hidden and subsequently rerendered

Open
#48,855 3 comments 0 reactions 0 assignees View on GitHub
area-blazor bug feature-blazor-form-validation Pillar: Technical Debt Priority:1
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 5h
Merged PRs (30d)
276

Description

### Is there an existing issue for this?

- [X] 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"

@if (pageIndex == 0)
{


Next
}
else if (pageIndex == 1)
{
Back
}

@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](https://github.com/dotnet/aspnetcore/assets/127516733/60c70702-5226-4251-9ec4-bca10a368ece)

Step 4
![image](https://github.com/dotnet/aspnetcore/assets/127516733/13521b7d-acf6-4b6d-9f83-e480ac0284a5)

Step 5
![image](https://github.com/dotnet/aspnetcore/assets/127516733/8c84bac2-e907-4b19-aa64-63a493ea94ec)

Step 6
![image](https://github.com/dotnet/aspnetcore/assets/127516733/0e253616-974a-469f-a615-2fa71cadc087)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.