Skip to content

Select

select

Rule

Basic Example

js
const rule = {
    type: 'select',
    title: 'Dropdown Selection',
    field: 'select',
    value: 'Wednesday',
    props: {
        title: 'Appointment',
        options: [
            { text: 'Monday', value: 'Monday' },
            { text: 'Tuesday', value: 'Tuesday' },
            { text: 'Wednesday', value: 'Wednesday' },
            { text: 'Thursday', value: 'Thursday' },
            { text: 'Friday', value: 'Friday' },
        ],
        placeholder: 'Select',
    }
}

Props Configuration Examples

Single Selection Dropdown

js
const rule = {
    type: 'select',
    title: 'Product Category',
    field: 'category',
    value: '1',
    props: {
        title: 'Select Category',
        options: [
            { text: 'Electronics', value: '1' },
            { text: 'Clothing & Accessories', value: '2' },
            { text: 'Home Goods', value: '3' },
        ],
        placeholder: 'Please select category',
    }
}

Multi-Column Selection

js
const rule = {
    type: 'select',
    title: 'Province/City/District',
    field: 'address',
    value: [],
    props: {
        title: 'Select Address',
        options: [
            [
                { text: 'Zhejiang', value: 'zhejiang' },
                { text: 'Fujian', value: 'fujian' },
            ],
            [
                { text: 'Hangzhou', value: 'hangzhou' },
                { text: 'Wenzhou', value: 'wenzhou' },
            ],
            [
                { text: 'Xihu District', value: 'xihu' },
                { text: 'Yuhang District', value: 'yuhang' },
            ],
        ],
    }
}

Custom Button Text

js
const rule = {
    type: 'select',
    title: 'Appointment Time',
    field: 'time',
    value: '',
    props: {
        title: 'Select Time',
        confirmButtonText: 'Confirm',
        cancelButtonText: 'Cancel',
        options: [
            { text: '09:00', value: '09:00' },
            { text: '10:00', value: '10:00' },
            { text: '11:00', value: '11:00' },
        ],
    }
}

Events Examples

Handle Selection Changes

js
const rule = {
    type: 'select',
    title: 'Dropdown Selection',
    field: 'select',
    value: '',
    props: {
        title: 'Appointment',
        options: [
            { text: 'Monday', value: 'Monday' },
            { text: 'Tuesday', value: 'Tuesday' },
        ],
        placeholder: 'Select',
    },
    on: {
        confirm: (result) => {
            console.log('Confirmed selection:', result);
        },
        cancel: () => {
            console.log('Cancelled selection');
        },
        change: (result) => {
            console.log('Selection changed:', result);
        },
    },
}

Linkage Update After Selection

js
const rule = [
    {
        type: 'select',
        title: 'Product Category',
        field: 'category',
        value: '',
        props: {
            title: 'Select Category',
            options: [
                { text: 'Electronics', value: '1' },
                { text: 'Clothing & Accessories', value: '2' },
            ],
        },
        inject: true,
        on: {
            confirm: ($inject, result) => {
                // Load subcategories based on selection
                const value = result.selectedValues[0];
                if (value === '1') {
                    $inject.api.updateRule('subcategory', {
                        props: {
                            options: [
                                { text: 'Mobile Phone', value: '11' },
                                { text: 'Computer', value: '12' },
                            ]
                        }
                    });
                } else if (value === '2') {
                    $inject.api.updateRule('subcategory', {
                        props: {
                            options: [
                                { text: 'Men\'s Clothing', value: '21' },
                                { text: 'Women\'s Clothing', value: '22' },
                            ]
                        }
                    });
                }
            },
        },
    },
    {
        type: 'select',
        title: 'Subcategory',
        field: 'subcategory',
        props: {
            title: 'Select Subcategory',
            options: [],
            placeholder: 'Please select category first',
            disabled: true,
        },
    },
]

Complete configuration items:Vant_Picker

value :Number | String

Options

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

Props

ParameterDescriptionTypeDefault Value
disabledWhether to disable inputbooleanfalse
optionsArray of objects, configure data displayed in each columnPickerOption[] | PickerOption[][][]
columns-field-namesCustom fields in options structureobject{ text: 'text', value: 'value', children: 'children' }
titleTop bar titlestring-
confirm-button-textConfirm button text, set to empty string to hide buttonstringConfirm
cancel-button-textCancel button text, set to empty string to hide buttonstringCancel
toolbar-positionTop bar position, optional value is bottomstringtop
loadingWhether to show loading statebooleanfalse
readonlyWhether it is in readonly state, cannot switch options in readonly statebooleanfalse
show-toolbarWhether to show top barbooleantrue
allow-htmlWhether to allow rendering HTML in option contentbooleanfalse
option-heightOption height, supports px vw vh rem units, default pxnumber | string44
visible-option-numNumber of visible optionsnumber | string6
swipe-durationDuration of inertial scrolling when swiping quickly, unit msnumber | string1000

Events

Event NameDescriptionCallback Parameters
confirmTriggered when confirm button is clicked{ selectedValues, selectedOptions, selectedIndexes }
cancelTriggered when cancel button is clicked{ selectedValues, selectedOptions, selectedIndexes }
changeTriggered when selected option changes{ selectedValues, selectedOptions, selectedIndexes, columnIndex }
click-optionTriggered when option is clicked{ currentOption, selectedValues, selectedOptions, selectedIndexes, columnIndex }
scrollIntoTriggered when user scrolls an option to the middle selection area by clicking or dragging{ currentOption, columnIndex }

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