Skip to main content

Component | DateTime Input

info

Introduced in v0.22.0 of the SDK.

Render a datetime input box.

ui.dateTimeInput("date-input-key", { 
label: "When will the world end?",
onEnter: (value) => console.log(value)
})

Learn more about working with inputs.

API reference

Function signature

/**
* One of the following:
* - A JS Date object in UTC
* - A human readable object with year, month (1-12), day (1-31), hour (0-23), and minute (0-59)
* - `null` to ignore the parameter and use the default value
*/
type DateTimeInput =
| {
year: number;
month: number; // 1-12
day: number; // 1-31
hour: number; // 0-23
minute: number; // 0-59
}
| Date // Assumes UTC for the given date
| null

/**
* One of the following:
* - An object with human readable values for year, month (1-12), day (1-31), hour (0-23), minute (0-59),
* and a JS Date object with the selected datetime in UTC
* - `null` if no datetime was selected
*/
type DateTimeOutput =
| {
year: number;
month: number; // 1-12
day: number; // 1-31
hour: number; // 0-23
minute: number; // 0-59
jsDate: Date; // Selected datetime in UTC
}
| null // Passes `null` if no datetime was selected

ui.dateTimeInput(
id: string,
properties: Partial<{
label: string,
description: string,
required: boolean,
min: DateTimeInput,
max: DateTimeInput,
initialValue: DateTimeInput,
validate: (value: DateTimeOutput) => string | void,
onEnter: (value: DateTimeOutput) => void,
style: Style | null
}>
)

Parameters

id

required string
A unique identifier for the component. This is necessary so that Compose can properly pass user actions back to the component.

properties.label

optional string

The label to display above the datetime input. If not provided, the label will be inferred from the id.


properties.description

optional string

A description to display between the label and datetime input box.


properties.required

optional boolean

Validate that the datetime input is not empty before submitting the form it's part of or calling it's onEnter hook. Defaults to true.


properties.min optional DateTimeInput

The earliest datetime that can be selected. If not provided, there is no minimum datetime.

The parameter expects either a JS Date in UTC or a human readable object with year, month (1-12), day (1-31), hour (0-23), and minute (0-59).

type DateTimeInput = 
| {
year: number;
month: number; // 1-12
day: number; // 1-31
hour: number; // 0-23
minute: number; // 0-59
}
| Date // Assumes UTC for the given date
| null // Use default value (i.e. no minimum datetime)

properties.max optional DateTimeInput

The latest datetime that can be selected. If not provided, there is no maximum datetime.

The parameter expects either a JS Date in UTC or a human readable object with year, month (1-12), day (1-31), hour (0-23), and minute (0-59).

type DateTimeInput = 
| {
year: number;
month: number; // 1-12
day: number; // 1-31
hour: number; // 0-23
minute: number; // 0-59
}
| Date // Assumes UTC for the given date
| null // Use default value (i.e. no maximum datetime)

properties.initialValue optional DateTimeInput

The initial value of the datetime input. Defaults to null. You can also update the value of the datetime input at any time using the page.setInputs() method.

The parameter expects either a JS Date in UTC or a human readable object with year, month (1-12), day (1-31), hour (0-23), and minute (0-59).

type DateTimeInput = 
| {
year: number;
month: number; // 1-12
day: number; // 1-31
hour: number; // 0-23
minute: number; // 0-59
}
| Date // Assumes UTC for the given date
| null // Use default value (i.e. no initial value)

properties.validate optional (value: DateTimeOutput) => string | void

Validate the input value before submitting it. If the function returns a string, it will be displayed as an error message.

The validator will be passed an object with the following properties:

type DateTimeOutput = 
| {
year: number;
month: number; // 1-12
day: number; // 1-31
hour: number; // 0-23
minute: number; // 0-59
jsDate: Date; // Selected datetime in UTC
}
| null // Passes `null` if no datetime was selected

properties.onEnter optional (value: DateTimeOutput) => void

A callback function that is called when the user presses enter in the datetime input.

The callback will be passed an object with the following properties:

type DateTimeOutput = 
| {
year: number;
month: number; // 1-12
day: number; // 1-31
hour: number; // 0-23
minute: number; // 0-59
jsDate: Date; // Selected datetime in UTC
}
| null // Passes `null` if no datetime was selected

properties.style

optional Style

Directly style the underlying element using CSS. See the styling guide for more details on available style properties.