views:

960

answers:

2

Ok, I'm trying to use the FaceBox() plugin for jQuery along with the jQuery UI datepicker().

I've got it to bind to the lightbox'd inputs on the first appearance of the lightbox, but it's not working afterwards.

I'm doing the following:

$(function() { 
    $('.jQueryCalendar').live('click', function () {
            $(this).datepicker({showOn: 'both'}).focus();
    });
});

When the lightbox closes, I'm re-appending it's content to the page (in order to not lose the content div), and this seems to be killing the live() call. [NB the re-appending takes place after the original content is destroyed]

EDIT

Ok, the live() event IS firing (thanks to Nick Craver for that), however the datepicker is no longer being shown. Does anyone have an idea why?

EDIT #2

Ok, the use of .html() to re-append causes the events to need rebinding, but the element to bind still has the class hasDatepicker, which messes with the datepicker() initialisation.

To fix, simply user

$(this).removeClass('hasDatepicker') .datepicker({showOn: 'both'}).focus();

+1  A: 

its possible that the datepicker is behind the box...

i had also the same problem a time ago.

put this in a css file, and that did the trick for me.

#ui-datepicker-div
{
    z-index:9999999;
}
bruno
nope, like I said, works the first time: I've already taken care of the z-index
Ed Woodcock
+2  A: 

Try this and see what happens:

$(function() { 
    $('.jQueryCalendar').live('click', function () {
            $(this).datepicker('destroy').datepicker({showOn: 'both'}).focus();
    });
});

If you're using jQuery UI 1.7.2 with jquery 1.4, some effects destroy widgets, it fading, etc may be causing datepicker issues. jQuery UI 1.8 fixes this, it's at RC3 Status at the moment.

Nick Craver
nope, sorry, exhibits exactly the same behaviour!
Ed Woodcock
@Ed - In that case, is the lightbox fading, or re-sizing, any animation on close?
Nick Craver
yes, it fades out, however, this does not break any other datepickers (that are not in the lightbox) and I'm on jQuery 1.3.2
Ed Woodcock
@Ed - Can you post the code where you're re-appending to the page? lightbox should be doing this by itself, maybe something's getting lost there.
Nick Craver
@Nick there's quite a lot of it, so check out my answer to http://stackoverflow.com/questions/2027290/facebox-adding-commas-to-input
Ed Woodcock
For future reference, the facebox lightbox is slightly dodgy when it comes to non-image content, so I'm using an almost completely re-written version now :)
Ed Woodcock
@Ed - I'm almost positive that .html() call is what's causing you issues, just pasting the code won't copy the widget data down.
Nick Craver
@Nick Correct, hence the use of live(). I've actually fixed it now: it's the fact that the element still has hasDatepicker as a class messing with the initialisation process.
Ed Woodcock