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

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: (checkedValue) => {
            console.log('Selection value changed:', checkedValue);
        },
    },
}

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, checkedValue) => {
                // Based on the number of selected tags, automatically set product status
                if (checkedValue.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: Ant-design-vue_Checkbox

value :Array

Options

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

Props

ParameterDescriptionTypeDefault
disabledEntire group disabledbooleanfalse
namename attribute for all input[type="checkbox"] under CheckboxGroupstring-
optionsSpecify options, can customize label through slot="label" slot-scope="option"string[] | Array<{ label: string value: string disabled?: boolean, indeterminate?: boolean, onChange?: function }>[]

Events

Event NameDescriptionCallback Parameters
changeCallback function when changedFunction(checkedValue)

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