The first part allows you to first drag an element into a sortable div, which is working fine. I then want to have that div become sortable as well so I can drag new elements (parts) into those.
That part works fine too, except sometimes if you reorder the elements (the darker ones) it wont let you put a part back into it until you either reorder them again, or try and put it in one of the other elements and go back to it.
It’s kind of hard to explain, but here’s a screen-cast: http://screencast.com/t/Ls2ksVY4Q
The demo is at: http://jsfiddle.net/9MXWp/
Here’s the relevant code:
$(document).ready(function() {
$('#the-grid').sortable({
tolerance: 'pointer',
update: function(event, ui) {
if( $(ui.item).has('.close').length == 0 ) {
$(ui.item).prepend('<a href="#" class="close" onclick="$(this).parent().remove();">x</a>');
}
$('.part-holder', ui.item).sortable({
tolerance: 'pointer',
update: function(event, ui) {
if( $(ui.item).has('.close').length == 0 )
$(ui.item).prepend('<a href="#" class="close" onclick="$(this).parent().remove();">x</a>');
}
});
}
});
$('#sidebar > ul > li.part').draggable({
helper: 'clone',
connectToSortable: '.part-holder',
addClasses: false
});
$('.drag-element').draggable({
revert: 'invalid',
helper: 'clone',
connectToSortable: '#the-grid',
addClasses: false
});
$('#update-list').click(updateList);
});
Recipe that seems to duplicate the problem (in FF 3.6):
-
Drag Element 1 to the staging area.
-
Drag Element 2 to the staging area; place it before element 1.
-
Drag a Part inside Element 1. ☞ Sometimes the page will fail right here. ☜ ☣
-
Drag a Part inside Element 2.
-
Now drag Element 2 to be after Element 1.
-
☞ Drag a Part inside Element 1; it won’t work. ☜ ☣
-
Drag a Part inside Element 2; it will work, and now Element 1 accepts parts again.
ok lets try this again; i added a ‘connectWith’ option, then wrapped the ‘.part-holder’ sortable initializer so it doesn’t get updated every time the grid is re-ordered…
with those changes, you are able to add the ‘parts’ to the ‘part-holders’! I did see some intermittent js errors… I have no idea why they appear, but they don’t seem to interfere with the operation of the page when viewed with FF 3.6