A DatePicker in mobile UIs enables users to select dates using a visual calendar interface.
### options Props
format: String. Moment date format. Default is "YYYY-MM-DD"
portrait: Boolean. Display the date picker in portrait view. Default is detective in the size of the screen.
future: String. The future value until which the dialog will render dates in the following format "YYYY-MM-DD"
past: String. The past until which the dialog will render dates in the following format "YYYY-MM-DD".
### Date formatting
DatePicker dialog uses moment js library, see https://momentjs.com/docs/ for more date formatting values.
Sample values are:
* "MMMM Do YYYY" : December 13th 2023
"dddd" : Wednesday
"MMM Do YY": Dec 13th 23
Examples
Example - Default
class Main extends App
{
onStart()
{
this.main = ui.addLayout("main", "Linear", "VCenter,FillXY")
this.btn = ui.addButton(this.main, "Show Date Picker")
this.btn.setOnTouch( this.showDatePicker )
}
showDatePicker()
{
ui.showDatePicker( this.onSelect )
}
onSelect( value )
{
ui.showPopup( value )
}
}
class Main extends App
onStart()
this.main = ui.addLayout("main", "Linear", "VCenter,FillXY")
this.btn = ui.addButton(this.main, "Show Date Picker")
this.btn.setOnTouch( this.showDatePicker )
showDatePicker()
ui.showDatePicker( this.onSelect )
onSelect( value )
ui.showPopup( value )
Example - With initial value and options object
class Main extends App
{
onStart()
{
this.main = ui.addLayout("main", "Linear", "VCenter,FillXY")
this.btn = ui.addButton(this.main, "Show Date Picker")
this.btn.setOnTouch( this.showDatePicker )
}
showDatePicker()
{
var opt = {
portrait: true,
format: "YYYY Do MMM"
}
ui.showDatePicker("2022-12-25", opt, this.onSelect);
}
onSelect( value )
{
ui.showPopup( value );
}
}
class Main extends App
onStart()
this.main = ui.addLayout("main", "Linear", "VCenter,FillXY")
this.btn = ui.addButton(this.main, "Show Date Picker")
this.btn.setOnTouch( this.showDatePicker )
showDatePicker()
opt =
portrait: true,
format: "YYYY Do MMM"
ui.showDatePicker("2022-12-25", opt, this.onSelect)
onSelect( value )
ui.showPopup( value )
Example - Dark mode with date limits
class Main extends App
{
onStart()
{
ui.setTheme( "dark" )
this.main = ui.addLayout("main", "Linear", "VCenter,FillXY")
this.btn = ui.addButton(this.main, "Show Date Picker")
this.btn.setOnTouch( this.showDatePicker )
}
showDatePicker()
{
var opt = {
past: "2023-12-05",
future: "2023-12-25"
}
ui.showDatePicker("2023-12-15", opt, this.onSelect)
}
onSelect( value )
{
ui.showPopup( value )
}
}
class Main extends App
onStart()
ui.setTheme( "dark" )
this.main = ui.addLayout("main", "Linear", "VCenter,FillXY")
this.btn = ui.addButton(this.main, "Show Date Picker")
this.btn.setOnTouch( this.showDatePicker )
showDatePicker()
opt =
past: "2023-12-05",
future: "2023-12-25"
ui.showDatePicker("2023-12-15", opt, this.onSelect)
onSelect( value )
ui.showPopup( value )