logoEnterprise-level component library based on Bootstrap and Blazor
gitee
version
license
download
repo
commit
build
coverage

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

Pat,Argo

Binding values are collections

Demo

Tvalue is set to IEnumerable<int> generic collection, the ValueField specified field of the bound collection must be consistent with the generic type

9,10

TValue is set to IEnumerable<string> generic collection

13,15

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

Middle,Primary

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

Loading...

Event

Loading...
@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">
    <p></p>
    <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>
    <CheckboxList @bind-Value="@Value1" Items="@Items1" ShowLabel="true" DisplayText="@Localizer[nameof(Foo.Name)]"
                  OnSelectedChanged="@OnSelectedChanged"></CheckboxList>
    <BlockLogger class="mt-3" @ref="Trace" />
</DemoBlock>

<DemoBlock Title="Client Validation" Introduction="Built in validateform" Name="ValidateForm">
    <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>
    <ValidateForm Model="@Dummy">
        <div class="row g-3">
            <div class="col-12">
                <CheckboxList @bind-Value="@Dummy.Name" Items="@Items2" />
            </div>
            <div class="col-12">
                <label class="form-label">@Localizer["Foo.BindValue"]</label>
                <div class="form-control flex-fill">@Dummy.Name</div>
            </div>
        </div>
    </ValidateForm>
</DemoBlock>

<DemoBlock Title="Bidirectional binding collection" Introduction="Binding values are collections" Name="ShowLabel">
    <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>
    <div class="row g-3">
        <div class="col-12">
            <CheckboxList TValue="IEnumerable<int>" Items="@Items3" @bind-Value="@Value2" ShowLabel="true" DisplayText="@Localizer[nameof(Foo.Name)]" />
        </div>
        <div class="col-12">
            <label class="form-label">@Localizer["Foo.BindValue"]</label>
            <div class="form-control">@(string.Join(",", Value2))</div>
        </div>
    </div>
    <p class="mt-3">TValue is set to <code>IEnumerable<string></code> generic collection</p>
    <div class="row g-3">
        <div class="col-12">
            <CheckboxList TValue="IEnumerable<string>" Items="@Items4" @bind-Value="@Value3" ShowLabel="true" DisplayText="@Localizer[nameof(Foo.Name)]" />
        </div>
        <div class="col-12">
            <label class="form-label">@Localizer["Foo.BindValue"]</label>
            <div class="form-control flex-fill">@(string.Join(",", Value3))</div>
        </div>
    </div>
</DemoBlock>

<DemoBlock Title="Bidirectional binding enumeration" Introduction="The binding value is enumeration" Name="Enum">
    <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>
    <div class="row g-3">
        <div class="col-12">
            <CheckboxList @bind-Value="@SelectedEnumValues" ShowLabel="true" DisplayText="@Localizer[nameof(Foo.Name)]" />
        </div>
        <div class="col-12">
            <label class="form-label">@Localizer["Foo.BindValue"]</label>
            <div class="form-control">@(string.Join(",", SelectedEnumValues))</div>
        </div>
    </div>
</DemoBlock>

<DemoBlock Title="No border" Introduction="By setting <code>ShowBorder='false'</code> do not display borders" Name="NoBorder">
    <p>Displays a red border when validation fails</p>
    <ValidateForm Model="@Dummy">
        <CheckboxList @bind-Value="@Dummy.Name" ShowBorder="false" Items="@Items2" />
    </ValidateForm>
</DemoBlock>

<DemoBlock Title="Vertical arrangement" Introduction="Arrange checkboxes vertically by setting <code>IsVertical = 'true' </code >" Name="Vertical">
    <CheckboxList @bind-Value="@Dummy1.Name" IsVertical="true" ShowBorder="false" Items="@Items5" />
</DemoBlock>

<DemoBlock Title="Disable" Introduction="Disable by setting <code>IsDisabled='true'</code>" Name="Disabled">
    <CheckboxList @bind-Value="@Dummy2.Name" IsDisabled="true" ShowBorder="false" Items="@Items6" />
</DemoBlock>

<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>
/// 
/// </summary>
public partial class CheckboxLists
{
    [NotNull]
    private IEnumerable<SelectedItem>? Items1 { get; set; }

    [NotNull]
    private IEnumerable<SelectedItem>? Items2 { get; set; }

    [NotNull]
    private IEnumerable<SelectedItem>? Items3 { get; set; }

    [NotNull]
    private IEnumerable<SelectedItem>? Items4 { get; set; }

    [NotNull]
    private IEnumerable<SelectedItem>? Items5 { get; set; }

    [NotNull]
    private IEnumerable<SelectedItem>? Items6 { get; set; }

    [Inject]
    [NotNull]
    private IStringLocalizer<CheckboxLists>? Localizer { get; set; }

    private IEnumerable<EnumEducation> SelectedEnumValues { get; set; } = new List<EnumEducation> { EnumEducation.Middle, EnumEducation.Primary };

    private string Value1 { get; set; } = "1,3";

    private IEnumerable<int> Value2 { get; set; } = new int[] { 9, 10 };

    private IEnumerable<string> Value3 { get; set; } = new string[] { "13", "15" };
    private Foo Dummy { get; set; } = new Foo();
    private Foo Dummy1 { get; set; } = new Foo();
    private Foo Dummy2 { get; set; } = new Foo();

    private BlockLogger? Trace { get; set; }

    /// <summary>
    /// OnInitialized method
    /// </summary>
    /// <returns></returns>
    protected override void OnInitialized()
    {
        base.OnInitialized();

        Items1 = new List<SelectedItem>(new List<SelectedItem>
        {
            new SelectedItem { Text = "Item 1", Value = "1" },
            new SelectedItem { Text = "Item 2", Value = "2" },
            new SelectedItem { Text = "Item 3", Value = "3" },
            new SelectedItem { Text = "Item 4", Value = "4" },
        });

        Items2 = new List<SelectedItem>(new List<SelectedItem>
        {
            new SelectedItem { Text = Localizer["SL1"], Value = Localizer["SL1"] },
            new SelectedItem { Text = Localizer["SL2"], Value = Localizer["SL2"] },
            new SelectedItem { Text = Localizer["SL3"], Value = Localizer["SL3"] },
            new SelectedItem { Text = Localizer["SL4"], Value = Localizer["SL4"] },
        });

        Items3 = new List<SelectedItem>(new List<SelectedItem>
        {
            new SelectedItem { Text = "Item 9", Value = "9" },
            new SelectedItem { Text = "Item 10", Value = "10" },
            new SelectedItem { Text = "Item 11", Value = "11" },
            new SelectedItem { Text = "Item 12", Value = "12" },
        });

        Items4 = new List<SelectedItem>(new List<SelectedItem>
        {
            new SelectedItem { Text = "Item 13", Value = "13" },
            new SelectedItem { Text = "Item 14", Value = "14" },
            new SelectedItem { Text = "Item 15", Value = "15" },
            new SelectedItem { Text = "Item 16", Value = "16" },
        });

        Items5 = new List<SelectedItem>(new List<SelectedItem>
        {
            new SelectedItem { Text = Localizer["SL10"], Value = Localizer["SL10"] },
            new SelectedItem { Text = Localizer["SL11"], Value = Localizer["SL11"] },
            new SelectedItem { Text = Localizer["SL12"], Value = Localizer["SL12"] },
            new SelectedItem { Text = Localizer["SL13"], Value = Localizer["SL13"] },
        });

        Items6 = new List<SelectedItem>(new List<SelectedItem>
        {
            new SelectedItem { Text = Localizer["SL21"], Value = Localizer["SL21"] },
            new SelectedItem { Text = Localizer["SL22"], Value = Localizer["SL22"] },
            new SelectedItem { Text = Localizer["SL23"], Value = Localizer["SL23"] },
            new SelectedItem { Text = Localizer["SL24"], Value = Localizer["SL24"] },
        });

        Dummy = new Foo() { Name = Localizer["Foo1"] };
        Dummy1 = new Foo() { Name = Localizer["Foo2"] };
        Dummy2 = new Foo() { Name = Localizer["Foo3"] };
    }

    private Task OnSelectedChanged(IEnumerable<SelectedItem> items, string value)
    {
        Trace?.Log($"{Localizer["Header"]} {items.Where(i => i.Active).Count()} {Localizer["Counter"]}:{value}");
        return Task.CompletedTask;
    }

    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>"
        }
    };
}

B station related video link

No

交流群

QQ Group:BootstrapAdmin & Blazor 795206915 675147445 Welcome to join the group discussion
img
Themes
Bootstrap
Motronic
Ant Design (完善中)
DevUI (制作中)
LayUI (完善中)
An error has occurred. This application may no longer respond until reloaded. Reload
Seems like the connection with the server has been lost. It can be due to poor or broken network. Please hang on while we're trying to reconnect...
Oh snap! Failed to reconnect with the server. This is typically caused by a longer network outage, or if the server has been taken down. You can try to reconnect, but if that does not work, you need to reload the page.
Oh man! The server rejected the attempt to reconnect. The only option now is to reload the page, but be prepared that it won't work, since this is typically caused by a failure on the server.
Bootstrap Blazor Component library updated to 7.0.8-beta05

Bootstrap Blazor at present has more than 120 components. This component is based on Bootstrap Blazor An enterprise-level component library that provides several types of common components such as layout, navigation, form, data, notification, icon, voice, etc. Each component has been carefully designed with modularity, responsiveness and excellent performance. Starting from more practical scenarios, meeting the needs of various scenarios, greatly reducing the time cost of developers, greatly shortening the development cycle, greatly improving development efficiency, and providing a set of General Rights Management System Example project。Bootstrap Blazor Products are maintained by a professional full-time technical team, with efficient response speed, diversified solutions, long-term support, and enterprise-level support. At present, it has been used in many well-known state-owned enterprises, and the project is running stably with a maximum of 1200 people online. On the right is the QR code of the Chinese Blazor QQ community with the largest number of people in China, welcome to scan and join the group.

component updated to 6.6.0 Change log [portal] If the component brings you convenience, please help to light up the project Star github gitee

QQGroup
QQ 795206915