3

Possible Duplicate:
problem when cloning jQuery UI datepicker

I have a problem with the jQuery datepicker. I have a div that i clone. That div contains an input element with the jQuery datepicker attached to it.

When i simply clone this element then the datepicker isn't working on the cloned element. To fix this i had to remove the hasDatepicker class from the cloned input element and re-initialize the datepicker method.

Now the datepicker shows up on the cloned element, but whenever i pick a date, then the date gets placed in the "original" input field instead of the field that opened the datepicker...

Anyone any idea how i can fix this problem..?

Here's a demo is the problem: http://jsfiddle.net/4VQkg/

Simply clone the element and try to pick a date fron the cloned input field. You'll see that the data won't get placed in the desired input field.

Community
  • 1
  • 1
w00
  • 26,172
  • 30
  • 101
  • 147

1 Answers1

4

try this,

Demo: http://jsfiddle.net/4VQkg/3/

Code:

function initGui()
{
    $('.date-iso8601').datepicker();
}

$(function() {
    initGui();

    $('.clone').click(function() {
        var clone = $('.datepicker').clone();

        var cloneObj = clone.find('.date-iso8601');
        cloneObj.removeClass('hasDatepicker').removeAttr('id');

        clone.appendTo('.elements');


        $(cloneObj).datepicker();
    });
});
Muthu Kumaran
  • 17,682
  • 5
  • 47
  • 70