Skip to content

Radio

Rules

Basic Example

js
const rule = {
    type:"radio",
    title:"Free Shipping",
    field:"is_postage",
    value:"0",
    options:[
        {value:"0",label:"No Free Shipping",disabled:false},
        {value:"1",label:"Free Shipping",disabled:true},
    ],
}

Props Configuration Examples

Button Style Radio

js
const rule = {
    type:"radio",
    title:"Delivery Method",
    field:"delivery",
    value:"1",
    options:[
        {value:"1",label:"Express Delivery"},
        {value:"2",label:"Store Pickup"},
        {value:"3",label:"Same City Delivery"},
    ],
    props: {
        optionType: "button",
        buttonStyle: "solid",
    },
}

Different Sizes

js
const rule = {
    type:"radio",
    title:"Product Status",
    field:"status",
    value:"1",
    options:[
        {value:"1",label:"On Sale"},
        {value:"2",label:"Off Sale"},
        {value:"3",label:"Pending Review"},
    ],
    props: {
        optionType: "button",
        size: "small",
    },
}

Events Examples

Listen to Selection Changes

js
const rule = {
    type:"radio",
    title:"Delivery Method",
    field:"delivery",
    value:"1",
    options:[
        {value:"1",label:"Express Delivery"},
        {value:"2",label:"Store Pickup"},
        {value:"3",label:"Same City Delivery"},
    ],
    on: {
        change: (e) => {
            console.log('Selection value changed:', e.target.value);
        },
    },
}

Linkage Update After Selection

js
const rule = [
    {
        type:"radio",
        title:"Delivery Method",
        field:"delivery",
        value:"1",
        options:[
            {value:"1",label:"Express Delivery"},
            {value:"2",label:"Store Pickup"},
            {value:"3",label:"Same City Delivery"},
        ],
        inject: true,
        on: {
            change: ($inject, e) => {
                // Based on the delivery method, automatically set freight
                const freightMap = {
                    "1": 10,
                    "2": 0,
                    "3": 5,
                };
                $inject.api.setValue('freight', freightMap[e.target.value] || 0);
            },
        },
    },
    {
        type:"input-number",
        title:"Freight",
        field:"freight",
        props: {
            disabled: true,
        },
    },
]

Complete configuration items: Ant-design-vue_Radio

value :String | Number

Options

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

Props

ParameterDescriptionTypeDefault
buttonStyleStyle of RadioButton, currently has two styles: outline and solidoutline | solid
disabledDisable all child radio buttonsbooleanfalse
namename attribute for all input[type="radio"] under RadioGroupstring-
optionsSet child elements in configuration formstring[] | number[] | Array<{ label: string value: string disabled?: boolean }>-
optionTypeUsed to set Radio options typedefault | button3.0.0
sizeSize, only effective for button stylelarge | default | default

Events

Event NameDescriptionCallback Parameters
changeCallback function when option changesFunction(e:Event)

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