Skip to content

Checkbox

Rules

Basic Example

js
const rule = {
    type:"checkbox",
    title:"Label",
    field:"label",
    value:["1","2","3"],
    options:[
        {value:"1",label:"Easy to Use",disabled:true},
        {value:"2",label:"Convenient",disabled:false},
        {value:"3",label:"Practical",disabled:false},
        {value:"4",label:"Effective",disabled:false},
    ]
}

Props Configuration Examples

Button Style Checkbox

js
const rule = {
    type:"checkbox",
    title:"Product Tags",
    field:"tags",
    value:["1","2"],
    options:[
        {value:"1",label:"Hot Sale"},
        {value:"2",label:"New Product"},
        {value:"3",label:"Recommended"},
        {value:"4",label:"Limited Time"},
    ],
    props: {
        type: "button",
        size: "default",
    },
}

Limit Selection Count

js
const rule = {
    type:"checkbox",
    title:"Product Categories",
    field:"categories",
    value:["1"],
    options:[
        {value:"1",label:"Electronics"},
        {value:"2",label:"Clothing & Accessories"},
        {value:"3",label:"Home Goods"},
        {value:"4",label:"Food & Beverages"},
    ],
    props: {
        min: 1,
        max: 3,
    },
    validate:[
        { required: true, message: 'Select at least 1 category, up to 3', trigger: 'change' },
    ],
}

Disabled State

js
const rule = {
    type:"checkbox",
    title:"Permission Settings",
    field:"permissions",
    value:["1"],
    options:[
        {value:"1",label:"View",disabled:false},
        {value:"2",label:"Edit",disabled:true},
        {value:"3",label:"Delete",disabled:true},
    ],
    props: {
        disabled: false,
    },
}

Events Examples

Listen to Selection Changes

js
const rule = {
    type:"checkbox",
    title:"Product Tags",
    field:"tags",
    value:["1"],
    options:[
        {value:"1",label:"Hot Sale"},
        {value:"2",label:"New Product"},
        {value:"3",label:"Recommended"},
    ],
    on: {
        change: (value) => {
            console.log('Selection value changed:', value);
        },
    },
}

Linkage Update After Selection

js
const rule = [
    {
        type:"checkbox",
        title:"Product Tags",
        field:"tags",
        value:[],
        options:[
            {value:"1",label:"Hot Sale"},
            {value:"2",label:"New Product"},
            {value:"3",label:"Recommended"},
        ],
        inject: true,
        on: {
            change: ($inject, value) => {
                // Automatically set product status based on number of selected tags
                if (value.length >= 2) {
                    $inject.api.setValue('status', 'active');
                } else {
                    $inject.api.setValue('status', 'inactive');
                }
            },
        },
    },
    {
        type:"input",
        title:"Product Status",
        field:"status",
        props: {
            disabled: true,
        },
    },
]

Complete configuration items: Element_Checkbox

value :Array

Options

Field NameDescriptionField TypeRequiredDefault Value
valueParameter valueString,Numbertrue-
labelField aliasStringtrue-
disabledSet to disabled stateBooleanfalsefalse

Props

Property NameDescriptionTypeDefault Value
sizeCheckbox group sizeenum
typeCheckbox type'button'| 'checkbox'-
disabledWhether disabledbooleanfalse
minMinimum number of checkboxes that can be checkednumber
maxMaximum number of checkboxes that can be checkednumber
ariaLabelNative aria-label attributestring
textColorFont color when button is activestring#ffffff
fillBorder and background color when button is activestring#409eff
tagCheckbox group element tagstringdiv
validateEventWhether to trigger form validationbooleantrue

Events

Event NameDescriptionType
changeEvent triggered when bound value changesFunction

FormCreate is an open-source project released under the MIT License. Free for personal and commercial use.