-
-
Notifications
You must be signed in to change notification settings - Fork 364
Description
Describe the bug
有个checkboxlist的问题,我这样给Items赋值时,会出现需要双击才能选中Checkbox,而且只能单选了, 改成razor中声明的List TestItems是无问题的,radiolist和multicselect不会出现这个问题
将下面代码 替换原 BootstrapBlazor.Share.Page.Index.razor 可以复现
code
@layout HomeLayout
@page "/"
@page "/index"
@page "/home"
@{
foreach (var field in FormGen.FormFields)
{
RenderFragment render = null;
switch (field.formFieldType)
{
case FormFieldType.TextBox:
render =@<BootstrapInput DisplayText="@field.Name" ShowLabel="true" TValue="string" @bind-Value="@field.Value"/>;
break;
case FormFieldType.MulticSelecte:
render =@<MultiSelect DisplayText="@field.Name" ShowLabel="true" Items="@field.Selecteds" TValue="string" @bind-Value="@field.Value"/>;
break;
case FormFieldType.Radio:
render =@<RadioList DisplayText="@field.Name" ShowLabel="true" Items="@field.Selecteds" TValue="string" @bind-Value="@field.Value"/>;
break;
case FormFieldType.CheckBox:
render = @<CheckboxList DisplayText="@field.Name" @ref="@testCheckBox" ShowLabel="true" Items="@field.Selecteds" TValue="string" @bind-Value="@field.Value"/>;
break;
}
@render
}
}
@
<CheckboxList @bind-Value="@teststr" DisplayText="测试" ShowLabel="true" Items="TestItems"/>
@
@code
{
public class FormGenerator
{
public IEnumerable<FormField> FormFields { get; set; }
}
public class FormField
{
public string Name { get; set; }
public FormFieldType formFieldType { get; set; }
public string Parameter;
public IEnumerable<SelectedItem>? Selecteds => System.Text.Json.JsonSerializer.Deserialize<List<SelectedItem>>(Parameter);
public string Value { get; set; }
}
public enum FormFieldType
{
TextBox,
Radio,
MulticSelecte,
CheckBox
}
public FormGenerator FormGen = new FormGenerator
{
FormFields = new List<FormField>
{
new FormField{formFieldType= FormFieldType.TextBox,Name="测试1"},
new FormField{formFieldType= FormFieldType.Radio,Name="测试2",Parameter="[{\"Text\":\"1\",\"Value\":\"1\",\"Active\":false,\"IsDisabled\":false,\"GroupName\":\"\"},{\"Text\":\"2\",\"Value\":\"2\",\"Active\":false,\"IsDisabled\":false,\"GroupName\":\"\"},{\"Text\":\"3\",\"Value\":\"3\",\"Active\":false,\"IsDisabled\":false,\"GroupName\":\"\"}]"},
new FormField{formFieldType= FormFieldType.MulticSelecte,Name="测试3",Value="1,3",Parameter="[{\"Text\":\"1\",\"Value\":\"1\",\"Active\":false,\"IsDisabled\":false,\"GroupName\":\"\"},{\"Text\":\"2\",\"Value\":\"2\",\"Active\":false,\"IsDisabled\":false,\"GroupName\":\"\"},{\"Text\":\"3\",\"Value\":\"3\",\"Active\":false,\"IsDisabled\":false,\"GroupName\":\"\"}]"},
new FormField{formFieldType= FormFieldType.CheckBox,Name="测试3",Value="1,3",Parameter="[{\"Text\":\"1\",\"Value\":\"1\",\"Active\":false,\"IsDisabled\":false,\"GroupName\":\"\"},{\"Text\":\"2\",\"Value\":\"2\",\"Active\":false,\"IsDisabled\":false,\"GroupName\":\"\"},{\"Text\":\"3\",\"Value\":\"3\",\"Active\":false,\"IsDisabled\":false,\"GroupName\":\"\"}]"},
}
};
private string TestStr { get; set; }
private List<SelectedItem> TestItems = new List<SelectedItem>
{
new SelectedItem{Text="1",Value="1"},
new SelectedItem{Text="2",Value="2"},
new SelectedItem{Text="3",Value="3"},
};
private CheckboxList<string> testCheckBox { get; set; }
public async Task OnSave()
{
var sf = FormGen;
var fsd = TestStr;
System.Diagnostics.Debug.WriteLine($"{testCheckBox.Value}");
}
}