1

I am using draggable and droppable features of jquery-ui. I need to identify whether revert has happened.
Is it possible to trap whether "revert" has happened or not?

Bharat Patil
  • 1,398
  • 1
  • 11
  • 28

1 Answers1

0

Feels a bit hacky, but a possible solution would be the following:

    $("#draggable").draggable({ revert: function(){if($('#droppable').hasClass('logRevert') == true){
            $('#droppable').removeClass('logRevert'); return false; 
    } 
else{
/*Your Code here*/
return true;
} 
});

revert accepts a function, so we only return true, if the draggable is not accepted, for whatever reason.

Now to make this work, we have to add our .logRevert-class when an acceptable draggable is above the droppable. After it drops and doesn't get reverted, it removes the helper-class .logRevert. You can now always add code to the return

$("#droppable").droppable({
    accept: '#draggable',
    over: function(event, ui){$(this).addClass('logRevert');},
    drop: function(event, ui) {
        $(this).addClass('ui-state-highlight').find('p').html('Dropped!');
    }
});

Derived from Nick Craver's answer on: jQuery draggable revert based on condition

Community
  • 1
  • 1
Semyazas
  • 2,101
  • 14
  • 14