[Blazor] Cannot bind custom checkbox element's `checked` value
See original GitHub issueDescribe the bug
Cannot bind custom checkbox element’s checked
value.
I am using the new FAST web components in a Blazor server side application and trying to bind the checkbox component any way I can, referencing <input type="checkbox" />
:
<!-- Works! -->
<input type="checkbox" @bind="MyBool" />
<!-- Does not work... -->
<fast-checkbox @bind-checked="MyBool" @bind-checked:event="onchange"></fast-checkbox>
<fast-checkbox checked="@MyBool" @onchange="@((ChangeEventArgs e) => ViewModel.AcceptTerms = (bool)e.Value"></fast-checkbox>
I know the values themselves are binding because changing the native input will cause the fast components to change to match. The problem seems to lie within the event. The event mapping code has a check built in specifically for checkboxes which causes the change event value to fall back to element.value
, in this case e.Value
is always "on"
.
Rather than making an exception for checkboxes, could we simply always include both value
and checked
in ChangeEventArgs
to match the JavaScript behavior? If this approach is acceptable I will open a PR.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:10 (5 by maintainers)
@arshia11d - two-way works for my checkbox. If I bind a native checkbox input to the same value they will both update to match. Blazor just doesn’t properly populate
ChangeEventArgs
because it only does so if the target isinput type="checked"
: https://github.com/dotnet/aspnetcore/blob/1455aaeff118aeaf2b0ab5f1627c2c8ca5df7f11/src/Components/Web.JS/src/Rendering/EventForDotNet.ts#L218-L220We’ve moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.