How do I display/hide a date picker only on click on a custom button?
My objective is to disable the functionality of the date picker by hiding it when I click somewhere other than the date picker.
How do I display/hide a date picker only on click on a custom button?
My objective is to disable the functionality of the date picker by hiding it when I click somewhere other than the date picker.
Consider to use showOn button option, it enable a button near the datepicker.
You can use show and hide datepicker methods in order to toggle the visibility.
In the demo I have blocked the opening/closing anywhere so it's totally handled.
Code:
jQuery.datepicker._checkExternalClick = function () {};
$("#datepicker").datepicker({
constrainInput: true,
showOn: 'none',
onSelect: function () {
$(this).data('datepicker').inline = true;
},
onClose: function () {
$(this).data('datepicker').inline = false;
}
});
$('#toggle').click(function () {
if ($(this).hasClass('opened')) {
$("#datepicker").datepicker('hide');
} else {
$("#datepicker").datepicker('show');
}
$(this).toggleClass('opened');
});