I am trying to force my jQuery Datepicker to allow only the months of May and October to be selected, and to increase or decrease the year according to whether the user is advancing forwards through the months or going backwards.
I'm getting closer to this goal so far with the following code, but without knowing whether the user is clicking forwards or backwards on the datepicker's month selector I can't know whether to increment or decerement the year value.
$("#ApplicantExpectedStartDate").datepicker({
onChangeMonthYear: function (year, month, inst) {
// Force datepicker to display only May and October
if ((month > 5) && (month < 10)) {
$(this).datepicker("setDate", new Date(year, 9, 1));
$(this).datepicker("refresh");
}
if (month > 10) {
$(this).datepicker("setDate", new Date(year, 4, 1));
$(this).datepicker("refresh");
}
},
dateFormat: "dd/mm/yy",
changeYear: true
});
Are there any events that fire immediately prior to onChangeMonthYear that I could use in order to compare the new date to the old one for means of comparison? Is there a much more straightforward way of doing this than I'm currently attempting?
jsfiddle here: http://jsfiddle.net/jfejhjs8/4/