Skip to content

DatePicker

DatePicker, MonthPicker, RangePicker, and WeekPicker components are all generated through datePicker. Use props.type to generate different components.

Rules

Basic Example

js
const rule = {
    type: "DatePicker",
    field: "section_day",
    title: "Activity Date",
    value: ['2018-02-20 12:12:12', '2018-03-20 12:12:12'],
    props: {
        type: "datetimerange",
        placeholder:"Please select activity date",
    }
}

Props Configuration Examples

Date Selection

js
const rule = {
    type: "DatePicker",
    field: "date",
    title: "Activity Date",
    value: "",
    props: {
        type: "date",
        format: "YYYY-MM-DD",
        placeholder: "Please select date",
        allowClear: true,
    }
}

Date Time Selection

js
const rule = {
    type: "DatePicker",
    field: "datetime",
    title: "Activity Time",
    value: "",
    props: {
        type: "date",
        showTime: true,
        format: "YYYY-MM-DD HH:mm:ss",
        placeholder: "Please select date and time",
    }
}

Date Range Selection

js
const rule = {
    type: "DatePicker",
    field: "dateRange",
    title: "Activity Period",
    value: [],
    props: {
        type: "range",
        format: "YYYY-MM-DD",
        placeholder: ["Start Date", "End Date"],
    }
}

Limit Date Range

js
const rule = {
    type: "DatePicker",
    field: "date",
    title: "Appointment Date",
    value: "",
    props: {
        type: "date",
        format: "YYYY-MM-DD",
        disabledDate: (current) => {
            // Disable dates before today
            return current && current < dayjs().startOf('day');
        },
        placeholder: "Please select date",
    }
}

Events Examples

Listen to Date Changes

js
const rule = {
    type: "DatePicker",
    field: "date",
    title: "Activity Date",
    value: "",
    props: {
        type: "date",
        format: "YYYY-MM-DD",
        placeholder: "Please select date",
    },
    on: {
        change: (date, dateString) => {
            console.log('Date changed:', date, dateString);
        },
        ok: (value) => {
            console.log('Clicked OK:', value);
        },
    },
}

Reference: Ant-design-vue_DatePicker

value: String | Array

Props

The following APIs are shared by DatePicker, MonthPicker, RangePicker, WeekPicker.

ParameterDescriptionTypeDefault
typeComponent type'date', 'month', 'week', 'range''date'
allowClearWhether to show clear buttonbooleantrue
autofocusAuto focusbooleanfalse
borderedWhether to have borderbooleantrue
dateRenderCustom date cell contentv-slot:dateRender="{current, today}"-
disabledDisabledbooleanfalse
disabledDateDates that cannot be selected(currentDate: dayjs) => boolean-
formatSet date format, supports multiple format matching when array, display uses first one. Configuration reference dayjs, supports custom formatformatTypeYYYY-MM-DD
popupClassNameAdditional popup calendar classNamestring-
getPopupContainerDefine popup container, default creates new div on bodyfunction(trigger)-
inputReadOnlySet input box to read-only (avoid opening virtual keyboard on mobile devices)booleanfalse
localeInternationalization configurationobjectDefault config
modeState of date paneltime | date | year | decade-
nextIconCustom next iconslot-
openControl whether popup is expandedboolean-
pickerSet picker typedate | week | quarter | yeardate
placeholderInput box hint textstring | [string, string]-
placementPosition where selector pops upbottomLeft bottomRight topLeft topRightbottomLeft
popupStyleAdditional popup calendar styleCSSProperties{}
prevIconCustom previous iconslot-
presetsPreset time range quick selection{ label: slot, value: dayjs }[]-
sizeInput box size, large height is 40px, small is 24px, default is 32pxlarge | middle | -
statusSet validation status'error' | 'warning'-
suffixIconCustom suffix icon for selectorv-slot:suffixIcon-
superNextIconCustom << switch iconslot-
superPrevIconCustom >> switch iconslot-
valueFormatOptional, format of bound value, affects value, defaultValue, defaultPickerValue. If not specified, bound value is dayjs objectstring, Specific format-

Common Events

Event NameDescriptionCallback Parameters
openChangeCallback when popup calendar opens and closesfunction(status)
panelChangeCallback when date panel changesfunction(value, mode)-

DatePicker

ParameterDescriptionTypeDefault
defaultPickerValueDefault panel datedayjs-
disabledTimeTime that cannot be selectedfunction(date)-
formatDisplay date format, configuration reference dayjsformatTypeYYYY-MM-DD
renderExtraFooterAdd extra footer in panelv-slot:renderExtraFooter="mode"-
showNowWhen showTime is set, whether panel displays "Now" buttonboolean-
showTimeAdd time selection functionObject | booleanTimePicker Options
showTime.defaultValueSet default hour, minute, second when user selects date, exampledayjsdayjs()
showTodayWhether to display "Today" buttonbooleantrue

DatePicker Events

Event NameDescriptionCallback Parameters
changeCallback when time changesfunction(date: dayjs | string, dateString: string)
okCallback when clicking OK buttonfunction(date: dayjs | string)

DatePicker[picker=year]

ParameterDescriptionTypeDefault
formatDisplay date format, configuration reference dayjsformatTypeYYYY

DatePicker[picker=quarter]

ParameterDescriptionTypeDefault
formatDisplay date format, configuration reference dayjsformatTypeYYYY-\QQ

DatePicker[picker=month]

ParameterDescriptionTypeDefault
formatDisplay date format, configuration reference dayjsformatTypeYYYY-MM
monthCellRenderCustom month content render methodv-slot:monthCellRender="{current, locale}"-

DatePicker[picker=week]

ParameterDescriptionTypeDefault
formatDisplay date format, configuration reference dayjsformatTypeYYYY-wo

RangePicker

ParameterDescriptionTypeDefault
allowEmptyAllow start item to be partially empty[boolean, boolean][false, false]
dateRenderCustom date cell content.v-slot:dateRender="{current: dayjs, today: dayjs, info: { range: start |end }}"
defaultPickerValueDefault panel datedayjs[]-
disabledDisable start item[boolean, boolean]-
disabledTimeTime that cannot be selectedfunction(date: dayjs, partial: start | end)
formatDisplay date formatformatTypeYYYY-MM-DD HH:mm:ss
presetsPreset time range quick selection{ label: slot, value: dayjs[] }[]-
rangesPreset time range quick selection{ [range: string]: dayjs[] } | { [range: string]: () => dayjs[] }-
renderExtraFooterAdd extra footer in panelv-slot:renderExtraFooter="mode"-
separatorSet separatorstring | v-slot:separator<SwapRightOutlined />
showTimeAdd time selection functionObject|booleanTimePicker Options
showTime.defaultValueSet default hour, minute, second when user selects date, exampledayjs[][dayjs(), dayjs()]

RangePicker Events

Event NameDescriptionCallback Parameters
calendarChangeCallback when pending date changesfunction(dates: [dayjs, dayjs] | [string, string], dateStrings: [string, string], info: { range:start|end })
changeCallback when date range changesfunction(dates: [dayjs, dayjs] | [string, string], dateStrings: [string, string])
okCallback when clicking OK buttonfunction(dates: [dayjs, dayjs] | [string, string])

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