Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I prevent multiple jQuery UI droppables from being triggered?

I have a jQuery UI draggable and several separately-defined droppables. Because one of the droppables is configured tolerance: 'intersect', it's possible for a draggable to be dropped on more than one kind of droppable at the same time.

What's the best way to prevent the unintended droppables from firing? Basically, I'd like to prioritize the droppables so that the droppables with tolerance: 'intersect' don't get triggered if another droppable was triggered.

Update - More info to clarify things:

  • All of the droppables are configured tolerance: 'pointer' except for one class of droppable with tolerance: 'intersect'.

  • The reason one class of droppable has tolerance: 'intersect' is that the droppables are really narrow, and users have problems finding them with tolerance: 'pointer'.

  • Moving the droppables further apart isn't an option.

  • None of the droppables overlap, but the draggable is large enough to overlap a droppable with tolerance: 'intersect' while the mouse pointer is over another droppable with tolerance: 'pointer'. At most two droppables can be triggered at once in this way.

  • The UI is laid out so the user's intentions can be determined by ignoring the tolerance: 'intersect' droppable if another droppable has been triggered; i.e. if the user moved the mouse pointer over a droppable with tolerance: 'pointer', it's safe to assume that he/she intended to drop it there. Problem is, I can't figure out how to ignore the unwanted droppable.

like image 465
bryan Avatar asked Aug 18 '09 06:08

bryan


2 Answers

In over:, assign a class to the intended droppable and remove the class from all other droppables:

$(".dragArea").not($(this)).removeClass("dragHover");
$(this).addClass("dragHover");

Then in drop:, check if the class is set:

if(!$(this).is('.dragHover')){
    return false;
}

This way, only one droppable is triggered.

like image 168
alingex Avatar answered Nov 15 '22 07:11

alingex


Maybe in the over event of the "less preferred" droppable you could check if the draggable is also over the "preferred" droppable and if it is disable the "less preferred" droppable.

Sorry for the terminology, just trying to brainstorm.

like image 27
Andy Gaskell Avatar answered Nov 15 '22 05:11

Andy Gaskell