Bootstrap Datepicker - Months and Years Only
I am using bootstrap datepicker and my code is like following, Demo of the code on jsfiddle
<div class="input-append date" id="datepicker" data-date="02-2012"
data-date-format="mm-yyyy">
<input type="text" readonly="readonly" name="date" >
<span class="add-on"><i class="icon-th"></i></span>
</div>
$("#datepicker").datepicker({
viewMode: 'years',
format: 'mm-yyyy'
});
The above code is working fine, but what I am trying to do is allow users pick months and years only.
Could you please tell me how to do that?
How about this :
$("#datepicker").datepicker( {
format: "mm-yyyy",
viewMode: "months",
minViewMode: "months"
});
Reference : Datepicker for Bootstrap
For version 1.2.0 and newer, viewMode
has changed to startView
, so use:
$("#datepicker").datepicker( {
format: "mm-yyyy",
startView: "months",
minViewMode: "months"
});
Also see the documentation.
Notice that in the version of 1.2.0 the viewMode
has changed to startView
.
eg:
$('#sandbox-container input').datepicker({
startView: 1,
minViewMode: 1
});
http://eternicode.github.io/bootstrap-datepicker/?markup=component&format=yyyy&weekStart=&startDate=&endDate=&startView=2&minViewMode=2&todayBtn=false&language=zh-CN&orientation=auto&autoclose=on&forceParse=on#sandbox
I'm using version 2(supports both bootstrap v2 and v3) and for me this works:
$("#datepicker").datepicker( {
format: "mm/yyyy",
startView: "year",
minView: "year"
});
For the latest bootstrap-datepicker
(1.4.0 at the time of writing), you need to use this:
$('#myDatepicker').datepicker({
format: "mm/yyyy",
startView: "year",
minViewMode: "months"
})
Source: Bootstrap Datepicker Options