Drag From Sortable To Droppable?
Solution 1:
The question is, what do you want to do with the element once it is dropped?
For example, if you want to remove the element when it is dropped, like the trashcan example, your drop function looks like this:
$("#drop_zone").droppable({
accept: ".connectedSortable li",
hoverClass: "ui-state-hover",
drop: function(ev, ui) {
$(ui.draggable[0]).remove();
}
});
I've included an updated jsFiddle for you: http://jsfiddle.net/LrVMw/5/
Documentation on the drop event: http://api.jqueryui.com/droppable/#event-drop
If it is something else you want, then let me know.
EDIT
To remove the element from the list and add it to a list of the dropzone, you just have to add 1 line to the drop function:
$("#drop_zone").droppable({
accept: ".connectedSortable li",
hoverClass: "ui-state-hover",
drop: function (ev, ui) {
$("<li></li>").text(ui.draggable.text()).appendTo(this); // It's this line
ui.draggable.remove();
}
});
Edited jsFiddle: http://jsfiddle.net/LrVMw/8/
EDIT 2
Instead of just getting the text from the li
element that is dropped, we will get the full html of it, just abit of tweaking gives:
$("#drop_zone").droppable({
accept: ".connectedSortable li",
hoverClass: "ui-state-hover",
drop: function (ev, ui) {
$("<li></li>").html(ui.draggable.html()).appendTo(this);
ui.draggable.remove();
}
});
And the jsFiddle: http://jsfiddle.net/LrVMw/9/
Post a Comment for "Drag From Sortable To Droppable?"