DatePicker
DatePicker create a datepicker and return its selected date.
API
func DatePicker(c *tgframe.Container, label string, conf ...*DatePickerConf) *time.Time
cis Parent container.labelis the label for datepicker.confis an optional configuration, at most one.- Return the selected date, as midnight UTC on the day picked. nil if no date is selected.
// DatePickerConf is the configuration for the DatePicker component.
type DatePickerConf struct {
tgframe.Base // ID
// Default is the date the picker starts on, read to the day. It is only
// read until the app user first picks one.
Default *time.Time
// Disabled is true if the datepicker is disabled.
Disabled bool
}
func (c *DatePickerConf) SetDefault(v time.Time) *DatePickerConf
Only the day is kept: a clock on the Default is dropped, the way
TimePicker drops the date. That is what lets the three pickers
be compared and added without a conversion in between.
Example
dateValue := tgcomp.DatePicker(p.Main, "DatePicker")
val := ""
if dateValue != nil {
val = dateValue.Format("2006-01-02")
}
tgcomp.Text(p.Main, "Value: "+val,
&tgcomp.TextConf{ID: "datepicker_result"})
Starting on a date, until the app user picks another:
tgcomp.DatePicker(p.Main, "DatePicker",
(&tgcomp.DatePickerConf{}).SetDefault(
time.Date(2026, 9, 8, 0, 0, 0, 0, time.UTC)))
Clearing the picker is an answer of "no date": the return goes back to nil and
stays there, rather than falling back to Default.
