Basically I have a list of draggable items and initially one droppable element for them to be dragged into. When an item is dragged into the droppable, the droppable is cloned (before the item is appended) and appended as a new droppable area.
Take a look at this stripped down fiddle: http://jsfiddle.net/DKBU9/1/ (omitted sortable())
HTML
<ul id="draggables">
<li>foo1</li>
<li>foo2</li>
<li>foo3</li>
</ul>
<ul class="droppable new">
</ul>
JS
$('#draggables > li').draggable({
appendTo: 'document',
revert: 'invalid'
});
$('.droppable > li').draggable({
appendTo: 'document',
revert: 'invalid'
});
$('#draggables').droppable({
accept: '.droppable > li',
drop: function(event, ui) {
ui.draggable.detach().css({top: 0,left: 0}).appendTo($(this));
}
});
$('.droppable').droppable({
accept: '#draggables > li',
drop: function(event, ui) {
if($(this).hasClass('new')) {
var clone = $(this).clone(true, true);
$(this).removeClass('new').after(clone);
}
ui.draggable.detach().css({top: 0,left: 0}).appendTo($(this));
}
});
As you can see, the dragging and dropping works for the initial elements, but is not preserved in the clone. I thought clone(true, true)
copied matched and child elements and their event handlers.
I even tried putting the above JS in a function and running that function in the drop events, but I got nothing.
Ultimately I want to be able to drag and drop between the "pool" list and the cloned lists and between the cloned lists themselves, as well as sort the items within the cloned lists.