The DatePicker element extends the View interface to enter dates.

To create DatePicker function is used:

func NewDatePicker(session Session, params Params) DatePicker

You can set/get the current value using the "date-picker-value" property (the DatePickerValue constant).The following can be passed as a value to the "date-picker-value" property:

  • time.Time
  • constant
  • text that can be converted to time.Time by function
func time.Parse(layout string, value string) (time.Time, error)

The text is converted to time.Time. Accordingly, the Get function always returns a time.Time value.The value of the "date-picker-value" property can also be read using the function:

func GetDatePickerValue(view View, subviewID ...string) time.Time

The dates you enter may be subject to restrictions. For this, the following properties are used:

Property Constant Data type Restriction
"date-picker-min" DatePickerMin time.Time Minimum date value
"date-picker-max" DatePickerMax time.Time Maximum date value
"date-picker-step" DatePickerStep int Date change step in days

You can read the values of these properties using the functions:

func GetDatePickerMin(view View, subviewID ...string) (time.Time, bool)
func GetDatePickerMax(view View, subviewID ...string) (time.Time, bool)
func GetDatePickerStep(view View, subviewID ...string) int

The "date-changed" event (DateChangedEvent constant) is used to track the change in the entered value.The main event listener has the following format:

func(picker DatePicker, newDate, oldDate time.Time)

where the second argument is the new date value, the third argument is the previous date value.

Additional event listeners can have the following format

func(picker DatePicker, newDate time.Time)
func(newDate, oldDate time.Time)
func(newDate time.Time)
func(picker DatePicker)

You can get the current list of date change listeners using the function

func GetDateChangedListeners(view View, subviewID ...string) []func(DatePicker, time.Time, time.Time)