-1

I have a table where every cell in the tbody is a droppable target. In the cells are various draggable divs.

Say a user drags a div around but ends up dropping it back where it started. How can I return false on my 'drop' function if the target is the same as the origin? I.e., how can I determine that the target is the same as the origin? I've been looking for two days and haven't found an answer to this.

EDITED: originally said 'destination' where I meant 'origin'.

Works for a Living
  • 1,262
  • 2
  • 19
  • 44

1 Answers1

0

I worked it out myself. You have to get the origin from a start function on the draggable, then check against that in the drop function on the droppable.

var origincell;
$('body').on('dragstart', '.my-drag', function(event, ui){
    origincell = $(event.currentTarget).parents('td').eq(0).attr('id'); 
}).on('drop', 'td.my-drop', function(event, ui){
    if(origincell == $(event.currentTarget).attr('id'))
    {
        ui.draggable.css({top: 0, left: 0});
        return false;
    }
    // continue with other drop function stuff
});
Works for a Living
  • 1,262
  • 2
  • 19
  • 44