4

I'd like to make the button into a toggle but I looked at the docs and couldn't find a isHidden isVisible type of property...

.showCalendar is my button and #weekDate is my input field. Is there a way to get the display state of datepicker?

 $('.showCalendar').click(function () {
    $('#weekDate').datepicker("show");
 });
PruitIgoe
  • 5,912
  • 15
  • 65
  • 129

2 Answers2

9

You can check visibility of widget and toggle widget as following:

$(".dp-icon").click(function (event) {
    var visible = $(".has-dp").datepicker("widget").is(":visible");
    $(".has-dp").datepicker(visible ? "hide" : "show");
})
Genc Hosting
  • 187
  • 2
  • 6
2

To my knowledge, there is no way to get the display state of the date picker (apparently, applying :visible to the UI widget does not work).

However, you can solve your problem by binding to the toggle event:

$(".showCalendar").toggle(function() {
    $("#weekDate").datepicker("show");
}, function() {
    $("#weekDate").datepicker("hide");
});
Community
  • 1
  • 1
Frédéric Hamidi
  • 249,845
  • 40
  • 466
  • 467
  • 1
    This doesn't quite work when the calendar is shown from the toggle button and hidden from input blur: next toggle tries to hide it again thus making the button "miss" a click. – Jawa Jan 21 '13 at 10:03