I have a list of elements that can be dropped into a list of (existing) sortables.
When a droppable element is dropped into the sortables, I want to modify the element. I do this by calling the drop event of droppable.
But it seems this drop event is also fired when the sortable elements are sorted inside sortable. And I only want to modify the dropped element when dropped-in from the outside.
$('#sortable').sortable().droppable({
// Drop should only fire when a draggable element is dropped into the sortables,
// and NOT when the sortables themselves are sorted (without something being dragged into).
drop: function(ev, ui){
$(ui.draggable).html('<div>TEMPLATE</div>');
}
});
$('#draggables li').draggable({
connectToSortable: '#sortable',
helper: 'clone',
revert: 'invalid',
cursor: 'move'
});
How can I modify a dropped-in element without modifying them when sorted inside of sortable?
I just ran into the same issue from a different angle. My
sortable/droppablewas firing off anoverevent and adropevent when all I wanted was thedropevent. Using your code, here’s how I fixed it:The only disadvantage is that all functionality within the
sortable.updateevent must now be placed in thedroppable.dropevent.