Back to Materialize

Pickers Content

jade/page-contents/pickers_content.html

1.0.08.3 KB
Original Source

Date Picker

The datepicker allows users to select a date from an interactive calendar.

Birthdate

<input type="text" class="datepicker">
Initialization
document.addEventListener('DOMContentLoaded', function() {
    var elems = document.querySelectorAll('.datepicker');
    var instances = M.Datepicker.init(elems, options);
  });

  // Or with jQuery

  $(document).ready(function(){
    $('.datepicker').datepicker();
  });
Options
NameTypeDefaultDescription
autoCloseBooleanfalseAutomatically close picker when date is selected.
formatString'mmm dd, yyyy'The date output format for the input field value.
parseFunctionnullUsed to create date object from current input string.
defaultDateDatenullThe initial date to view when first opened.
setDefaultDateBooleanfalseMake the defaultDate the initial selected value.
disableWeekendsBooleanfalsePrevent selection of any date on the weekend.
disableDayFnFunctionnullCustom function to disable certain days.
firstDayNumber0First day of week (0: Sunday, 1: Monday etc).
minDateDatenullThe earliest date that can be selected.
maxDateDatenullThe latest date that can be selected.
yearRangeNumberArray
isRTLBooleanfalseChanges Datepicker to RTL.
showMonthAfterYearBooleanfalseShow month after year in Datepicker title.
showDaysInNextAndPreviousMonthsBooleanfalseRender days of the calendar grid that fall in the next or previous month.
containerElementnullSpecify a DOM element to render the calendar in, by default it will be placed before the input.
showClearBtnBooleanfalseShow the clear button in the datepicker.
i18nObjectSee i18n documentation.Internationalization options.
eventsArray[]An array of string returned by Date.toDateString(), indicating there are events in the specified days.
onSelectFunctionnullCallback function when date is selected, first parameter is the newly selected date.
onOpenFunctionnullCallback function when Datepicker is opened.
onCloseFunctionnullCallback function when Datepicker is closed.
onDrawFunctionnullCallback function when Datepicker HTML is refreshed.
Date format options

Use these in the format option to customize your date string.

KeyDescriptionOutput
dDate of the month.1-31
ddDate of the month (2 digits).01-31
dddDay of the week in short form set by the i18n option.Sun-Sat
ddddDay of the week in full form set by the i18n option.Sunday-Saturday
mMonth of the year.1-12
mmMonth of the year (2 digits).01-12
mmmMonth of the year in short form set by the i18n option.Jan-Dec
mmmmMonth of the year in full form set by the i18n option.January-December
yy2-digit year.17
yyyy4-digit year.2017
Datepicker Internationalization options

Use these in the i18n option to localize the datepicker.

KeyText
cancel'Cancel'
clear'Clear'
done'Ok'
previousMonth'‹'
nextMonth'›'
months
[
  'January',
  'February',
  'March',
  'April',
  'May',
  'June',
  'July',
  'August',
  'September',
  'October',
  'November',
  'December'
]

| | monthsShort |

[
  'Jan',
  'Feb',
  'Mar',
  'Apr',
  'May',
  'Jun',
  'Jul',
  'Aug',
  'Sep',
  'Oct',
  'Nov',
  'Dec'
]

| | weekdays |

[
  'Sunday',
  'Monday',
  'Tuesday',
  'Wednesday',
  'Thursday',
  'Friday',
  'Saturday'
]

| | weekdaysShort |

[
  'Sun',
  'Mon',
  'Tue',
  'Wed',
  'Thu',
  'Fri',
  'Sat'
]

| | weekdaysAbbrev | ['S','M','T','W','T','F','S'] |

Properties
NameTypeDescription
elElementThe input element the plugin was initialized with.
optionsObjectThe options the instance was initialized with.
isOpenBooleanIf the picker is open.
dateDateThe selected Date.
Methods

Because jQuery is no longer a dependency, all the methods are called on the plugin instance. You can get the plugin instance like this:

var instance = M.Datepicker.getInstance(elem);

/* jQuery Method Calls
You can still use the old jQuery plugin method calls.
But you won't be able to access instance properties.

$('.datepicker').datepicker('methodName');
$('.datepicker').datepicker('methodName', paramName);
*/
.open();

Open datepicker

instance.open();
.close();

Close datepicker

instance.close();
.toString();

Gets a string representation of the selected date

instance.toString();
.setDate();

Set a date on the datepicker

Arguments

Date (optional): Date to set on the datepicker.

instance.setDate(new Date());
.gotoDate();

Change date view to a specific date on the datepicker

Arguments

Date: Date to show on the datepicker.

instance.gotoDate(new Date());
.destroy();

Destroy plugin instance and teardown

instance.destroy();

Time Picker

The timepicker allows users to select a date from an interactive clock.

Lunchtime

<input type="text" class="timepicker">
Initialization
document.addEventListener('DOMContentLoaded', function() {
    var elems = document.querySelectorAll('.timepicker');
    var instances = M.Timepicker.init(elems, options);
  });

  // Or with jQuery

  $(document).ready(function(){
    $('.timepicker').timepicker();
  });
Options
NameTypeDefaultDescription
durationNumber350Duration of the transition from/to the hours/minutes view.
containerStringnullSpecify a selector for a DOM element to render the calendar in, by default it will be placed before the input.
showClearBtnBooleanfalseShow the clear button in the Timepicker.
defaultTimeString'now'Default time to set on the timepicker 'now' or '13:14'
fromNowNumber0Millisecond offset from the defaultTime.
i18nObjectSee i18n documentation.Internationalization options.
autoCloseBooleanfalseAutomatically close picker when minute is selected.
twelveHourBooleantrueUse 12 hour AM/PM clock instead of 24 hour clock.
vibrateBooleantrueVibrate device when dragging clock hand.
onOpenStartFunctionnullCallback function called before modal is opened.
onOpenEndFunctionnullCallback function called after modal is opened.
onCloseStartFunctionnullCallback function called before modal is closed.
onCloseEndFunctionnullCallback function called after modal is closed.
onSelectFunctionnullCallback function when a time is selected, first parameter is the hour and the second is the minute.
Timepicker Internationalization options

Use these in the i18n option to localize the timepicker.

KeyText
cancel'Cancel'
clear'Clear'
done'Ok'
Properties
NameTypeDescription
elElementThe input element the plugin was initialized with.
optionsObjectThe options the instance was initialized with.
isOpenBooleanIf the picker is open.
timeStringThe selected time.
Methods

Because jQuery is no longer a dependency, all the methods are called on the plugin instance. You can get the plugin instance like this:

var instance = M.Timepicker.getInstance(elem);

/* jQuery Method Calls
You can still use the old jQuery plugin method calls.
But you won't be able to access instance properties.

$('.timepicker').timepicker('methodName');
$('.timepicker').timepicker('methodName', paramName);
*/
.open();

Open timepicker

instance.open();
.close();

Close timepicker

instance.close();
.showView();

Show hours or minutes view on timepicker

Arguments

String: The name of the view you want to switch to, 'hours' or 'minutes'.

instance.showView('hours');
.destroy();

Destroy plugin instance and teardown

instance.destroy();