Skip to content

Select

Rules

Basic Example

js
const rule = {
    type: "select",
    field: "cate_id",
    title: "Product Category",
    value: ["104","105"],
    options: [
        {"value": "104", "label": "Organic Vegetables", "disabled": false},
        {"value": "105", "label": "Fresh Fruits", "disabled": false},
     ],
    props: {
        multiple: true
    },
}

Props Configuration Examples

Single Selection Dropdown

js
const rule = {
    type: "select",
    field: "category",
    title: "Product Category",
    value: "104",
    options: [
        {"value": "104", "label": "Organic Vegetables"},
        {"value": "105", "label": "Fresh Fruits"},
        {"value": "106", "label": "Seafood"},
    ],
    props: {
        placeholder: "Please select product category",
        allowClear: true,
    },
}

Multiple Selection Dropdown

js
const rule = {
    type: "select",
    field: "tags",
    title: "Product Tags",
    value: ["104","105"],
    options: [
        {"value": "104", "label": "Hot Sale"},
        {"value": "105", "label": "New Product"},
        {"value": "106", "label": "Recommended"},
    ],
    props: {
        mode: "multiple",
        placeholder: "Please select tags",
        maxTagCount: 2,
    },
}

Searchable Dropdown

js
const rule = {
    type: "select",
    field: "product",
    title: "Product Name",
    options: [
        {"value": "1", "label": "iPhone 15 Pro"},
        {"value": "2", "label": "MacBook Pro"},
        {"value": "3", "label": "iPad Air"},
    ],
    props: {
        showSearch: true,
        placeholder: "Please enter or select product",
        allowClear: true,
        filterOption: (input, option) => {
            return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0;
        },
    },
}
js
const rule = {
    type: "select",
    field: "user",
    title: "Select User",
    options: [],
    props: {
        showSearch: true,
        placeholder: "Please enter username to search",
        allowClear: true,
        filterOption: false,
        onSearch: async (value) => {
            if (value) {
                // Call remote search API
                const res = await searchUsers(value);
                // Update options
                // Need to update options through other methods
            }
        },
    },
}

Events Examples

Listen to Selection Changes

js
const rule = {
    type: "select",
    field: "category",
    title: "Product Category",
    options: [
        {"value": "104", "label": "Organic Vegetables"},
        {"value": "105", "label": "Fresh Fruits"},
    ],
    props: {
        placeholder: "Please select category",
        allowClear: true,
    },
    on: {
        change: (value) => {
            console.log('Selection value changed:', value);
        },
        blur: () => {
            console.log('Lost focus');
        },
        focus: () => {
            console.log('Gained focus');
        },
    },
}

Linkage Update Other Fields After Selection

js
const rule = [
    {
        type: "select",
        field: "category",
        title: "Product Category",
        options: [
            {"value": "1", "label": "Electronics"},
            {"value": "2", "label": "Clothing & Accessories"},
        ],
        props: {
            placeholder: "Please select category",
        },
        inject: true,
        on: {
            change: ($inject, value) => {
                // Based on the selected category, load corresponding subcategories
                if (value === "1") {
                    $inject.api.updateRule('subcategory', {
                        options: [
                            {"value": "11", "label": "Phone"},
                            {"value": "12", "label": "Computer"},
                        ]
                    });
                } else if (value === "2") {
                    $inject.api.updateRule('subcategory', {
                        options: [
                            {"value": "21", "label": "Men's Clothing"},
                            {"value": "22", "label": "Women's Clothing"},
                        ]
                    });
                }
            },
        },
    },
    {
        type: "select",
        field: "subcategory",
        title: "Subcategory",
        options: [],
        props: {
            placeholder: "Please select category first",
            disabled: true,
        },
    },
]

Reference: Ant-design-vue_Select

value :Number | String | Array

Options

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

Props

ParameterDescriptionTypeDefault
allowClearSupport clearbooleanfalse
autoClearSearchValueWhether to clear search box after selecting item, only effective when mode is multiple or tags.booleantrue
autofocusDefault focusbooleanfalse
borderedWhether to have borderbooleantrue
clearIconCustom clear icon for multiple selectionVNode | slot-
defaultActiveFirstOptionWhether to highlight first option by defaultbooleantrue
defaultOpenWhether to expand dropdown menu by defaultboolean-
disabledWhether disabledbooleanfalse
popupClassNameclassName attribute of dropdown menustring-
dropdownMatchSelectWidthDropdown menu and selector have the same width. By default, min-width will be set, which will be ignored when the value is less than the selector width. false will disable virtual scrollingboolean | numbertrue
dropdownMenuStyleCustom style for dropdown menuobject-
dropdownRenderCustom dropdown content({menuNode: VNode, props}) => VNode | v-slot-
dropdownStylestyle attribute of dropdown menuobject-
fieldNamesCustom fields for node label, value, optionsobject{ label: label, value: value, options: options }
filterOptionWhether to filter based on input items. When it is a function, it will receive inputValue and option as parameters. When option meets the filter condition, it should return true, otherwise return false.boolean | function(inputValue, option)
filterSortSort function for filtered result items when searching, similar to compareFunction in Array.sort(optionA: Option, optionB: Option) => number-
firstActiveValueDefault highlighted optionstring | string[]-
getPopupContainerParent node for menu rendering. Default renders to body. If you encounter menu scroll positioning issues, try changing to scroll area and position relative to it.function(triggerNode)() => document.body
labelInValueWhether to wrap each option's label into value, will change Select's value type from string to {key: string, label: vNodes, originLabel: any} format, originLabel (3.1) maintains original type, if node is constructed through a-select-option children, this value is a function (i.e., default slot of a-select-option)booleanfalse
listHeightSet popup scroll heightnumber256
maxTagCountMaximum number of tags to displaynumber-
maxTagPlaceholderContent displayed when tags are hiddenslot | function(omittedValues)-
maxTagTextLengthMaximum displayed tag text lengthnumber-
menuItemSelectedIconCustom icon for currently selected itemVNode | slot-
modeSet Select mode to multiple selection or tags'multiple' | 'tags' | 'combobox'-
notFoundContentContent displayed when dropdown list is emptystring|slotNot Found
openWhether to expand dropdown menuboolean-
optionCustom node through option slotv-slot:option="{value, label, [disabled, key, title]}"-
optionFilterPropOption property to filter when searching, does not support childrenstringvalue
optionLabelPropProperty value of Option backfilled to selector, default is Option's child element. For example, when child element needs highlight effect, this value can be set to value.stringchildren |
optionsoptions data, if set then no need to manually construct selectOption nodesArray<{value, label, [disabled, key, title]}>[]
placeholderDefault text of selectorstring|slot-
placementPosition where selector pops upbottomLeft bottomRight topLeft topRightbottomLeft
removeIconCustom clear icon for multiple selectionVNode | slot-
searchValueControl search textstring-
showArrowWhether to show dropdown arrowbooleantrue for single selection, false for multiple selection
showSearchConfigure whether searchablebooleanfalse for single selection, true for multiple selection
sizeSelector size, options: large smallstringdefault
statusSet validation status'error' | 'warning'-
suffixIconCustom suffix icon for selectorVNode | slot-
tagRenderCustom tag content render, only effective when mode is multiple or tagsslot | (props) => any-
tokenSeparatorsSeparators for automatic word segmentation, only effective when mode="tags"string[]-
virtualSet false to disable virtual scrollingbooleantrue

Events

Event NameDescriptionCallback Parameters
blurCallback when losing focusfunction
changeCalled when option is selected, or input value changes (in combobox mode)function(value, option:Option | Array<Option>)
deselectCalled when deselected, parameter is selected item's value (or key), only effective in multiple or tags modefunction(value,option:Option)
dropdownVisibleChangeCallback when dropdown menu expandsfunction(open)
focusCallback when gaining focusfunction
inputKeyDownCallback when key is pressedfunction
mouseenterCallback when mouse entersfunction
mouseleaveCallback when mouse leavesfunction
popupScrollCallback when dropdown list scrollsfunction
searchCallback when text box value changesfunction(value: string)
selectCalled when selected, parameter is selected item's value (or key)function(value, option:Option)

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