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

Blazor InputText binding not updating UI with space string is assigned, but works when empty

$
0
0

I can't figure out why if I assign an empty string in the "if" block, everything works and the string and field are updated.But if I remove the space at the end, also changing the variable, nothing happens. I used StateHasChanged but it does not help. I checked the value through debugging, the line definitely changes.

<TagList ListOfTagNames="Tags"><InputText @bind-value="Tag" @oninput="HandleInput" class="w-full inputSetUp bgDarkLight" placeholder="Укажитетеги..." /><p>Value: @Tag</p></TagList>@code {    public string Tag { get; set; } = "";    [Parameter]    public List<string> Tags { get; set; } = new();    private void HandleInput(ChangeEventArgs e)    {        Tag = e.Value.ToString().TrimStart();        bool spaceIsTiped = Tag.EndsWith('');        bool isValidTag = !string.IsNullOrEmpty(Tag) && Tag.Length > 2 && spaceIsTiped;        if (isValidTag)        {            Tags.Add(Tag.ToUpper());            Tag = "";        }        else        {            Tag = Tag.Trim();            StateHasChanged();        }    }}

Viewing all articles
Browse latest Browse all 4839

Trending Articles



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