I am trying to disable months in a datepicker using the option datesDisabled. According to the docs it should work by passing an array of strings in the format of what I'm using for the datepicker but I can't get it to work.
HTML:
<div class="modal-body">
<div class="input-append date" id="datepicker1" data-date="Aug-2015" data-date-format="mm-yyyy" data-dates-disabled="Sep-2015,Oct-2015" style="display:inline-block; font-weight:bold;">
Check In: <input type="text" readonly="readonly" name="date1" >
<span class="add-on"><i class="glyphicon glyphicon-calendar"></i></span>
</div>
</div>
Javascript:
var dateStart = new Date();
dateStart.setDate(dateStart.getDate()-1);
$( document ).ready(function() {
var dp = document.getElementById("datepicker1");
$("#datepicker1").datepicker( {
format: "mm-yyyy",
startView: "months",
minViewMode: "months",
startDate: dateStart,
datesDisabled: dp.dataset.datesDisabled.split()
}).datepicker("setDate",null);
});
Update:
It doesn't look like this will get answered so I decided to try and do this by finding all of the months and changing them to the disabled class. The problem is that I can't detect the clicks to be able to get the year of the current calendar.
HTML of the datepicker header:
<tr>
<th style="visibility: hidden;" class="prev">?</th>
<th colspan="5" class="datepicker-switch">2015</th>
<th style="visibility: visible;" class="next">?</th>
</tr>
Javascript:
$("th.next:first").click(function(){
var currentYear = $("th.datepicker-switch:first").html();
console.log("current year is " + currentYear); // nothing happens here
});
What's the correct way to detect clicks on elements inside of the datepicker?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…