DateField

Package: Libraries.Interface.Controls · Inherits from: Libraries.Interface.Events.FocusListener, Libraries.Interface.Events.CalendarListener, Libraries.Interface.Controls.Control, Libraries.Interface.Events.MouseMovementListener, Libraries.Interface.Item, Libraries.Interface.Item2D, Libraries.Language.Object, Libraries.Interface.Events.MouseListener, Libraries.Interface.Controls.TextField

A DateField is a text field for a date, with a button at its right edge that opens a Calendar below it. The date is shown in the field's format, "November 12, 2026" unless set otherwise with SetDateFormat, and typed dates are read in that format when the field loses the focus. Text that isn't a date in the format is left as typed, and the field says so to screen readers ("Not a date") until it is fixed. The calendar opens with the "Choose date" button, or with Alt and Down from the field, which also moves the focus into it. Choosing a day writes it in the field and closes the calendar; Escape, Alt and Up, or a click outside closes it without choosing. When the focus was in the calendar, it goes back to the field. Listeners (AddCalendarListener) are told when the user chooses a date, in the calendar or by typing. Screen readers hear the date in words as the field's description, such as "Thursday, November 12, 2026", whatever the format.

Example Code

use Libraries.Interface.Forms.Form
use Libraries.Interface.Forms.Page
use Libraries.Interface.Controls.DateField
use Libraries.System.CalendarDate

Form form
Page page = form:GetMainPage()

page:AddLabel("Due date")
DateField due
due:SetName("Due date")
CalendarDate date
date:SetDate(2026, 11, 20)
due:SetDate(date)
page:Add(due)

form:Display()

Actions

AddCalendarListener(Libraries.Interface.Events.CalendarListener listener)

This action adds a listener, told when the user chooses a date: in the calendar, or by typing one and leaving the field. When the user empties the field, the event's new date is undefined.

Parameters

Example

use Libraries.Interface.Controls.DateField
use Libraries.Interface.Events.CalendarListener

DateField field
CalendarListener listener
field:AddCalendarListener(listener)

CalendarChanged(Libraries.Interface.Events.CalendarChangedEvent event)

This action is called when the user chooses a day in the field's calendar: the date is written in the field, the calendar closes, and the field's listeners are told.

Parameters

ClickedMouse(Libraries.Interface.Events.MouseEvent event)

This action is called for a click on the field. It does what a text field does, placing the caret, and also opens the calendar, or closes it if it is open. A click on the calendar button is the button's own, which does the same.

Parameters

CloseCalendar()

This action closes the calendar without choosing a day, as Escape does. If the focus was in the calendar, it goes back to the field.

Example

use Libraries.Interface.Controls.DateField

DateField field
field:OpenCalendar()
field:CloseCalendar()

CloseCalendarForClick(number x, number y)

This action closes the calendar because of a click outside it, and remembers where the click was, so that if the same click reaches the field or its button next, it doesn't open the calendar again. The calendar's click listener calls it, so most users won't need to.

Parameters

  • x number: The click's x position.
  • y number: The click's y position.

Example

use Libraries.Interface.Controls.DateField

DateField field
field:CloseCalendarForClick(10, 10)

GainedFocus(Libraries.Interface.Events.FocusEvent event)

This action is called when the field gets the focus. It does what a text field does. (A text field gets this action from two parents, so a subclass has to name the one it means.)

Parameters

GetCalendar()

This action returns the calendar the field opens, so a program can set its range or first day of the week.

Returns

Libraries.Interface.Controls.Calendar: The calendar.

Example

use Libraries.Interface.Controls.DateField
use Libraries.Interface.Controls.Calendar
use Libraries.System.CalendarDate

DateField field
CalendarDate today
today:SetToToday()
Calendar calendar = field:GetCalendar()
calendar:SetMinimumDate(today)

GetCalendarButton()

This action returns the "Choose date" button at the field's right edge.

Returns

Libraries.Interface.Controls.Button: The button.

Example

use Libraries.Interface.Controls.DateField
use Libraries.Interface.Controls.Button

DateField field
Button button = field:GetCalendarButton()

GetDate()

This action returns the date in the field, read from its text in the field's format, or undefined while the text is empty or isn't a date in the format.

Returns

Libraries.System.CalendarDate: The date, or undefined.

Example

use Libraries.Interface.Controls.DateField
use Libraries.System.CalendarDate

DateField field
CalendarDate date = field:GetDate()

GetDateFormat()

This action returns the format the date is shown and read in.

Returns

Libraries.System.DateFormat: The format.

Example

use Libraries.Interface.Controls.DateField
use Libraries.System.DateFormat

DateField field
DateFormat format = field:GetDateFormat()

IsCalendarOpen()

This action returns whether the calendar is open.

Returns

boolean: True if the calendar is showing.

Example

use Libraries.Interface.Controls.DateField

DateField field
boolean open = field:IsCalendarOpen()

IsClosingClick(number x, number y)

This action returns whether a click is the one that just closed the calendar from outside it, and forgets that click, so it is only recognized once.

Parameters

  • x number: The click's x position.
  • y number: The click's y position.

Returns

boolean: true if this click closed the calendar.

Example

use Libraries.Interface.Controls.DateField

DateField field
boolean closing = field:IsClosingClick(10, 10)

IsDateValid()

This action returns whether the field's text is a date in its format, or empty. It is false after the user typed text that isn't a date and left the field.

Returns

boolean: True unless the text isn't a date.

Example

use Libraries.Interface.Controls.DateField

DateField field
boolean valid = field:IsDateValid()

IsOnScreenPoint(number x, number y)

This action returns whether a point on the screen is on the field, such as a click on its button.

Parameters

  • x number: The point's place across the screen.
  • y number: The point's place up the screen.

Returns

boolean: True if the point is on the field.

Example

use Libraries.Interface.Controls.DateField

DateField field
boolean inside = field:IsOnScreenPoint(10, 10)

LoadGraphics(Libraries.Interface.Layouts.LayoutProperties properties)

This action loads the field's graphics, then draws the small calendar on its button in the button's text color. The game engine calls it as needed, so most users won't need to call it directly.

Parameters

LostFocus(Libraries.Interface.Events.FocusEvent event)

This action is called when the field loses the focus: the typed text is read as a date in the field's format.

Parameters

OpenCalendar(boolean moveFocus)

This action opens the calendar below the field, or above it if there isn't room below, showing the field's date, or today's month when the field has none. The focus moves into the calendar if asked, as it does from the keyboard; a click on the button leaves it where it is.

Parameters

  • moveFocus boolean: True to move the focus into the calendar.

Example

use Libraries.Interface.Controls.DateField

DateField field
field:OpenCalendar(false)

OpenCalendar()

This action opens the calendar below the field, showing the field's date, or today's month when the field has none, and moves the focus into it, as Alt and Down do.

Example

use Libraries.Interface.Controls.DateField

DateField field
field:OpenCalendar()

RemoveCalendarListener(Libraries.Interface.Events.CalendarListener listener)

This action removes a listener.

Parameters

Example

use Libraries.Interface.Controls.DateField
use Libraries.Interface.Events.CalendarListener

DateField field
CalendarListener listener
field:AddCalendarListener(listener)
field:RemoveCalendarListener(listener)

SetDate(Libraries.System.CalendarDate newDate)

This action sets the date the field shows, as a program does: the text is the date in the field's format, and listeners aren't told. With undefined, the field is emptied.

Parameters

Example

use Libraries.Interface.Controls.DateField
use Libraries.System.CalendarDate

DateField field
CalendarDate date
date:SetDate(2026, 11, 12)
field:SetDate(date)

SetDateFormat(Libraries.System.DateFormat newFormat)

This action sets the format the date is shown and read in, such as one from DateFormat's GetNumericFormat ("11/12/2026"). A date in the field is written again in the new format. The format is "MMMM d, yyyy" ("November 12, 2026") unless set.

Parameters

Example

use Libraries.Interface.Controls.DateField
use Libraries.System.DateFormat

DateField field
DateFormat formats
field:SetDateFormat(formats:GetISOFormat())

SetNextFocus(Libraries.Interface.Item item)

This action sets where the focus goes after the field. Tab goes from the text to the "Choose date" button, then to the item given.

Parameters

Example

use Libraries.Interface.Controls.DateField
use Libraries.Interface.Controls.Button

DateField field
Button done
field:SetNextFocus(done)

TakeIgnoreNextToggle()

This action returns whether the button's activation should be ignored because the press that started it closed the calendar: a click outside the calendar closed it within the last half second. It forgets that click either way, so only the activation right after it is ignored. The button's behavior calls it, so most users won't need to.

Returns

boolean: true if the button's activation should do nothing.

Example

use Libraries.Interface.Controls.DateField

DateField field
boolean skip = field:TakeIgnoreNextToggle()

Inherited Actions

258 actions from Libraries.Interface.Controls.Control
72 actions from Libraries.Interface.Controls.TextField
1 action from Libraries.Interface.Events.MouseMovementListener
59 actions from Libraries.Interface.Item
201 actions from Libraries.Interface.Item2D
3 actions from Libraries.Language.Object