Basic usage
Call the datepicker via javascript:
$('#myInput').datepicker();
Options
Name | type | default | description |
---|---|---|---|
format | string | 'mm/dd/yyyy' | The date format, combination of d, dd, m, mm, yy, yyyy and separators -,/,. |
weekStart | integer | 0 | Day of the week start. 0 for Sunday - 6 for Saturday |
autoClose | boolean | false | If true, datepicker will close after date selection. If false, datepicker will be open until user click outside the datepicker. |
viewMode | string | integer | 0 = 'days' | Set the start view mode. Accepts: 'days' , 'months' , 'years' , 0 for days, 1 for months and 2 for years |
minViewMode | string | integer | 0 = 'days' | Set a limit for view mode. Accepts: 'days' , 'months' , 'years' , 0 for days, 1 for months and 2 for years |
onStart | function | '' | This function is used when the datepicker is called. Should have a date as parameter and this parameter filled with date from input value or form group data tag. |
onRender | function | '' | This function is used when a day is rendered inside the datepicker. Should have a date as parameter. Should return a string, in fact the class name(s).
Return 'disabled' to disable the day from being selected. |
Markup
Simple input.
<input type="text" class="form-control" value="12-01-2015" id="myInput" />
Or as input group.
<div class="input-group date" id="myInput">
<input type="text" class="form-control" value="12/01/2015" />
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
</div>
data-date="01-01-1990"
. All over options starts with prefix data-date-
, namely data-date-format
, data-date-viewmode
and data-date-minviewmode
.
Methods
$().datepicker(options)
Initializes an datepicker.
$('#myInput').datepicker({
format: 'dd-mm-yyyy'
});
.datepicker('show')
Show the datepicker.
$('#myInput').datepicker('show');
.datepicker('hide')
Hide the datepicker.
$('#myInput').datepicker('hide');
.datepicker('place')
Updates the date picker's position relative to the element
$('#myInput').datepicker('place');
.datepicker('setValue', value)
Set a new value for the datepicker. It cand be a string in the specified format or a Date object.
$('#myInput').datepicker('setValue', value);
Events
Datepicker class exposes a few events for manipulating the dates.
Event | Description |
---|---|
show | This event fires immediately when the date picker is displayed. |
hide | This event is fired immediately when the date picker is hidden. |
changeDate | This event is fired when the date is changed. |