
CheckboxList
The control is used to create a multi-select check box group
Show check box groups by data binding
Demo
- Set bidirectional binding data value through
bind-Value
- Set candidate data sources through
Items
- Get the changed item instance through the
onSelectedChanged
callback method
Built in validateform
Demo
You can experience adaptive layout by changing the window size
In this example, the Name
field of the binding model binditem
is automatically changed by checking the option
Because it is built into the ValidateForm
form, in this example, RequiredAttribute
required for verification is added. When all options are cancelled, the verification result will be prompted
ShowLabelIntro
Demo
Tvalue is set to IEnumerable<int>
generic collection, the ValueField
specified field of the bound collection must be consistent with the generic type
TValue is set to IEnumerable<string>
generic collection
The binding value is enumeration
Demo
When CheckboxList
binds an enumeration set, Items
does not need to be specified, Items
will be automatically set to all values in the enumeration. If you need to bind some values, please provide the enumeration set Items
By setting ShowBorder='false'
do not display borders
Demo
Displays a red border when validation fails
Arrange checkboxes vertically by setting IsVertical = 'true'
Demo
Disable by setting IsDisabled='true'
Demo
Attributes
Event
@page "/checkboxlists"
<h3>CheckboxList</h3>
<h4>The control is used to create a multi-select check box group</h4>
<DemoBlock Title="Basic usage" Introduction="Show check box groups by data binding" Name="Normal" Demo="typeof(Demos.CheckboxList.CheckboxListNormal)">
<ul class="ul-demo mb-3">
<li>Set bidirectional binding data value through <code>bind-Value</code ></li>
<li>Set candidate data sources through <code>Items</code></li>
<li>Get the changed item instance through the <code>onSelectedChanged</code> callback method</li>
</ul>
</DemoBlock>
<DemoBlock Title="Client Validation" Introduction="Built in validateform" Name="ValidateForm" Demo="typeof(Demos.CheckboxList.CheckboxListValidateForm)">
<p>You can experience adaptive layout by changing the window size</p>
<p>In this example, the <code>Name</code> field of the binding model <code>binditem</code> is automatically changed by checking the option</p>
<p>Because it is built into the <code>ValidateForm</code> form, in this example, <code>RequiredAttribute</code> required for verification is added. When all options are cancelled, the verification result will be prompted</p>
</DemoBlock>
<DemoBlock Title="@Localizer["ShowLabelTitle"]" Introduction="@Localizer["ShowLabelIntro"]" Name="ShowLabel" Demo="typeof(Demos.CheckboxList.CheckboxListShowLabel)">
<p>Tvalue is set to <code>IEnumerable<int></code> generic collection, the <Code>ValueField</Code> specified field of the bound collection must be consistent with the generic type</p>
</DemoBlock>
<DemoBlock Title="Bidirectional binding enumeration" Introduction="The binding value is enumeration" Name="Enum" Demo="typeof(Demos.CheckboxList.CheckboxListEnum)">
<p>When <code>CheckboxList</code> binds an enumeration set, <code>Items</code> does not need to be specified, <code>Items</code> will be automatically set to all values in the enumeration. If you need to bind some values, please provide the enumeration set <code>Items</code></p>
</DemoBlock>
<DemoBlock Title="No border" Introduction="By setting <code>ShowBorder='false'</code> do not display borders" Name="NoBorder" Demo="typeof(Demos.CheckboxList.CheckboxListNoBorder)">
<p>Displays a red border when validation fails</p>
</DemoBlock>
<DemoBlock Title="Vertical arrangement" Introduction="Arrange checkboxes vertically by setting <code>IsVertical = 'true' </code >" Name="Vertical" Demo="typeof(Demos.CheckboxList.CheckboxListVertical)" />
<DemoBlock Title="Disable" Introduction="Disable by setting <code>IsDisabled='true'</code>" Name="Disabled" Demo="typeof(Demos.CheckboxList.CheckboxListDisabled)" />
<AttributeTable Items="@GetAttributes()" />
<EventTable Items="@GetEvents()" />
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Website: https://www.blazor.zone or https://argozhang.github.io/
namespace BootstrapBlazor.Shared.Samples;
/// <summary>
/// CheckboxLists
/// </summary>
public partial class CheckboxLists
{
[Inject]
[NotNull]
private IStringLocalizer<CheckboxLists>? Localizer { get; set; }
private IEnumerable<AttributeItem> GetAttributes() => new AttributeItem[]
{
new AttributeItem() {
Name = "Items",
Description = Localizer["Att1"],
Type = "IEnumerable<SelectedItem>",
ValueList = " — ",
DefaultValue = " — "
},
new AttributeItem() {
Name = "IsDisabled",
Description = Localizer["Att1"],
Type = "boolean",
ValueList = " — ",
DefaultValue = "false"
},
new AttributeItem(){
Name = "Value",
Description = Localizer["Att1"],
Type = "TValue",
ValueList = " — ",
DefaultValue = " — "
},
new AttributeItem(){
Name = "IsVertical",
Description = Localizer["Att1"],
Type = "boolean",
ValueList = " true / false ",
DefaultValue = " false "
}
};
/// <summary>
/// Get event method
/// </summary>
/// <returns></returns>
private IEnumerable<EventItem> GetEvents() => new EventItem[]
{
new EventItem()
{
Name = "OnSelectedChanged",
Description = Localizer["Event1"],
Type ="Func<IEnumerable<SelectedItem>, TValue, Task>"
}
};
}