Reputation: 40675
I have draggable list of < li > elements which I'm able to drag into another empty < ul > element. If I drag the first < li > element of the draggable original < ul > everything works fine...
Problem:
...but when I drag any other < li > element of that list the 'helper' moves away from the mouse pointer as soon as I cross the border of the recieving sortable < ul >. More precicely it moves up to the top of the list.
Has anyone seen this and knows a solution? Well, my problem is, I'm just using jquery, not really deeply into it and never really used javascript in depth either.
More info about the problem:
My jQuery code:
$(document).ready(function() {
$('#roleList > li').draggable({
connectToSortable: '#roleDrop',
containment: '#container',
revert: 'invalid'
});
$('#roleDrop').sortable({
cursor: 'move',
containment: '#container',
revert: true,
update: function() {
var order = $('#roleDrop').sortable('serialize');
$.ajax({
type: 'POST',
url: '".$postUrl."',
dataType: 'html',
data: order
});
}
});
$('#roleList').disableSelection();
});
While #roleList and #roleDrop are the aforementioned unordered lists, #container is a table.
Now a screenshot of what happens.
I start dragging the item:
When I cross the border of the second < ul > the helper jumps up.
If you need the xhtml markup too, please tell me.
Upvotes: 5
Views: 4277
Reputation: 14644
Try adding helper: 'clone'
to your .draggable
options:
$('#roleList > li').draggable({
helper: 'clone',
connectToSortable: '#roleDrop',
containment: '#container',
revert: 'invalid'
});
According to the jQuery documentation, you should set this option when connecting a draggable to a sortable.
While this yields a different interface experience (dragged items are cloned instead of moved), it's at least a temporary workaround for what the documentation implies is a known problem. Additional event handling could clean the original item out of #roleList
during the #roleDrop
update callback.
Upvotes: 9