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

Why isn't my bound value updating with each keystroke?

$
0
0

I have two html components - an <input type="text"/> and a <label/>. The goal is to have the value of the label update with each keystroke of the textbox.

The text input is setup like this:

<input type="text" @bind="@SelectedField.Name"/>

The behavior that I'm seeing is the value of the text-input isn't propagating to SelectedField.Name with each keystroke. I setup an @onKeyUp event to check this. Entering values into the text-input isn't updating the value of SelectedField.Name until after the text-input is destroyed.

This implementation is in .NET 7.

How I tested this:

<input type="text" @bind="@SelectedField.Name" @onkeyup="() => CheckData()"/>@code {    public void CheckData()    {        Console.WriteLine(SelectedField.Name);    }}
  1. The initial value of SelectedField.Name is String.Empty
  2. Expected behavior is that on every key-press, the value of the text-input is printed to the console.
  3. Actual behavior is that on every key-press, an empty string is printed to the console.

Is this a bug? Am I using the @bind functionality incorrectly? I'm coming from Angular so maybe I'm looking at this with the wrong pattern.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



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