Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery UI datepicker: how to bind an event AFTER the calendar was rendered?

I am using datepicker. The usual way to bind an event, lets say for example, beforeShowDay, would be:

$('.selector').datepicker({
   beforeShowDay: function(date) { ... }
});

What I need is to bind the beforeShowDay event after the calendar was rendered. So, let's say first I render the calendar:

$('.mySpecialContainer').datepicker({
   //in this moment, for some reason, I am not allowed to bind nothing (that's not me who renders the calendar, that's why I am not allowed)
});

And then, if I try to bind something in the usual way:

$('.mySpecialContainer').datepicker({
   beforeShowDay: function(date) { ... }
});

The calendar will be - of course - rendered again inside '.mySpecialContainer', instead of just binding the event. I have tried:

$('.mySpecialContainer').bind('beforeShowDay', function(date) { ... });

But that was just a desperate action :)

like image 580
bluefoot Avatar asked Mar 05 '11 03:03

bluefoot


2 Answers

It doesn't make sense to me why you can't call bind on that particular datepicker event (or, for that matter, most datepicker events). Most other jQueryUI widgets allow late-binding of events.

However, you can try the following. hasDatepicker is applied to datepickers, and calling .datepicker again on those elements is not reinitializing the widget, it's just modifying an option:

$('.hasDatepicker').datepicker("option", "beforeShowDay", 
    function(date) { ... });
like image 115
Andrew Whitaker Avatar answered Nov 04 '22 22:11

Andrew Whitaker


$('.ui-datepicker-current-day').click();
like image 1
Sam T Avatar answered Nov 04 '22 21:11

Sam T