I\'ve searched here in SO and all around but no properly solutions founded for this issue. With jQueryUI DatePicker I need to select a recursive date for all years, so I do
Building upon the answer from Tats_innit, here is a solution which solves a couple of its problems.
$(function() {
$('.dp').datepicker({
dateFormat: 'd MM yy',
beforeShow: function(inp, inst) {
if (inp.classList.contains("Birthday")) {
inst.dpDiv.addClass('BirthdayDatePicker');
return {
dateFormat: 'MM d',
defaultDate: new Date(1904, 0, 1),
minDate: new Date(1904, 0, 1),
maxDate: new Date(1904, 11, 31),
};
}
},
onClose: function(dateText, inst) {
inst.dpDiv.removeClass('BirthdayDatePicker');
}
});
});
.BirthdayDatePicker .ui-datepicker-year {
display: none;
}
Birthday:
Defaults:
I find that using a class on the input is a simpler way to specify which behavior we want out of the datepicker.
If the Birthday class is found, we use the year 1904 rather than whatever the current year is because 1904 is a leap year which insures that February 29th is available. Also we limit the widget to one 12-month period with the minDate/MaxDate options. You could also include numberOfMonths: [ 3, 4 ]
in the return'd object to display the whole year at once if you like.