Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Updating input field in Blazor fails

$
0
0
<input value="@Answer" @oninput="OnInput" />

Enter any series of digits.
If you enter more than two digits, input will be cleared.
If you enter '12', input will be cleared.
Same should happen for 8. I can't see why it fails.

@code {    private string Answer = "";    private string input = "";    private string updated = "";    private void OnInput(ChangeEventArgs e) {        string answer = e.Value!.ToString()!;        input = ":" + answer;        if (answer == "12" || answer == "8") {   // correct answer!            Answer = "";    //        if (answer.Length == 1) {    //            Console.WriteLine(Answer);    //        }  // uncomment this if you want to add a breakpoint when it should clear        } else if (answer.Length > 2) {            Answer = "";        } else {            Answer = answer;        }        updated = ":" + Answer +":";        StateHasChanged();    }}

Try it here:
https://blazorfiddle.com/s/bgudkadp


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>