I want to apply function called copie_contenue that change the div parent id on the copy I created after I dragged my original,but my script change the original not the copy I also tried ui.helper in the place of this but nothing happen
$('#model_1').draggable({
connectToSortable:'#global_div',
addClasses: false,
helper:'clone',
stop: function(e,ui) {
$(this).replaceWith(copie_contenue("model_1"));
}
})
@DarthJDG :actually it worked but i included my sortable in the draggable script thanks
});
To change the newly inserted item, you should use the sortable's receive event. However, as of today, there is a known limitation/missing feature in jQuery UI (1.8.11) so that you can't easily get access to the cloned item from the receive event. The existing ui.item references the original element, not the copy.
As a workaround, you can add a special class to the original item when dragging starts for which you can search the sortable's items on the receive event (which fires after the clone has been inserted into the DOM). At the end of the drag you have to make sure that whatever happens, no elements in your document should have the special class set. It's especially important if you're copying/cloning, as the sortable's receive event fires BEFORE the draggable's stop event (where we remove the special class from our original draggable).
http://jsfiddle.net/3Gkrf/1/
HTML:
CSS:
javascript:
If you just want to create another instance manually whenever dragging stops, that's possible on the draggable's stop event. However, I don't think there is a reliable way in there to detect wether it was dropped on the sortable or somewhere else.
You have to manually clone your object, because even though you set the helper to clone it, the helper gets destroyed whenever dragging stops. If it WAS dropped on a sortable, you might end up with two new objects though, as the sortable automatically clones on receive.