Skip to main content

DatePicker

Properties

PropertyTypeDescription
defaultValuestring, string[]Default value displayed when opened
showNowbooleanWeather to show now, when showTime i set
showTimetable, booleanProvider an additional time selection
showTodaybooleanWeather to show today button
rangePickerbooleanWhen true user can pick range of date
allowClearbooleanWeather to show clear button
autoFocusbooleanWeather for element to be focused when opened
borderedbooleanWeather the element has a border
changeOnBlurbooleanSee changeOnBlur
disabledbooleanWeather the element is disabled
modetime date month year decadeMode of picker panel
openbooleanOverwrite how to display the datepicker
pickerdate week month quarter yearType of pick
placeholderstringThe placeholder of date input
placementbottomLeft bottomRight topLeft topRightPlacement of the popover
nextIconstringIcon of next button
prevIconstringIcon of previous button
sizelarge middle smallSize of datepicker
statuserror warningValidation status
suffixIconstringSuffix icon, displayed after input
superNextIconstringIcon of super next icon
superPrevIconstringIUcon of super previous icon
popupStyletable, CSSPropertiesCSS Properties of the popup
formatstringForamt of the date
onChangefunction(date, dateString)Fired when selected date is changed
onOkfunction(date)Fired when next/ok button is pressed
onPanelChangefunction(value, mode)Fired when user want to select month, year, etc
valueundefinedValue
disabledTimeundefinedUnimplemented
allowEmptybooleanAllows the user to leave input empty
separatorundefinedUnimplemented
onCalendarChangefunction(dates, dateStrings, info)Fired when either starttime or endtime is picked
All properties are optional.
List of icons.
Ant Design Documentation.

Children

DatePicker does not support children.

Example

"Trigger change when blur. e.g. datetime picker no need click confirm button".

defaultValue

The default value of the DatePicker.

-- Default Format: DD-MM-YYYY
defaultValue = "DD-MM-YYY", -- Input has to match format.

defaultValue

When its a RangePicker:

defaultValue = {"DD-MM-YYYY", "DD-MM-YYYY"} -- {left side, right side}
rangePicker = true,

defaultValue

showNow

When showTime = true, a "Now" button will appear when this is also true.

image

showTime

Weather the user also has to pick time:

image

NOTE: Remember to set foramt to include time!: foramt = "DD-MM-YYYY HH:mm:ss"

showToday

Weather to display the "today" button:

image

rangePicker

When true the user can pick a start and a end date:

image

allowClear

Weather to display the clear button to clear users input.

image

autoFocus

When true the DatePicker element will be focused when shown to the user.

bordered

Weather the DatePicker has a border, here hows it looks without a border:

image

changeOnBlur

"Trigger change when blur. e.g. datetime picker no need click confirm button"

disabled

Weather the DatePicker is disabled:

image

mode

Changes what the user has to pick, "date" is default.

time month year decade

open

Weather the popof the the DatePicker is displayed.

When set you'll have to handle how it opens and closes yourself.

picker

What the "final output" user has to choose.

Date: User has to pick full date DD-MM-YYYY

Week: week

Month: month

Quarter: quarter

Year: year

placeholder

Placeholder text if no input is selected.

placeholder

placement

Can be any of the following: bottomLeft bottomRight topLeft topRight.

Changes the placement of the popover.

nextIcon

Changes the icon of the next button.

nextIcon = "StepForwardOutlined",

nextIcon

prevIcon

Changes the icon of the previous button.

You can see an image from nextIcon.

size

Changes the size of the input.

Does not change anything in the popover.

status

Changes the outline color of the DatePickers input.

Error: error

Warning: warning

suffixIcon

Changes the icon displayed to the right side of the input.

suffixIcon = StepForwardOutlined

suffixIcon

superNextIcon / superPrevIcon

Changes the icon of the "super" next/previous icon.

supernext

popupStyle

CSS Styling for the container of the popup.

It's displayed behind the actual popover, but you can try and play around with it if you want.

format

format = "DD-MM-YYYY" Is the default format.

Meaning the input is DAY-MONTH-YEAR.

format = "MM-DD-YYYY" Means MONTH-DAY-YEAR.

format = "DD-MM-YYYY HH:mm:ss" is DAY-MOTH-YEAR HOUR:minute:second.

Your defaultValue has to match this!.

Also the output from the events is always "DD-MM-YYYY" as of now...

onChange

Fired when user changes input of the DatePicker.

onChange = function(_, _, date, dateString)
print("onChange: ", json.encode(date, {indent = true}), json.encode(dateString))
end

Example of output: example

When rangePicker = true:

onChange = function(_, _, date, dateString)
print("onChange: ", json.encode(date, {indent = true}), json.encode(dateString))
local first = date[0] -- Earliest date
local second = date[1] -- Latest date
local first2 = dateString[0]
local second2 = dateString[1]
end

onOk

Fired when user clicks the "ok" button.

onOk = function(_, _, date)
print("onOk: Clicked Ok: ", json.encode(date))
local date = date.dateString
local time = date.timeString
end

For rangePicker:

onOk = function(_, _, date)
print("onOk: Clicked Ok: ", json.encode(date, {indent = true}))
local first = date[0] -- Earliest date
local second = date[1] -- Latest date
local first2 = dateString[0]
local second2 = dateString[1]
end

onPanelChange

Fired when user goes in to change the year, month or decade.

onPanelChange = function(_, _, value, mode)
print("onPanelChange: ", json.encode(value), mode)
print("Panel Change To: ", mode)
end

mode is a array when rangePicker = true

allowEmpty

Weather user is allowed to not pick a date.

onCalendarChange

Requires rangePicker = true.

Fired when user changes either side of the picker, so either early date or late date...

disabledTime

Yet to be implemented correctly.