I have defined max. min. values for my numerical input field in my blazor app. If the user input is out of range, the last value shall be kept. How?

Viewed 24

My code in my Blazor Server app is as follows:

I am checking the input, on "oninput" event. In my check function I compare the value reg. max and min limits. If they are out of range I can set them to the limit value. That is working.

But I want, if the entered value is out of range, the input value should return immediatly to the last entered correct value. How can I do that?

 <td> <input type="text" inputmode="numeric" @bind="@NC_VAR_index"  @onchange=@(e => check_NC_VAR_index(e)) /></td>
 

 protected void check_NC_VAR_index(ChangeEventArgs e)
 {
    if(NC_VAR_index>4) // max value
    {
        TagService.NC_VAR_index[index_] = 4;
    }

    if(NC_VAR_index<1) // min value
    {
        TagService.NC_VAR_index[index_] = 1;
    }
 }
0 Answers
Related