Datepicker control type

The "Datepicker K2BTools" control type extends GeneXus' default datepicker control to add advanced features:

  • Establishing a range of valid dates. This can be done setting the minimum and maximum date expression properties.
  • Specifying which dates are selectable. This can be accomplished using the "Day status provider" property. This is typically used to show the user which dates are valid/available. See more details below.

DatepickerK2BToolsConfiguration DatepickerK2BToolsControlType
Datepicker configuration Datepicker control in runtime

As you can see in the images above, the control does not allow to select dates in weekends, and in runtime those days are shown as disabled. Also, the minimum and maximum dates are set, and that affects how navigation buttons are shown.

Specifying date status

To specify the dates status a data provider or procedure must be selected in the "Day status provider" property. The selected object must:

  • Use the K2BTools.Controls.Datepicker.ExtendedDatepickerDateStatus SDT as its return type.
  • Have "From" and "To" date parameters.
  • In its logic, it must load the SDT with the status for all dates between the values received as parameters (including the boundaries). For each date, load a "DayStatus" structure as follows.
    • date: The date that is being configured.
    • status: Determines if the date should be available for selection or not. Use the "DayStatus" domain.
    • class: Optional. If set, the specified class will be added to the div used to display the date. This may be used to convey more precise status for the date, such as "few slots available".
    • tooltip: Optional. If set, the specified value will be used as the day's tooltip.

In runtime, the procedure will be called whenever the user changes the month in the datepicker. The visible month's boundaries will be passed as parameters.

Sample

A sample procedure can be found in the "K2BTools.Controls.Datepicker.WeekendsNotAvailable" object. That object implements the logic needed to make weekends non-selectable.

Its code is as follows:

&Result = new()
Do While &DateFrom <= &DateTo
    &DayStatus = new()
    &DayStatus.date = &DateFrom
    
    If &DateFrom.DayOfWeek() = 1 or &DateFrom.DayOfWeek() = 7
        &DayStatus.status = DayStatus.Unavailable
    Else
        &DayStatus.status = DayStatus.Available
    EndIf

    &DayStatus.tooltip = &DateFrom.DayOfWeekName()
    
    &Result.status.Add(&DayStatus)
    
    &DateFrom = &DateFrom.AddDays(1)
EndDo

Validation

This control implements validations on the client side to provide feedback to the user. As with all client side validations, our recommendation is that you repeat validations on the server side prior to using the value. In this case, aside from possible problems arising from people abusing the system a secondary problem may occur: The dates available for selection may change (for example, when the datepicker is used to select dates to book appointments).

When validations fail, the user will be presented with a user friendly message in the UI if the "Show validation errors" property is set to True.

Methods

The control implements these methods:

  • SetDateStatus: This method is used by K2BTools, its manual usage is not recommended.
  • GoToDate(year, month, day): This method can be used to force the control to navigate to the specified date.