I am working off of a Draggable example where you can drag a copies of one element into a sortable list of other elements. What I want to do is assign every new element dragged into the list an ID so that they can be distinguished from one another. The problem seems to be that when you start moving these elements around, it looks like you are dragging that element, but in actuality you are dragging a spawned helper that just looks like it. Initially I was setting newly placed elements' IDs on Sortable stop
model = [];
$( "#sortable" ).sortable({
revert: true,
stop: function(event, ui){
ui.item[0].id = id++;
model.push(id);
}
console.log(model);
}
});
In this case the html element stored in the ui.item[0] was the element that will be kept in the list, and not its helper clone. The issue is, as I said before, the moment you try to move it again, this element seems to be destroyed and a new one will be created. The new element will be given a new ID and any functionality I had tied to that original ID elsewhere will now break because the selector will be incorrect. I could set a temporary variable to hold the ID while I am dragging within sortable, or I could perpetuate the new ID through my project, but I am hoping that Sortable already has something built in. Does Sortable have a way to deal with this cloning issue?
My code is available in this plunker.