Skip to main content

Pickers

Date pickers let users select a date, or a range of dates.

Date pickers

Date pickers let users select a date or range of dates. They should be suitable for the context in which they appear.

Date pickers can be embedded into:

  • Dialogs on mobile
  • Text field dropdowns on desktop

For advanced Pickers, read flatpickr plugin documentation.

A date picker has to be activated via JavaScript.

N.B. Date picker requires material.js, material.min.js or https://cdn.jsdelivr.net/npm/pickadate@3.6.4/lib/picker.date.min.js.

<label for="exampleInputDatePicker1">A basic picker</label>
<input class="form-control" id="exampleInputDatePicker1" placeholder="Pick a date" type="text">
$('#exampleInputDatePicker1').pickdate();

Options

Alternatively, options can be passed on to override some default datepicker behaviours.

<label for="exampleInputDatePicker2">A customised date picker:</label>
<input class="form-control" id="exampleInputDatePicker2" name="exampleInputDatePicker2" placeholder="Pick a date" type="text">
$('.datepicker').pickdate({
  cancel           : 'Clear',
  closeOnCancel    : false,
  closeOnSelect    : true,
  container        : 'body',
  containerHidden  : 'body',
  firstDay         : 1,
  // Escape any 'rule' characters with an exclamation mark (!)
  format           : 'You selecte!d: dddd, d mm, yy',
  formatSubmit     : 'dd/mmmm/yyyy',
  hiddenPrefix     : 'prefix_',
  hiddenSuffix     : '_suffix',
  labelMonthNext   : 'Next month',
  labelMonthPrev   : 'Previous month',
  labelMonthSelect : 'Choose month',
  labelYearSelect  : 'Choose year',
  ok               : 'Close',
  onClose          : function () {
    console.log('Datepicker closes')
  },
  onOpen           : function () {
    console.log('Datepicker opens')
  },
  selectMonths     : true,
  selectYears      : 10,
  today            : 'Today'
});
Option Description
cancel Change the text of the cancel button or use cancel: '' to hide the button. Default is 'Cancel'.
closeOnCancel Close the picker when the cancel button is clicked. Default is true. Set to false to change this behaviour.
closeOnSelect Close the picker when a date is selected. Default is false. Set to true to change this behaviour.
container Change where to insert the datepicker element by passing any valid CSS selector. By default, the picker is inserted right after the associated input element.
containerHidden By default, the picker’s hidden input is inserted right after the main input element. Specify where to insert the hidden element by passing any valid CSS selector to this option.
disable Disable a date or a set of dates from being selectable in the picker. See below for detailed usage.
firstDay Change the first day of the week. Default is 0 which sets it to Sunday. Set it to Monday by changing the value to 1.
format Set the date format. See below for a full list of available date format rules.
formatSubmit Optionally, set a different date format for the value to be submitted to the server. When formatSubmit is specified, a hidden input with the same name attribute as the original will be created to hold the value.
hiddenName Set to true to only send the hidden value hold by the hidden input created by setting formatSubmit to the server. Setting this to true essentially nullifies the hiddenPrefix and hiddenSuffix, strips the name attribute from the source input, and then sets it as the name of the hidden input.
hiddenPrefix
hiddenSuffix
Add optional prefix/suffix to the name attribute of the hidden input that is created by setting formatSubmit.
labelMonthNext
labelMonthPrev
labelMonthSelect
labelYearSelect
Change the accessibility labels (i.e. title attributes) to several elements of the picker.
max Set the maximum selectable date. See below for detailed usage.
min Set the minimum selectable date. See below for detailed usage.
monthsFull Change labels of months.
monthsShort Change abbreviations of months.
ok Change the text of the OK button or set it to '' to hide the button. Default is 'OK'.
onClose,
onOpen,
onRender,
onSet,
onStart,
onStop
Fire events as the user interacts with the picker. Within scope of these events, this refers to the picker.
selectMonths Default is false. Set it to true to display a dropdown menu to pick the month.
selectYears Default is false. Set it to true to display a dropdown menu to pick the year or use an even integer to specify the number of years to be shown in the dropdown menu (half after and the other half before the year in focus).
today Change the text of the today button or pass an empty value to hide the button: today: ''. Default is 'Today'.
weekdaysFull Change labels of weekdays.
weekdaysShort Change abbreviations of weekdays.

Date limit

Maximum and minimum selectable dates can be set on the picker.

<label for="exampleInputDatePicker3">Using boolean or integers:</label>
<input class="form-control" id="exampleInputDatePicker3" placeholder="Pick a date" type="text">
$('.datepicker').pickdate({
  // Default is `false` which removes any limits. `true` sets it to today.
  max: true,
  // An integer (negative or positive) sets it relative to today.
  min: -10
});
<label for="exampleInputDatePicker4">Using JavaScript date:</label>
<input class="form-control" id="exampleInputDatePicker4" placeholder="Pick a date" type="text">
$('.datepicker').pickdate({
  max: new Date(2016,1,13),
  min: new Date(2016,0,3)
});
<label for="exampleInputDatePicker5">Using <code>[YEAR,MONTH,DATE]</code>:</label>
<input class="form-control" id="exampleInputDatePicker5" placeholder="Pick a date" type="text">
$('.datepicker').pickdate({
  max: [2016,1,13],
  min: [2016,0,3]
});

Disable dates

Disable a specific or arbitrary set of dates selectable on the picker.

<label for="exampleInputDatePicker6">Using JavaScript date or <code>[YEAR,MONTH,DATE]</code>:</label>
<input class="form-control" id="exampleInputDatePicker6" placeholder="Pick a date" type="text" value="1/1/2016">
$('.datepicker').pickdate({
  disable: [
    new Date(2016,0,16),
    new Date(2016,0,20),
    [2016,0,24]
  ]
});
<label for="exampleInputDatePicker7">Using integers as days of the week:</label>
<input class="form-control" id="exampleInputDatePicker7" placeholder="Pick a date" type="text" value="1/1/2016">
$('.datepicker').pickdate({
  disable: [
    1, 2, 3
  ]
});
<label for="exampleInputDatePicker8">Using objects as a range of dates:</label>
<input class="form-control" id="exampleInputDatePicker8" placeholder="Pick a date" type="text" value="1/1/2016">
$('.datepicker').pickdate({
  disable: [
    { from: new Date(2016,0,16), to: [2016,0,24] }
  ]
});

The values for from and to can be:

  • Array formatted as [YEAR,MONTH,DATE]
  • JavaScript date
  • true to set it as “today”

The values can also be integers representing dates relative to the other:

<label for="exampleInputDatePicker9"><code>from</code> can only be negative:</label>
<input class="form-control" id="exampleInputDatePicker9" placeholder="Pick a date" type="text">
{ from: -10, to: true }
<label for="exampleInputDatePicker10"><code>to</code> can only be positive:</label>
<input class="form-control" id="exampleInputDatePicker10" placeholder="Pick a date" type="text" value="1/1/2016">
{ from: [2016,0,16], to: 10 }

Formatting rules

The following rules can be used to format any date:

Rule Description Result
d Date of the month 1 – 31
dd Date of the month with a leading zero 01 – 31
ddd Day of the week in short form Sun – Sat
dddd Day of the week in full form Sunday – Saturday
m Month of the year 1 – 12
mm Month of the year with a leading zero 01 – 12
mmm Month name in short form Jan – Dec
mmmm Month name in full form January – December
yy Year in short form * 00 – 99
yyyy Year in full form 2000 – 2999