Skip to content

Blazor/Razor: Binded value constraint does not work as expected. #19788

Open

Description

Describe the bug

When the bound input value is updated to be equal to the previous value then subsequent updates do not behave as expected.

To Reproduce

Copy the following into a .razor page. Then view it in a browser and update the top field. Notice that the other bound fields update as expected.
Then, update one of the bottom fields and notice that the update only acts as expected with the first character input. After the first character, the binding behavior is not as expected.


<div style="border: 5px solid black; margin: 5px;">
  <p>
    Updating the value of this input works as expected.
  </p>
  <p>
    <input value="@value" @oninput="@((ChangeEventArgs e) => value = e.Value.ToString())" />
  </p>
</div>
<div style="border: 2px solid black; margin: 5px;">
  <p>
    These do not work as expected.<br />
    When you type multiple characters the value should stay "constant" but it does not.<br />
    These update the value to "constant" with the first character input; but subsequent<br />
    characters are appended to the end of the current input and other bindings are not updated<br/>
    as demonstrated with the above input field not getting updated.
  </p>
  <p>
    <input value="@value" @oninput="@((ChangeEventArgs e) => ChangeValue(e))" />
    <input value="@value" @oninput="@((ChangeEventArgs e) => value = "Constant")" />
  </p>

</div>

@code {
  string value = "Default";

  private void ChangeValue(ChangeEventArgs e)
  {
    value = "Constant";
  }
}

Further technical details

dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 3.1.200-preview-015002
Commit: b3dae24c3b

Runtime Environment:
OS Name: Windows
OS Version: 10.0.18363
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.1.200-preview-015002\

Host (useful for support):
Version: 3.1.2
Commit: 916b5cba26

.NET Core SDKs installed:
3.1.101 [C:\Program Files\dotnet\sdk]
3.1.102 [C:\Program Files\dotnet\sdk]
3.1.200-preview-015002 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

The IDE (VS / VS Code/ VS4Mac) you're running on, and it's version
Visual Studio: Version 16.5.0 Preview 5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Pillar: Technical Debtaffected-very-fewThis issue impacts very few customersarea-blazorIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.feature-blazor-component-modelAny feature that affects the component model for Blazor (Parameters, Rendering, Lifecycle, etc)severity-minorThis label is used by an internal tool

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions