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

Checkbox

Multiple-select in a set of alternatives

Using alone can represent a switch between two states, and column head or header can represent a switch between three states when used. Components support generic data binding, setting the binding data type the TValue, and setting the component state by State

Demo

Check box is not available, and the IsDisabled is set by whether the component is available

Demo

Change the component background color by setting the Color property

Demo

Change the component size by setting the Size property

Demo

The check box displays text, and the component status flips when you tap display text, using the DisplayText settings component to display text

Demo

Set DisplayText property, or display text messages through bidirectional binding

Binding variables within a component, data automatically synchronized, binding data types boolean type when the value is automatically flipped

Demo

Binding variables within a component, data is automatically synchronized

Demo

When you use Checkbox in a form, the display label text is placed in front of the component

Demo

The pre-label explicit rules are consistent with the BootstrapInput component [portal]

Attributes

Loading...

Event

Loading...
@page "/checkboxs"
@inject IStringLocalizer<Checkboxs> Localizer

<h3>Checkbox</h3>

<h4>Multiple-select in a set of alternatives</h4>

<DemoBlock Title="Basic usage" Introduction="Using alone can represent a switch between two states, and column head or header can represent a switch between three states when used. Components support generic data binding, setting the binding data type the <code>TValue</code>, and setting the component state by <code>State</code>" Name="Normal">
    <div class="row g-3 form-inline">
        <div class="col-12 col-sm-4">
            <Checkbox TValue="string" State="CheckboxState.Checked" OnStateChanged="@OnStateChanged" DisplayText="Selected" ShowLabel="true"></Checkbox>
        </div>
        <div class="col-12 col-sm-4">
            <Checkbox TValue="string" State="CheckboxState.UnChecked" OnStateChanged="@OnStateChanged" DisplayText="Not selected" ShowLabel="true"></Checkbox>
        </div>
        <div class="col-12 col-sm-4">
            <Checkbox TValue="string" State="CheckboxState.Indeterminate" OnStateChanged="@OnStateChanged" DisplayText="Indeterminate" ShowLabel="true"></Checkbox>
        </div>
    </div>
    <BlockLogger @ref="Trace" class="mt-3" />
</DemoBlock>

<DemoBlock Title="Disable the check box" Introduction="Check box is not available, and the <code>IsDisabled</code> is set by whether the component is available" Name="Disabled">
    <div class="row g-3 form-inline">
        <div class="col-12 col-sm-4">
            <Checkbox TValue="string" State="CheckboxState.Checked" IsDisabled="true" DisplayText="Selected" ShowLabel="true"></Checkbox>
        </div>
        <div class="col-12 col-sm-4">
            <Checkbox TValue="string" State="CheckboxState.UnChecked" IsDisabled="true" DisplayText="Not selected" ShowLabel="true"></Checkbox>
        </div>
    </div>
</DemoBlock>

<DemoBlock Title="Color" Introduction="Change the component background color by setting the <code>Color</code> property" Name="ShowLabel">
    <div class="row g-3 form-inline">
        <div class="col-12 col-md-4">
            <Checkbox TValue="string" State="CheckboxState.Checked" DisplayText="Selected" ShowLabel="true" Color="@Color.Primary"></Checkbox>
        </div>
        <div class="col-12 col-md-4">
            <Checkbox TValue="string" State="CheckboxState.Checked" DisplayText="Selected" ShowLabel="true" Color="@Color.Success"></Checkbox>
        </div>
        <div class="col-12 col-md-4">
            <Checkbox TValue="string" State="CheckboxState.Checked" DisplayText="Selected" ShowLabel="true" Color="@Color.Danger"></Checkbox>
        </div>
        <div class="col-12 col-md-4">
            <Checkbox TValue="string" State="CheckboxState.Checked" DisplayText="Selected" ShowLabel="true" Color="@Color.Info"></Checkbox>
        </div>
        <div class="col-12 col-md-4">
            <Checkbox TValue="string" State="CheckboxState.Checked" DisplayText="Selected" ShowLabel="true" Color="@Color.Warning"></Checkbox>
        </div>
        <div class="col-12 col-md-4">
            <Checkbox TValue="string" State="CheckboxState.Checked" DisplayText="Selected" ShowLabel="true" Color="@Color.Dark"></Checkbox>
        </div>
    </div>
</DemoBlock>

<DemoBlock Title="Size" Introduction="Change the component size by setting the <code>Size</code> property" Name="DisplayText">
    <div class="row g-3 form-inline">
        <div class="col-12 col-md-3">
            <Checkbox TValue="string" State="CheckboxState.Checked" DisplayText="Default" ShowLabel="true"></Checkbox>
        </div>
        <div class="col-12 col-md-3">
            <Checkbox TValue="string" State="CheckboxState.Checked" DisplayText="Small" ShowLabel="true" Size="Size.Small"></Checkbox>
        </div>
        <div class="col-12 col-md-3">
            <Checkbox TValue="string" State="CheckboxState.Checked" DisplayText="Medium" ShowLabel="true" Size="Size.Medium"></Checkbox>
        </div>
        <div class="col-12 col-md-3">
            <Checkbox TValue="string" State="CheckboxState.Checked" DisplayText="Large" ShowLabel="true" Size="Size.Large"></Checkbox>
        </div>
        <div class="col-12 col-md-3">
            <Checkbox TValue="string" State="CheckboxState.Checked" DisplayText="ExtraLarge" ShowLabel="true" Size="Size.ExtraLarge"></Checkbox>
        </div>
        <div class="col-12 col-md-3">
            <Checkbox TValue="string" State="CheckboxState.Checked" DisplayText="ExtraExtraLarge" ShowLabel="true" Size="Size.ExtraExtraLarge"></Checkbox>
        </div>
    </div>
</DemoBlock>

<DemoBlock Title="Label text" Introduction="The check box displays text, and the component status flips when you tap display text, using the <code>DisplayText</code> settings component to display text" Name="ShowAfterLabel">
    <p>Set <code>DisplayText</code> property, or display text messages through bidirectional binding</p>
    <div class="row g-3 form-inline">
        <div class="col-12 col-md-3">
            <Checkbox TValue="string" State="CheckboxState.Checked" DisplayText="Default" ShowAfterLabel="true"></Checkbox>
        </div>
        <div class="col-12 col-md-3">
            <Checkbox TValue="string" State="CheckboxState.Checked" DisplayText="Small" ShowAfterLabel="true" Size="Size.Small"></Checkbox>
        </div>
        <div class="col-12 col-md-3">
            <Checkbox TValue="string" State="CheckboxState.Checked" DisplayText="Medium" ShowAfterLabel="true" Size="Size.Medium"></Checkbox>
        </div>
        <div class="col-12 col-md-3">
            <Checkbox TValue="string" State="CheckboxState.Checked" DisplayText="Large" ShowAfterLabel="true" Size="Size.Large"></Checkbox>
        </div>
        <div class="col-12 col-md-3">
            <Checkbox TValue="string" State="CheckboxState.Checked" DisplayText="ExtraLarge" ShowAfterLabel="true" Size="Size.ExtraLarge"></Checkbox>
        </div>
        <div class="col-12 col-md-3">
            <Checkbox TValue="string" State="CheckboxState.Checked" DisplayText="ExtraExtraLarge" ShowAfterLabel="true" Size="Size.ExtraExtraLarge"></Checkbox>
        </div>
    </div>
</DemoBlock>

<DemoBlock Title="Two-way binding boolean" Introduction="Binding variables within a component, data automatically synchronized, binding data types <code>boolean</code> type when the value is automatically flipped" Name="OnStateChanged">
    <div class="row g-3 form-inline">
        <div class="col-12">
            <Checkbox DisplayText="Two-way binding" ShowLabel="true" @bind-Value="@BindValue" OnStateChanged="@OnItemChanged"></Checkbox>
        </div>
        <div class="col-12">
            <BootstrapInput @bind-Value="@BindValue" IsDisabled="true"></BootstrapInput>
        </div>
    </div>
    <BlockLogger @ref="BinderLog" class="mt-3" />
</DemoBlock>

<DemoBlock Title="Bind string data in both directions" Introduction="Binding variables within a component, data is automatically synchronized" Name="BindString">
    <div class="row g-3 form-inline">
        <div class="col-12">
            <Checkbox DisplayText="Two-way binding" ShowLabel="true" @bind-Value="@BindString" OnStateChanged="@OnItemChangedString"></Checkbox>
        </div>
        <div class="col-12">
            <BootstrapInput @bind-Value="@BindString"></BootstrapInput>
        </div>
    </div>
    <BlockLogger @ref="BinderLog" class="mt-3" />
</DemoBlock>

<DemoBlock Title="Used in forms" Introduction="When you use <code>Checkbox</code> in a form, the display label text is placed in front of the component" Name="ValidateForm">
    <p>The pre-label explicit rules are consistent with the <code>BootstrapInput</code> component <a href='inputs'>[portal]</a></p>
    <ValidateForm Model="@Model">
        <div class="row g-3 form-inline">
            <div class="col-12 col-sm-6">
                <Checkbox @bind-Value="@Model.BindValue" ShowLabel="true"></Checkbox>
            </div>
            <div class="col-12 col-sm-6">
                <Checkbox @bind-Value="@Model.BindValue1" ShowLabel="true" DisplayText="Handwritten labels"></Checkbox>
            </div>
        </div>
    </ValidateForm>
</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/

using System.ComponentModel;

namespace BootstrapBlazor.Shared.Samples;

/// <summary>
/// 
/// </summary>
public sealed partial class Checkboxs
{
    private class Foo
    {
        [DisplayName("标签文字1")]
        public bool BindValue { get; set; }

        [DisplayName("标签文字2")]
        public bool BindValue1 { get; set; }
    }

    private Foo Model { get; set; } = new Foo();

    /// <summary>
    /// 
    /// </summary>
    private BlockLogger? Trace { get; set; }

    /// <summary>
    /// 
    /// </summary>
    private BlockLogger? BinderLog { get; set; }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="state"></param>
    /// <param name="value"></param>
    private Task OnStateChanged(CheckboxState state, string value)
    {
        Trace?.Log($"Checkbox state changed State: {state}");
        return Task.CompletedTask;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="state"></param>
    /// <param name="value"></param>
    private Task OnItemChanged(CheckboxState state, bool value)
    {
        BinderLog?.Log($"CheckboxState: {state} - Bind Value: {value}");
        return Task.CompletedTask;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="state"></param>
    /// <param name="value"></param>
    private Task OnItemChangedString(CheckboxState state, string value)
    {
        BinderLog?.Log($"CheckboxState: {state} - Bind Value: {value}");
        return Task.CompletedTask;
    }

    /// <summary>
    /// 
    /// </summary>
    private string BindString { get; set; } = "我爱 Blazor";

    /// <summary>
    /// 
    /// </summary>
    private bool BindValue { get; set; }

    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    private IEnumerable<AttributeItem> GetAttributes()
    {
        return new AttributeItem[]
        {
                new AttributeItem() {
                    Name = "ShowLabel",
                    Description = Localizer["Att1"],
                    Type = "bool",
                    ValueList = "true|false",
                    DefaultValue = "false"
                },
                new AttributeItem() {
                    Name = "ShowAfterLabel",
                    Description = Localizer["Att2"],
                    Type = "bool",
                    ValueList = "true|false",
                    DefaultValue = "false"
                },
                new AttributeItem() {
                    Name = "DisplayText",
                    Description = Localizer["Att3"],
                    Type = "string",
                    ValueList = " — ",
                    DefaultValue = " — "
                },
                new AttributeItem(){
                    Name = "IsDisabled",
                    Description = Localizer["Att4"],
                    Type = "boolean",
                    ValueList = "true / false",
                    DefaultValue = "false"
                },
                new AttributeItem()
                {
                    Name = "State",
                    Description = Localizer["Att5"],
                    Type = "CheckboxState",
                    ValueList = "Mixed / Checked / UnChecked",
                    DefaultValue = "UnChecked"
                },
        };
    }

    /// <summary>
    /// 获得事件方法
    /// </summary>
    /// <returns></returns>
    private IEnumerable<EventItem> GetEvents() => new EventItem[]
    {
            new EventItem()
            {
                Name = "OnStateChanged",
                Description = Localizer["Event1"],
                Type ="Action<CheckboxState, TItem>"
            },
            new EventItem()
            {
                Name = "StateChanged",
                Description = Localizer["Event2"],
                Type ="EventCallback<CheckboxState>"
            }
    };
}

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