Skip to content

TimePicker

timePicker

Rule

Basic Example

js
const rule = {
    type: 'timePicker',
    title: 'Time Selection',
    field: 'time',
    value: '12:47',
    props: {
        title: 'Time Selection',
    }
}

Props Configuration Examples

Hour/Minute Selection

js
const rule = {
    type: 'timePicker',
    title: 'Event Time',
    field: 'time',
    value: '12:47',
    props: {
        title: 'Select Time',
        columnsType: ['hour', 'minute'],
    }
}

Hour/Minute/Second Selection

js
const rule = {
    type: 'timePicker',
    title: 'Precise Time',
    field: 'time',
    value: '12:47:58',
    props: {
        title: 'Select Time',
        columnsType: ['hour', 'minute', 'second']
    }
}

Hour Selection

js
const rule = {
    type: 'timePicker',
    title: 'Hour',
    field: 'hour',
    value: '12',
    props: {
        title: 'Select Hour',
        columnsType: ['hour']
    }
}

Minute Selection

js
const rule = {
    type: 'timePicker',
    title: 'Minute',
    field: 'minute',
    value: '58',
    props: {
        title: 'Select Minute',
        columnsType: ['minute']
    }
}

Limit Time Range

js
const rule = {
    type: 'timePicker',
    title: 'Working Time',
    field: 'workTime',
    value: '09:00',
    props: {
        title: 'Select Time',
        minTime: '09:00:00',
        maxTime: '18:00:00',
    }
}

Events Examples

Listen to Time Changes

js
const rule = {
    type: 'timePicker',
    title: 'Event Time',
    field: 'time',
    value: '12:47',
    props: {
        title: 'Select Time',
    },
    on: {
        confirm: (result) => {
            console.log('Confirmed selection:', result);
        },
        cancel: () => {
            console.log('Cancelled selection');
        },
        change: (result) => {
            console.log('Time changed:', result);
        },
    },
}

Complete configuration items:Vant_TimePicker

value :String

Props

ParameterDescriptionTypeDefault Value
disabledWhether to disablebooleanfalse
columns-typeOption types, array composed of hour, minute, and secondstring[]['hour', 'minute']
min-hourMinimum selectable hournumber | string0
max-hourMaximum selectable hournumber | string23
min-minuteMinimum selectable minutenumber | string0
max-minuteMaximum selectable minutenumber | string59
min-secondMinimum selectable secondnumber | string0
max-secondMaximum selectable secondnumber | string59
min-timeMinimum selectable time, format reference 07:40:00, when used, min-hour min-minute min-second will not take effectstring-
max-timeMaximum selectable time, format reference 10:20:00, when used, max-hour max-minute max-second will not take effectstring-
titleTop bar titlestring''
confirm-button-textConfirm button textstringConfirm
cancel-button-textCancel button textstringCancel
show-toolbarWhether to show top barbooleantrue
loadingWhether to show loading statebooleanfalse
readonlyWhether it is in readonly state, cannot switch options in readonly statebooleanfalse
filterOption filter function(type: string, options: PickerOption[], values: string[]) => PickerOption[]-
formatterOption formatter function(type: string, option: PickerOption) => PickerOption-
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 option changes{ selectedValues, selectedOptions, selectedIndexes, columnIndex }

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