Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery ui.draggable event/status on revert

Is there a way to get information if an element that's draggable is reverted?

I'm stuck on this. I want to make an element droppable again, but only if the draggable that was lying there is moved elsewhere (meaning doesn't revert).

like image 279
flos Avatar asked Dec 05 '09 19:12

flos


1 Answers

I found out that there is away to get information about whether an object has reverted or not. It's built into jQuery but not that well documented apparently.

Essentially it's done via using a callback function for the revert option of a draggable object.

Something like the following:

$(".myselector").draggable(
{
  revert: function(droppableObj)
  {
     //if false then no socket object drop occurred.
     if(droppableObj === false)
     {
        //revert the .myselector object by returning true
        return true;
     }
     else
     {
        //droppableObj was returned,
        //we can perform additional checks here if we like
        //alert(droppableObj.attr('id')); would work fine

        //return false so that the .myselector object does not revert
        return false;
     }
  }
});

See http://www.agilepro.com/blog/2009/12/while-this-functionality-is-built-into.html for more details.

like image 93
mbeedub Avatar answered Sep 28 '22 00:09

mbeedub