带有表单字段的大火服务器侧竞赛条件
我有一个问题,即单击单击后立即重置单选按钮。
我有以下形式的字段:
i think think 发生了什么事:
- 用户在输入中键入一个值
- ,然后单击无线电选项(同时将焦点放在焦点中文本输入)
- 此单击“触发文本输入到fire Server sine的OnChange/bind事件”
- ,用户在短时间内看到了他们的无线电选项,
- 大概是当服务器从输入的OnChange事件中响应时选择的无线电选项,它将重新呈现“无线电”按钮当时它收到的状态 - 即没有无线电选择
代码:
<InputText @bind-Value="_viewModel.Amount"></InputText>
<InputRadioGroup @bind-Value="_viewModel.SelectedOptionId" Name="name">
@foreach (var option in _viewModel.RadioOptions)
{
<InputRadio Name="name" Value="@option.Id.ToString()" />
<text> </text>@option.Name<br>
}
</InputRadioGroup>
您如何防止此?
I have an issue where a radio button selection is reset immediately after clicking it.
I have the following fields in a form:
I think what's happening is:
- The user types a value into the input
- The user then clicks a radio option (whilst having focus in the text input)
- This click triggers the onChange/bind event for the text input to fire server side
- For a brief moment, the user see's their radio option selected
- Presumably when the server responds from the input's onChange event, it re-renders the radio button with the state it received at the time - i.e. no radio selection
Code:
<InputText @bind-Value="_viewModel.Amount"></InputText>
<InputRadioGroup @bind-Value="_viewModel.SelectedOptionId" Name="name">
@foreach (var option in _viewModel.RadioOptions)
{
<InputRadio Name="name" Value="@option.Id.ToString()" />
<text> </text>@option.Name<br>
}
</InputRadioGroup>
How do you prevent this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里发生的事情是您绑定到错误的类型。
我认为RadioOption.ID和SelectedOptionID均为
int
。很好,但是不要将选项的ID转换为其他东西。它将阻碍与所选值的绑定。
What is happening here is that you bind to the wrong type.
I assume that both RadioOption.Id and SelectedOptionId are of type
int
.That is fine, but then don't convert the Options' Ids to something else. It will hinder binding to the Selected value.
事实证明,
inputRadiogroup
控制存在问题。此github问题描述了问题。
建议的解决方法(有效)是实施具有以下添加行为的自定义inputradiogroup:
我相信这将在.net 7中按照此拉请求
It turned out that there is an issue with the
InputRadioGroup
control.This GitHub issue describes the problem.
The suggested workaround (which worked) is to implement a custom InputRadioGroup with the following added behaviour:
I believe this will be addressed in .NET 7 as per this pull request