Skip to content

DatePicker ​

Rules ​

Basic Example ​

js
const rule = {
    type: "DatePicker",
    field: "section_day",
    title: "Activity Date",
    value: ['2018-02-20', '2021-02-15'],
    props: {
        type: "datetimerange",
        format: "YYYY-MM-dd HH:mm:ss",
        placeholder:"Select activity date",
    }
}

Props Configuration Examples ​

Date Selection ​

js
const rule = {
    type: "DatePicker",
    field: "date",
    title: "Activity Date",
    value: "2024-01-01",
    props: {
        type: "date",
        format: "YYYY-MM-DD",
        valueFormat: "YYYY-MM-DD",
        placeholder: "Select date",
        clearable: true,
    }
}

Date Time Selection ​

js
const rule = {
    type: "DatePicker",
    field: "datetime",
    title: "Activity Time",
    value: "2024-01-01 12:00:00",
    props: {
        type: "datetime",
        format: "YYYY-MM-DD HH:mm:ss",
        valueFormat: "YYYY-MM-DD HH:mm:ss",
        placeholder: "Select date and time",
    }
}

Date Range Selection ​

js
const rule = {
    type: "DatePicker",
    field: "dateRange",
    title: "Activity Period",
    value: ["2024-01-01", "2024-01-31"],
    props: {
        type: "daterange",
        format: "YYYY-MM-DD",
        valueFormat: "YYYY-MM-DD",
        startPlaceholder: "Start Date",
        endPlaceholder: "End Date",
    }
}

Limit Date Range ​

js
const rule = {
    type: "DatePicker",
    field: "date",
    title: "Appointment Date",
    value: "",
    props: {
        type: "date",
        format: "YYYY-MM-DD",
        disabledDate: (time) => {
            // Disable dates before today
            return time.getTime() < Date.now() - 8.64e7;
        },
        placeholder: "Select date",
    }
}

Shortcuts ​

js
const rule = {
    type: "DatePicker",
    field: "dateRange",
    title: "Query Date",
    value: [],
    props: {
        type: "daterange",
        format: "YYYY-MM-DD",
        shortcuts: [
            {
                text: 'Last Week',
                value: () => {
                    const end = new Date();
                    const start = new Date();
                    start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                    return [start, end];
                },
            },
            {
                text: 'Last Month',
                value: () => {
                    const end = new Date();
                    const start = new Date();
                    start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                    return [start, end];
                },
            },
        ],
    }
}

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: "Select date",
    },
    on: {
        change: (value) => {
            console.log('Date changed:', value);
        },
        blur: (event) => {
            console.log('Lost focus:', event);
        },
        focus: (event) => {
            console.log('Gained focus:', event);
        },
        clear: () => {
            console.log('Date cleared');
        },
        'visible-change': (visible) => {
            console.log('Dropdown visibility:', visible);
        },
    },
}

Complete configuration items: Element_DatePicker,Element_DateTimePicker

value: String | Array

DatePicker ​

Props ​

Property NameDescriptionTypeDefault
readonlyReadonlybooleanfalse
disabledDisabledbooleanfalse
sizeInput sizeenum—
editableText box can be inputbooleantrue
clearableWhether to show clear buttonbooleantrue
placeholderPlaceholder content for non-range selectionstring''
startPlaceholderPlaceholder content for start date in range selectionstring—
endPlaceholderPlaceholder content for end date in range selectionstring—
typeDisplay typeenumdate
formatFormat displayed in input boxSee date formatsYYYY-MM-DD
popperClassClass name of DatePicker dropdownstring—
popperOptionsCustom popper options, see popper.js for moreobject{}
rangeSeparatorSeparator when selecting rangestring'-'
defaultValueOptional, default time displayed when picker opensobject—
defaultTimeSpecific time of day used for selected date in range selectionobject—
valueFormatOptional, format of bound value. If not specified, bound value is Date objectSee date formats—
idEquivalent to native input id attributestring / object—
nameEquivalent to native input name attributestring / object''
unlinkPanelsUnlink two date panels in range pickerbooleanfalse
prefixIconCustom prefix icon. If type value is TimeLikeType, then it's Clock, otherwise it's Calendarstring / object''
clearIconCustom clear iconstring / objectCircleClose
validateEventWhether to trigger form validationbooleantrue
disabledDateFunction to determine if date is disabled, accepts a Date object as parameter. Should return a Boolean value.Function—
shortcutsSet shortcut options, need to pass array objectobject[]
cellClassNameSet custom class nameFunction—
teleportedWhether to insert date-picker dropdown list into body elementbooleantrue
emptyValuesComponent empty value configuration refer to config-providerarray—
valueOnClearValue when clearing options refer to config-providerstring / number / boolean / Function—
fallbackPlacementsAvailable positions for Tooltip, see popper.js documentationarrary—
placementPosition where dropdown appearsPlacementbottom

Events ​

Event NameDescriptionType
changeTriggered when user confirms selected valueFunction
blurTriggered when component Input loses focusFunction
focusTriggered when component Input gains focusFunction
clearTriggered when user clicks clear button in clearable modeFunction
calendar-changeTriggered when calendar selected date changesFunction
panel-changeTriggered when date panel changesFunction
visible-changeTriggered when DatePicker dropdown appears/disappearsFunction

Slots ​

NameDescription
defaultCustom cell content
range-separatorCustom range separator content
prev-monthPrevious month icon
next-monthNext month icon
prev-yearPrevious year icon
next-yearNext year icon

DateTimePicker (props.type:'datetime') ​

Props ​

Property NameDescriptionTypeDefault Value
readonlyReadonlybooleanfalse
disabledDisabledbooleanfalse
editableText box can be inputbooleantrue
clearableWhether to show clear buttonbooleantrue
sizeInput sizeenumdefault
placeholderPlaceholder content for non-range selectionstring—
startPlaceholderPlaceholder content for start date in range selectionstring—
endElaceholderPlaceholder content for end date in range selectionstring—
arrowControlWhether to use arrows for time selectionbooleanfalse
typeDisplay typeenumdate
formatFormat displayed in input boxstring see date formatsYYYY-MM-DD HH:mm:ss
popperClassClass name of DateTimePicker dropdownstring—
rangeSeparatorSeparator when selecting rangestring'-'
defaultValueOptional, default time displayed when picker opensobject—
defaultTimeDefault time value after selecting date. If not specified, default time value is 00:00:00object—
valueFormatOptional, format of bound value. If not specified, bound value is Date objectstring see date formats—
dateFormatOptional, date format displayed in time picker dropdown liststring see date formats—
timeFormatOptional, time format displayed in time picker dropdown liststring see date formats—
idEquivalent to native input id attributestring / object—
nameEquivalent to native input name attributestring—
unlinkPanelsUnlink two date panels in range pickerbooleanfalse
prefixIconCustom prefix icon componentstring / ComponentDate
clearIconCustom clear iconstring / ComponentCircleClose
shortcutsSet shortcut options, need to pass array objectobject—
disabledDateFunction to determine if date is disabled, accepts a Date object as parameter. Should return a Boolean value.Function—
cellClassNameSet custom class nameFunction—
teleportedWhether to insert datetime-picker dropdown list into body elementbooleantrue
emptyValuesComponent empty value configuration refer to config-providerarray—
valueOnClearValue when clearing options refer to config-providerstring / number / boolean / Function—
showNowWhether to show now buttonbooleantrue

Events ​

Event NameDescriptionCallback Parameters
changeTriggered when user confirms selected valuevalue
blurTriggered when component Input loses focus(e: FocusEvent)
focusTriggered when component Input gains focus(e: FocusEvent)
clearTriggered when user clicks clear button in clearable modeFunction
calendar-changeIf user hasn't selected a date, default to display current month. Callback executed after selecting calendar date, only effective for datetimerange[Date, Date]
visible-changeTriggered when DateTimePicker dropdown appears/disappearstrue when appears, false when hidden

Slots ​

Slot NameDescription
defaultCustom cell content
range-separatorCustom range separator content
prev-monthPrevious month icon
next-monthNext month icon
prev-yearPrevious year icon
next-yearNext year icon

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