Reputation: 1194
I have two connected sortables, dragging between these works fine. I needed to drag more than one at a time, so I got that working using the following like, appending selected items to event.item.
$(this).sortable({
connectWith: ".stage-content",
placeholder: 'placeholder',
start: function(ui, e) {
e.item.siblings(".selected").appendTo(e.item);
....
The problem I can't figure out, when not hovering over one of the two drop zones, the placeholder ends up within the elements I am dragging. If you let go at this time, they disappear.
HierarchyRequestError: Node cannot be inserted at the specified point in the hierarchy
Which makes perfect sense, but I do not know what the solution is, any help is appreciated!
http://jsfiddle.net/mstefanko/kxBUG/
Upvotes: 2
Views: 1764
Reputation: 1
You should add $(YOUR SORTABLE OBJECT).sortable( "refresh" )
in start function.
$(this).sortable({
connectWith: ".stage-content",
placeholder: 'placeholder',
start: function(ui, e) {
e.item.siblings(".selected").appendTo(e.item);
$(YOUR SORTABLE OBJECT).sortable( "refresh" );}
...
Upvotes: 0
Reputation: 489
At the bottom is the jsfiddle with an example. Hope this helps.
$(document).ready(function(){
$(".droppable").droppable({
drop: function(event, ui) {
var $list = $(this);
$helper = ui.helper;
$($helper).removeClass("selected");
var $selected = $(".selected");
if($selected.length > 1){
moveSelected($list,$selected);
}else{
moveItem(ui.draggable,$list);
}
}, tolerance: "touch"
});
$(".draggable").draggable({
revert: "invalid",
helper: "clone",
cursor: "move",
drag: function(event,ui){
var $helper = ui.helper;
$($helper).removeClass("selected");
var $selected = $(".selected");
if($selected.length > 1){
$($helper).html($selected.length + " items");
}
}
});
function moveSelected($list,$selected){
$($selected).each(function(){
$(this).fadeOut(function(){
$(this).appendTo($list).removeClass("selected").fadeIn();
});
});
}
function moveItem( $item,$list ) {
$item.fadeOut(function() {
$item.find(".item").remove();
$item.appendTo( $list ).fadeIn();
});
}
$(".item").click(function(){
$(this).toggleClass("selected");
});
});
http://jsfiddle.net/caferdo/k5XJv/3/
Upvotes: 1