0

Possible Duplicate:
problem when cloning jQuery UI datepicker

I used the jQuery clone function to clone a table with a datepicker function, but each time I clone a new table and try to click on its datepicker input, it appears on the default table that was cloned:

$('.clone_table').on("click", function() { 
    var $fromTable = $(this).closest(".contain"); 
    var $cloneTable = $fromTable.clone(true); 
    $(".contain:last").after($cloneTable); 
    var selects = $fromTable.find("select"); 
    $(selects).each(function(i) { 
        var select = this; 
        $cloneTable.find("select").eq(i).val($(select).val()); 
    });
});
Community
  • 1
  • 1
deetu
  • 79
  • 7
  • This is the Table function `this.insertStatsTable = function() { self.insertInstanceRow($(".contain:first")); var $newTable = $(".contain:first").clone(true); $("tbody tr td select:eq(0)", $newTable).attr("disabled", "true").append($("").val("*").text("AGGREGATE VALUE")); self.generateTimeColumns(defaultcolumn, $newTable); ($("tbody tr", $(".contain:first"))).remove(); $(".contain:last").after($newTable); $newTable.show(); $(".datepicker", $newTable).datetimepicker({ onClose: function(p1, p2) { processStaticTable($(p2.input)); } }); return $newTable; };` – deetu Oct 24 '12 at 09:17
  • @deetu it would generally be better to edit your original post instead of pasting code in the comments. It does have a 600 character limit after all. :P – Joseph Marikle Oct 24 '12 at 09:19

1 Answers1

2

The clone function MUST be called with parameters of true, true (withDataAndEvents and deepWithDataAndEvents) for this to work. withDataAndEvents might be enough though.

$("#element").clone(true, true); //You might not need the last true!
h2ooooooo
  • 39,111
  • 8
  • 68
  • 102
  • its fine now, what i did was ` $(".datepicker", $cloneTable).datetimepicker("destroy").removeAttr("id"); $(".datepicker", $cloneTable).datetimepicker({ onClose: function(p1, p2) { processStaticTable($(p2.input)); } });` – deetu Oct 24 '12 at 10:26