views:

44

answers:

1

Hi all, I've tried so many different possibilities to achieve what I feel like should be a simple code execution. I am loading DOM objects from the server via .load(). One of the loaded items is an input text box with a date in it. I want to load the jdpicker (a plugin datepicker) when I click on the input box. Due to the behavior of .live() and .delegate(), even when I use .die() or .undelegate() respectively, I can't get the popup datepicker to behave normally. It either pops up, allows me to click one object in the window and then immediately closes (I cannot navigate through the months, years without the window closing), or the window pops up and every subsequent click re-executes the code producing multiple instances of the datepicker.

I've tried different combinations of .live(), .delegate(), .one() with no luck. I've tested the datepicker in the main window and know that it works fine there. I could post code, but am not sure which of the ten different attempts I've made would be the best example. I can show my latest attempt.

Does anyone have a suitable example for this? Thanks!


Update

I've edited the code to read as follows:

$("#edit-entry").load("/edit/", { id:id }, function(){
                $('.jdpicker').one('click', function(){
                    $(this).jdPicker();
                });
});

This is hinging on becoming the complete answer. The datepicker is no longer calling multiple instances, which is good, but I still can't navigate it's controls (month, year selection). If I click the next month, it will load and close. The next time I click it, it re-opens on the next month. So, it does work, but is certainly not desirable. Any suggestions?

A: 
Pointy
@Pointy - That's funny now that you mention it, because your comment took me back to where I started. I'm a newbie, so everything is the first time for me. I took your suggestion, but still have a slight issue...see my edit above. Thanks!
ionalchemist
Awesome, using .each is not something I had even looked at before. It is behaving better than it was, but I still can't navigate. I think there may be a bug with the plugin I am using. When I select a class element "jdpicker", the popup opens, but the next click closes it, no matter where that click occurs. I can click the nav arrow, I can click a new date as long as it is in the visible window, or I can click the main window....every second click closes the window, but only when the code has been dynamically loaded...?
ionalchemist
Nevertheless, thanks a lot!
ionalchemist
OK, well I've never used "jdPicker" so I can't offer any specific suggestions.
Pointy