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

Input element is not re-rendered

$
0
0

The input element is not re-rendered, the use case is that when the user enters some text the current date is filled into the input element via the 'value' attribute. See the code below.

@page "/"<label>Text Binding check:</label><input type="text" value="@TextData" @onchange="OnChange_Text" /><br /><br /><label>Text Dummy:</label><input type="text" value="dummy" />@code{    public string? TextData { get; set; } = "12-12-2022";    protected override bool ShouldRender()    {        return true;    }    private void OnChange_Text(ChangeEventArgs e)    {        TextData = GetValue(e.Value?.ToString());        InvokeAsync(() => StateHasChanged());    }    private string GetValue(string? strValue)    {        return strValue switch        {"test" => DateTime.Now.ToString("dd-MM-yyyy"),"data" => DateTime.Now.ToString("dd-MM-yyyy"),"nash" => DateTime.Now.ToString("dd-MM-yyyy"),            _ => DateTime.Now.ToString("dd-MM-yyyy")        };    }}

If the user enters the same text or any text again, the date is not rendered in the input element the second time. Even with StateHasChanged() and ShouldRender set to true, the value is not rendered.

Issue demonstarion

So as per the Blazor mechanism the element is not really changed so the render tree will not render the input element to DOM. How can I solve this problem and how can I re-render the element that has not changed?. I thought SateHasChanged() and ShouldRender refresh the UI, it doesn't care about the element difference.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



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