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 Select 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: "Select product category",
        clearable: true,
    },
}

Multiple Select 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: {
        multiple: true,
        collapseTags: true,
        collapseTagsTooltip: true,
        placeholder: "Select tags",
    },
}

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: {
        filterable: true,
        placeholder: "Enter or select product",
        clearable: true,
    },
}
js
const rule = {
    type: "select",
    field: "user",
    title: "Select User",
    props: {
        filterable: true,
        remote: true,
        remoteMethod: async (query) => {
            if (query) {
                // Call remote search API
                const res = await searchUsers(query);
                return res.data.map(item => ({
                    value: item.id,
                    label: item.name
                }));
            }
            return [];
        },
        placeholder: "Enter username to search",
        loading: false,
    },
}

Limit Multiple Selection Count

js
const rule = {
    type: "select",
    field: "categories",
    title: "Product Category",
    value: ["104"],
    options: [
        {"value": "104", "label": "Organic Vegetables"},
        {"value": "105", "label": "Fresh Fruits"},
        {"value": "106", "label": "Seafood"},
    ],
    props: {
        multiple: true,
        multipleLimit: 3,
        placeholder: "Select up to 3 categories",
    },
}

Events Examples

Listen to Changes and Focus Events

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

Linkage Update Other Fields

js
const rule = [
    {
        type: "select",
        field: "category",
        title: "Product Category",
        options: [
            {"value": "1", "label": "Electronics"},
            {"value": "2", "label": "Clothing & Accessories"},
        ],
        props: {
            placeholder: "Select category",
        },
        inject: true,
        on: {
            change: ($inject, value) => {
                // Load subcategories based on selected category
                if (value === "1") {
                    $inject.api.updateRule('subcategory', {
                        options: [
                            {"value": "11", "label": "Mobile Phones"},
                            {"value": "12", "label": "Computers"},
                        ]
                    });
                } 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: "Select category first",
            disabled: true,
        },
    },
]

Remove Tag in Multiple Selection Mode

js
const rule = {
    type: "select",
    field: "tags",
    title: "Product Tags",
    value: ["1", "2"],
    options: [
        {"value": "1", "label": "Hot Sale"},
        {"value": "2", "label": "New Product"},
        {"value": "3", "label": "Recommended"},
    ],
    props: {
        multiple: true,
        collapseTags: true,
    },
    on: {
        'remove-tag': (value) => {
            console.log('Tag removed:', value);
        },
    },
}

Slots Examples

Custom Empty Data Hint

js
const rule = {
    type: "select",
    field: "category",
    title: "Product Category",
    options: [],
    props: {
        filterable: true,
        placeholder: "Enter to search",
    },
    children: [
        {
            type: 'div',
            slot: 'empty',
            children: ['No data available, please try other keywords']
        }
    ]
}

Complete configuration items: Element_Select

value :Number | String | Array

Options

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

Props

Property NameDescriptionTypeDefault
multipleWhether multiple selectionbooleanfalse
disabledWhether disabledbooleanfalse
valueKeyKey name as unique identifier for value, required when binding value is object typestringvalue
sizeInput sizeenum
clearableWhether options can be clearedbooleanfalse
collapseTagsWhether to display selected values as text in multiple selection modebooleanfalse
collapseTagsTooltipWhether to display all selected tags when hovering over collapsed tag text. This property requires collapse-tags to be set to truebooleanfalse
multipleLimitWhen multiple is set to true, represents the maximum number of items users can select in multiple selection scenario, 0 means unlimitednumber0
nameNative name attribute of Select inputstring
effectTooltip theme, built-in dark / lightenum / stringlight
autocompleteNative autocomplete attribute of Select inputstringoff
placeholderPlaceholder, default is "Select"string
filterableWhether Select component is filterablebooleanfalse
allowCreateWhether to allow users to create new entries, only effective when filterable is set to truebooleanfalse
filterMethodCustom filter methodFunction
remoteWhether options are loaded remotely from serverbooleanfalse
remoteMethodCustom remote search methodFunction
remoteShowSuffixShow suffix icon for remote search methodbooleanfalse
loadingWhether data is being fetched from remotebooleanfalse
loadingTextText displayed when loading data from server, default is "Loading"string
noMatchTextText displayed when search condition has no match, can also use empty slot to set, default is "No matching data"string
noDataTextText displayed when there are no options, can also use empty slot to set custom content, default is "No data"string
popperClassCustom class name for selector dropdown menustring''
reserveKeywordWhen multiple and filterable are set to true, whether to keep current search keyword after selecting an optionbooleantrue
defaultFirstOptionWhether to select first matching item when pressing Enter in input box. Requires filterable or remote to be usedbooleanfalse
teleportedWhether to use teleport. If set to true, it will be appended to append-to locationbooleantrue
appendToWhich DOM element the dropdown is mounted toCSSSelector / HTMLElement
persistentWhen dropdown selector is not activated and persistent is set to false, selector will be removedbooleantrue
automaticDropdownFor non-searchable Select, auto-popup option menu when input gains focusbooleanfalse
clearIconCustom clear iconstring / objectCircleClose
fitInputWidthWhether dropdown width is the same as input boxbooleanfalse
suffixIconCustom suffix icon componentstring / objectArrowDown
tagTypeTag typeenuminfo
tagEffectTag effectenumlight
validateEventWhether to trigger form validationbooleantrue
offsetDropdown panel offsetnumber12
showArrowWhether dropdown menu content has arrowbooleantrue
placementPosition where dropdown appearsenumbottom-start
fallbackPlacementsAvailable positions for dropdown, please refer to popper.js documentationarray['bottom-start', 'top-start', 'right', 'left']
maxCollapseTagsMaximum number of Tags to display, only effective when collapse-tags is set to truenumber1
popperOptionspopper.js parametersobjectrefer to popper.js doc{}
ariaLabelEquivalent to native input aria-label attributestring
emptyValuesComponent empty value configuration refer to config-providerarray
valueOnClearValue when clearing options refer to config-providerstring / number / boolean / Function
tabindexInput tabindexstring / number

Events

Event NameDescriptionType
changeTriggered when selected value changesFunction
visible-changeTriggered when dropdown appears/hidesFunction
remove-tagTriggered when tag is removed in multiple selection modeFunction
clearTriggered when user clicks clear button in clearable single selection modeFunction
blurTriggered when input loses focusFunction
focusTriggered when input gains focusFunction
popup-scroll 2.9.4Triggered when dropdown scrollsFunction

Slots

Slot NameDescriptionChild Tags
defaultOption component listOption Group / Option
header 2.4.3Content at top of dropdown list
footer 2.4.3Content at bottom of dropdown list
prefixSelect component header content
emptyList when there are no options
tag 2.5.0Select component custom tag content
loading 2.5.2Select component custom loading content
label 2.7.4Select component custom label content

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