Skip to content

Blazor Wasm does not honor binding if previous value is a part of the new value for textarea when using oninput #45797

Closed
@roysurles

Description

@roysurles

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Blazor Wasm does not honor binding if previous value is a part of the new value for textarea when using oninput

Expected Behavior

I expect the textarea to render the new value.

Steps To Reproduce

  1. Start new Blazor Wasm project (.Net 6 or .Net 7)
  2. Copy the following code into Index.razor
  3. type "12345" into the first textarea
    3a) the textarea renders "12345" instead of "1234" even though the underlying value is "1234"
  4. type "12345" into the second textarea
    4a) the textarea renders the correct value of "abcd", but if you keep typing the same result of the textarea occurs
<div class="row">
    <div class="col">
        <br />
    </div>
</div>

<div class="col">
    <textarea value="@InputValue1"
        @oninput="@OnTextAreaInput1">
    </textarea>
</div>

<div class="row">
    <div class="col">
        <label>InputValue1 = @InputValue1</label>
    </div>
</div>

<div class="row">
    <div class="col">
        <br />
        <hr />
        <br />
    </div>
</div>

<div class="col">
    <textarea value="@InputValue2"
        @oninput="@OnTextAreaInput2">
    </textarea>
</div>

<div class="row">
    <div class="col">
        <label>InputValue2 = @InputValue2</label>
    </div>
</div>


@code {

    protected string? InputValue1 { get; set; }

    protected void OnTextAreaInput1(ChangeEventArgs changeEventArgs)
    {
        var newValue = changeEventArgs.Value?.ToString() ?? string.Empty;

        InputValue1 = newValue.Length > 4
            ? "1234"
            : InputValue1 = newValue;
    }

    // *************************************************************

    protected string? InputValue2 { get; set; }

    protected void OnTextAreaInput2(ChangeEventArgs changeEventArgs)
    {
        var newValue = changeEventArgs.Value?.ToString() ?? string.Empty;

        InputValue2 = newValue.Length > 4
            ? "abcd"
            : InputValue2 = newValue;
    }

}

Exceptions (if any)

No unhandled exception

.NET Version

.Net 6 & .Net 7

Anything else?

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.Status: Resolvedarea-blazorIncludes: Blazor, Razor Componentsfeature-renderingFeatures dealing with how blazor renders componentsquestion

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions