Skip to content

DatePicker

datePicker

Rule

Basic Example

js
const rule = {
    type: 'datePicker',
    title: 'Year/Month/Day Selection',
    field: 'date',
    value: '2024-06-12',
    props: {
        title: 'Year/Month/Day Selection',
    }
}

Props Configuration Examples

Year/Month/Day Selection

js
const rule = {
    type: 'datePicker',
    title: 'Event Date',
    field: 'date',
    value: '2024-06-12',
    props: {
        title: 'Select Date',
        columnsType: ['year', 'month', 'day'],
    }
}

Year/Month Selection

js
const rule = {
    type: 'datePicker',
    title: 'Year/Month Selection',
    field: 'month',
    value: '2024-06',
    props: {
        title: 'Select Year/Month',
        columnsType: ['year', 'month']
    }
}

Year Selection

js
const rule = {
    type: 'datePicker',
    title: 'Year',
    field: 'year',
    value: '2024',
    props: {
        title: 'Select Year',
        columnsType: ['year'],
    }
}

Month/Day Selection

js
const rule = {
    type: 'datePicker',
    title: 'Month/Day Selection',
    field: 'monthDay',
    value: '06-12',
    props: {
        title: 'Select Month/Day',
        columnsType: ['month', 'day'],
    }
}

Limit Date Range

js
const rule = {
    type: 'datePicker',
    title: 'Appointment Date',
    field: 'date',
    value: '',
    props: {
        title: 'Select Date',
        minDate: new Date(),
        maxDate: new Date(2025, 11, 31),
    }
}

Events Examples

Listen to Date Changes

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

Complete configuration items:Vant_DatePicker

value: String

Props

ParameterDescriptionTypeDefault Value
disabledWhether to disablebooleanfalse
columns-typeOption types, array composed of year, month, and daystring[]['year', 'month', 'day']
min-dateMinimum selectable time, accurate to dayDateTen years ago
max-dateMaximum selectable time, accurate to dayDateTen years later
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[]) => 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.