Date Picker

The Date Picker lets you easily add date selection functionality to your webview.

Example Usage

The following code snippet shows how to create a Date Picker:

const url = await webview.datePicker.create({
  ref: 'pickup-date',
  title: 'Choose a pick up date',
  onSelect: {
    eventName: 'pick date',
    paramName: 'date'
  }
})

In this example, the Date Picker is given a reference ID (ref), a title that appears at the top, and an onSelect configuration that specifies which event to trigger when a date is chosen.

Properties

PropertyTypeExampleDescription
refstringpickup-dateOptional. If provided, the webview will update its content.
titlestringChoose a date...Required. The title shown at the top of the webview.
tintstring#FF0000Optional. The tint color applied to the buttons.
button.labelstringChoose dateOptional. The text displayed on the confirmation button.
onSelect.eventNamestringDate selectedRequired. The name of the event that will be triggered when a selection is made.
onSelect.paramNamestringpickupDateOptional. The name of the parameter that will hold the selected date.

Calendar properties

These parameters allows you to customize the calendar’s behavior and appearance:

ParameterTypeDefaultDescription
valuearrayNAAn array of dates that are initially selected.
disabledDate RangeNASpecifies dates that should be disabled (unavailable for selection). Accepts a Date Range (see Date Range below).
eventsDate RangeNASpecifies dates that have events. These dates are marked with an extra dot on the calendar. Accepts a Date Range (see Date Range below).
monthNamesarray['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August' , 'September' , 'October', 'November', 'December']An array of full month names.
monthNamesShortarray['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']An array of abbreviated month names.
dayNamesarray['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']An array of full weekday names.
dayNamesShortarray['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']An array of abbreviated weekday names.
firstDaynumber1The first day of the week. By default, 1 is Monday.
weekendDaysarray[0,6]The index numbers for weekend days. [0,6] indicated Saturday and Sunday.
dateFormatstringyyyy-mm-ddDefines the format of the displayed date. Available expressions: yyyy – 4-digit year yy – 2-digit year mm – 2-digit month (01 to 12) m – month number (1 to 12) MM – full month name M – abbreviated month name dd – 2-digit day (01 to 31) d – day number (1 to 31) DD – full weekday name D – abbreviated weekday name
multiplebooleanfalseAllow the selection of multiple dates.
rangePickerbooleanfalseEnable a range selection mode. Note: This is not compatible with multiple date selection.
rangePickerMinDaysnumber1The minimum number of days that must be selected when using range mode.
rangePickerMaxDaysnumber0The maximum number of days that can be selected in range mode. Use 0 for no maximum.
directionstringhorizontalThe layout direction for the calendar months.
minDateDatenullThe earliest selectable date.
maxDateDatenullThe latest selectable date.
weekHeaderbooleantrueEnable a header row displaying abbreviated weekday names.
monthSelectorbooleantrueEnable a month selector in the toolbar.
yearSelectorbooleantrueEnable a year picker in the toolbar.

More details

Date Range {#date-range}

Certain calendar properties (like disabled and events) accept a Date Range. This feature allows you to specify a group of dates using simple objects.

Example: Disable a Range of Dates

To disable all dates from September 1, 2015 to November 31, 2015, use:

...
  // Disable all dates between 1st October 2015 and 31 December 2015
  disabled: {
    from: new Date(2015, 9, 1),
    to: new Date(2015, 11, 31)
  }
  ...

Example: Mixed Date Range for Events

You can also mix individual dates with ranges:

...
  events: [
    new Date(2015, 9, 1),
    new Date(2015, 9, 5),
    {
        from: new Date(2015, 9, 10),
        to: new Date(2015, 9, 15)
    },
    {
        from: new Date(2015, 9, 20),
        to: new Date(2015, 9, 31)
    },
    {
        date: new Date(2015, 11, 1),
        color: '#ff0000'
    }
  ]
  ...

Date Events

You can add more than one colored dot to indicate multiple events. To do this, include multiple event objects with date and color properties:

...
  events: [
    new Date(2015, 9, 1),
    new Date(2015, 9, 5),
    {
        from: new Date(2015, 9, 10),
        to: new Date(2015, 9, 15)
    },
    {
        from: new Date(2015, 9, 20),
        to: new Date(2015, 9, 31)
    },
    {
        date: new Date(2015, 11, 1),
        color: '#ff0000'
    },
    // same date but one more color dot will be added
    {
        date: new Date(2015, 11, 1),
        color: '#00ff00'
    },
  ]
  ...

In this case, November 1, 2015 shows two dots (one red and one green) to indicate multiple events.