See the code here on jsbin. I'm basically trying to create a series of switches. Each filled red square can be dragged up and down. The red outlines on the bottom are drop zones. When a square is dragged over a drop zone that is eligible to accept it the drop zone should turn pink.
There are two problems with this code. One is that while the motion of the toggles is constrained to the y-axis, they can still be dropped on any drop zone. Click and drag a toggle and slide around the bottom row and you'll see the drop zones turn pink even though the toggle stays in place.
Which leads to the second problem. To address this issue I tried to use the scope option, which groups drags and drops. A drag can only drop on a drop zone with the same scope. In the above example the lines that add scope are commented out. The scope for each drag and drop is "Default."
If you uncomment those two lines (click the tab in the upper right if you're new to jsbin, then click preview after a change) you'll see that instead of restricting each drag to one drop zone, they can no longer drop on any drop zone. The callback function never fires.
For convenience, here is the javascript portion of the example:
$(document).ready( function() {
var draggables = $('div.dragMe'),
droppables = $('div.dropMe');
draggables.draggable(
{
axis: 'y',
containment: 'parent'
});
droppables.droppable(
{
hoverClass: 'dropped',
drop: dropCallBack
});
draggables.each(function(index) {
//$(this).draggable('option', 'scope', ''+index);
//droppables.eq(index).droppable('option', 'scope', ''+index);
$(this).text( $(this).draggable('option', 'scope') )
droppables.eq(index).text( droppables.eq(index).droppable('option', 'scope') );
});
function dropCallBack(e, ui) {
alert('Dropped!');
}
});