The DatePicker will always open on the date which is selected in the input. I need to open DatePicker at the current month, no matter what date is selected in the input.
I have tried the following, but it will change the value of the input as well, which is not desirable.
beforeShow: function() {
$(input).datepicker("setDate", "0");
}
CodePudding user response:
It is not ideal, but a workaround could be to enable the today button panel, hide it with css and trigger click this button when the calendar is rendered:
$('#datepickerText').datepicker({
showButtonPanel: true
});
$('#datepickerText').on('click',function(){
$('.ui-datepicker-current').trigger('click');
});
css:
.ui-datepicker-buttonpane{
display:none;
}
See working fiddle: https://jsfiddle.net/03hf5x6t/
CodePudding user response:
After playing with it for a while I did it this way:
$('input').datepicker({
beforeShow: function(input, inst) {
setTimeout(function() {
var date = new Date();
inst.selectedDay = date.getDate();
inst.drawMonth = inst.selectedMonth = date.getMonth();
inst.drawYear = inst.selectedYear = date.getFullYear();
$.datepicker._adjustDate(input);
}, 1);
}
});
