Skip to content

Cascader Multi-level Linkage ​

Rules ​

Basic Example ​

js
const rule = {
    type:"cascader",
    title:"Location",
    field:"address",
    value:['Shaanxi Province','Xi\'an City','Xincheng District'],
    props:{
        options:[{
            value: 'beijing',
            label: 'Beijing',
            children: [
                {
                    value: 'gugong',
                    label: 'Forbidden City'
                },
                {
                    value: 'tiantan',
                    label: 'Temple of Heaven'
                },
                {
                    value: 'wangfujing',
                    label: 'Wangfujing'
                }
            ]
        }, {
            value: 'jiangsu',
            label: 'Jiangsu',
            children: [
                {
                    value: 'nanjing',
                    label: 'Nanjing',
                    children: [
                        {
                            value: 'fuzimiao',
                            label: 'Confucius Temple',
                        }
                    ]
                },
                {
                    value: 'suzhou',
                    label: 'Suzhou',
                    children: [
                        {
                            value: 'zhuozhengyuan',
                            label: 'Humble Administrator\'s Garden',
                        },
                        {
                            value: 'shizilin',
                            label: 'Lion Grove Garden',
                        }
                    ]
                }
            ]
        }]
    }
}

Props Configuration Examples ​

Searchable ​

js
const rule = {
    type:"cascader",
    title:"Location",
    field:"address",
    props:{
        options:[{
            value: 'beijing',
            label: 'Beijing',
            children: [
                { value: 'gugong', label: 'Forbidden City' },
                { value: 'tiantan', label: 'Temple of Heaven' },
            ]
        }],
        filterable: true,
        placeholder: "Select or search area",
    }
}

Multiple Selection ​

js
const rule = {
    type:"cascader",
    title:"Product Category",
    field:"categories",
    props:{
        options:[{
            value: 'electronics',
            label: 'Electronics',
            children: [
                { value: 'phone', label: 'Phone' },
                { value: 'computer', label: 'Computer' },
            ]
        }],
        props: {
            multiple: true,
        },
        collapseTags: true,
        placeholder: "Select category",
    }
}

Select Any Level ​

js
const rule = {
    type:"cascader",
    title:"Product Category",
    field:"category",
    props:{
        options:[{
            value: 'electronics',
            label: 'Electronics',
            children: [
                { value: 'phone', label: 'Phone' },
                { value: 'computer', label: 'Computer' },
            ]
        }],
        props: {
            checkStrictly: true,
        },
        placeholder: "Select any level",
    }
}

Show Only Last Level ​

js
const rule = {
    type:"cascader",
    title:"Location",
    field:"address",
    props:{
        options:[{
            value: 'beijing',
            label: 'Beijing',
            children: [
                { value: 'gugong', label: 'Forbidden City' },
            ]
        }],
        showAllLevels: false,
        placeholder: "Select area",
    }
}

Dynamic Loading ​

js
const rule = {
    type:"cascader",
    title:"Product Category",
    field:"category",
    props:{
        props: {
            lazy: true,
            lazyLoad: (node, resolve) => {
                // Dynamically load child node data
                const { level } = node;
                if (level === 0) {
                    // Load first level data
                    resolve([
                        { value: '1', label: 'Electronics', leaf: false },
                        { value: '2', label: 'Clothing', leaf: false },
                    ]);
                } else if (level === 1) {
                    // Load second level data
                    resolve([
                        { value: '11', label: 'Phone', leaf: true },
                        { value: '12', label: 'Computer', leaf: true },
                    ]);
                }
            },
        },
        placeholder: "Select category",
    }
}

Events Examples ​

Listen to Selection Changes ​

js
const rule = {
    type:"cascader",
    title:"Location",
    field:"address",
    props:{
        options:[{
            value: 'beijing',
            label: 'Beijing',
            children: [
                { value: 'gugong', label: 'Forbidden City' },
            ]
        }],
        placeholder: "Select area",
        clearable: true,
    },
    on: {
        change: (value) => {
            console.log('Selection changed:', value);
        },
        'expand-change': (value) => {
            console.log('Expanded node changed:', value);
        },
        blur: (event) => {
            console.log('Lost focus:', event);
        },
        focus: (event) => {
            console.log('Gained focus:', event);
        },
        clear: () => {
            console.log('Cleared selection');
        },
        'visible-change': (visible) => {
            console.log('Dropdown visibility:', visible);
        },
    },
}

Update After Selection ​

js
const rule = [
    {
        type:"cascader",
        title:"Location",
        field:"address",
        props:{
            options:[{
                value: 'beijing',
                label: 'Beijing',
                children: [
                    { value: 'gugong', label: 'Forbidden City' },
                ]
            }],
            placeholder: "Select area",
        },
        inject: true,
        on: {
            change: ($inject, value) => {
                // Auto-fill zip code based on selected area
                const zipCodeMap = {
                    'beijing': '100000',
                    'gugong': '100006',
                };
                const lastValue = value[value.length - 1];
                if (zipCodeMap[lastValue]) {
                    $inject.api.setValue('zipCode', zipCodeMap[lastValue]);
                }
            },
        },
    },
    {
        type:"input",
        title:"Zip Code",
        field:"zipCode",
        props: {
            disabled: true,
        },
    },
]

Full configuration: Element_Cascader

value :Array

Props ​

Attribute NameDescriptionTypeDefault Value
optionsData source for options. value and label can be customized via CascaderProps.object—
propsConfiguration options. Please refer to the CascaderProps table below.object—
sizeSizeenum—
placeholderInput placeholder textstring—
disabledWhether to disableboolean—
clearableWhether to support clearing optionsboolean—
showAllLevelsWhether to display the full path of selected value in the input boxbooleantrue
collapseTagsWhether to collapse Tags in multiple selection modeboolean—
collapseTagsTooltipWhether to display all selected tags when hovering over collapsed tag text. This property requires collapse-tags to be set to truebooleanfalse
maxCollapseTagsTooltipHeightMaximum height of collapse tagsstring / number—
separatorCharacter used to separate optionsstring' / '
filterableWhether the option can be searchedboolean—
filterMethodCustom search logic. The first parameter is node, the second parameter is keyword, and the returned boolean indicates whether to keep the optionFunction—
debounceDebounce delay when typing search keywords, in millisecondsnumber300
beforeFilterHook function to call before the filter function is called. This function receives the value to be filtered as a parameter. If the return value of this function is false or a rejected Promise, the subsequent filtering logic will not be executed.Function—
popperClassCustom class name for popup contentstring''
teleportedWhether the popup layer uses teleportbooleantrue
tagTypeTag typeenuminfo
tagEffectTag effectenumlight
validateEventWhether to trigger form validation on inputbooleantrue
maxCollapseTagsMaximum number of Tags to display. Only takes effect when collapse-tags is set to true.number1
emptyValuesEmpty value configuration for the component Refer to config-providerarray—
valueOnClearValue when clearing options Refer to config-providerstring / number / boolean / Function—
persistentWhen the dropdown is not activated and persistent is set to false, the dropdown container will be removed.booleantrue
fallbackPlacementsAvailable positions for Tooltip. Please refer to popper.js documentationarray—
placementPosition where the dropdown appearsenumbottom-start

Events ​

Event NameDescriptionType
changeEvent triggered when the bound value changesFunction
expand-changeTriggered when expanded nodes changeFunction
blurTriggered when losing focusFunction
focusTriggered when gaining focusFunction
clearTriggered when user clicks clear button in clearable single selection modeFunction
visible-changeTriggered when dropdown appears/hidesFunction
remove-tagTriggered when Tag is removed in multiple selection modeFunction

Slots ​

Slot NameDescriptionScope
defaultCustom node content for options. Parameters are the current node's Node object and dataobject
emptyContent when no matching options—
prefixInput box header content—
suggestion-itemCustom suggestion item content when searchingobject

CascaderProps ​

AttributeDescriptionTypeDefault Value
expandTriggerExpansion method for secondary menuenumclick
multipleWhether multiple selection is allowedbooleanfalse
checkStrictlyWhether to strictly follow that parent and child nodes are not mutually associatedbooleanfalse
emitPathWhen selected node changes, whether to return an array composed of values from all levels of menus where the node is located. If set to false, only the value of the node is returnedbooleantrue
lazyWhether to dynamically load child nodes. Must be used together with lazyLoad methodbooleanfalse
lazyLoadMethod to load dynamic data. Only effective when lazy is trueFunction—
valueSpecify the value of the option as a property value of the option objectstringvalue
labelSpecify the label of the option as a property value of the option objectstringlabel
childrenSpecify the child options of the option as a property value of the option objectstringchildren
disabledSpecify the disabled state of the option as a property value of the option objectstringdisabled
leafSpecify the leaf node flag of the option as a property value of the option objectstringleaf
hoverThresholdSensitivity threshold for expanding menu on hovernumber500

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