Skip to content

InputSelect with empty option doesn't validate int #47088

@giarico

Description

@giarico

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When i submit the form, if I don't change the value of the select, I have no validation error.
If I change value and go back to the empty choice, the error is shown.

public class MyModel
{
    [Required]
    public int MyProperty { get; set; }
}
<EditForm Model="model" OnValidSubmit="HandleValidSubmit">

    <DataAnnotationsValidator />
    <ValidationSummary />

    <InputSelect @bind-Value="model.MyProperty">
        <option></option>
        <option value="1">1</option>
        <option value="2">2</option>
    </InputSelect>

    <button type="submit">Save</button>
</EditForm>

@code 
{
    MyModel model = new();

    void HandleValidSubmit()
    {
        
    }
}

This is when you click insert without changing option
first

This is when you click insert changing option and going back to the empty choice
second

Expected Behavior

The validation should trigger also when I don't modify the choice

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

7

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions