I have a list of draggable items that can be dragged into a sortable and rearranged. I have that bit working ok.
What I am now trying to do is to add a delete link to each item once it has been dropped. The code I currently have fires twice so I get to delete links for each item and I can't figure out why.
Here's the code:
$(function () {
var order = null;
$("#sortable")
.sortable({
revert: true,
placeholder: "ui-state-highlight"
})
.droppable({
drop: function (event, ui) {
addControls(ui.draggable);
}
});
$(".draggable").draggable({
connectToSortable: "#sortable",
helper: "clone",
revert: "invalid"
});
$("ul, li").disableSelection();
});
function addControls($item) {
$item.append('<a href="#">delete</a>');
}
There's a JS fiddle here to play with: http://jsfiddle.net/2X7zk/