I'm trying to set a specific functionality using jquery sortable. I seem to be close but hitting an issue. I need the subitems to move to level 3 positions only - under the account types
http://jsfiddle.net/Davos8549/x6f0upng/1/
I only want the sub items to be able to drag - drop into other lists that has the class="hasItems"
I should still be able to move AR, VZ, BANK within its main container "Asset". But i should not be able to drop the whole thing into a sublist (which is the problem i'm having now).
Asset
AR
subitem2-1
subitem3-15
subitem3-25
subitem2-2
subitem2-3
subitem2-4
VZ
subitem3-1
subitem3-2
subitem1-35
subitem3-3
subitem3-4
Bank
subitem1-1
subitem1-2
subitem3-45
subitem1-3
subitem1-4
Liability
Bank5
subitem1-15
subitem1-25
subitem1-45
AR5
subitem2-15
subitem2-25
subitem2-35
subitem2-45
VZ5
subitem3-35
I believe the solution could be in this code:
<script>
$(function() {
$('ul.mainlist').sortable({
connectWith: 'ul.mainlist',
beforeStop: function(ev, ui) {
if ($(ui.item).hasClass('hasItems') && $(ui.placeholder).parent()[0] != this) {
$(this).sortable('cancel');
}
}
});
$('ul.sublist').sortable({
connectWith: 'ul.sublist'
});
});
</script>