0

This is basically a followup question to this, as it is not encouraged to ask further questions in the comments: Draggable revert if outside this div and inside of other draggables (using both invalid and valid revert options)

This solution works rather well even though my use case is not exactly the same. There is just one small visual thing that bothers me. I have rather large draggable objects, so I am using a helper for it. No matter if the drop is valid or not, the helper still has a revert animation on it: If it is an invalid drop, the helper moves to the original position before it fades away, which is fine. But if it is a valid drop it does the same whereas the original gets moved to the valid position. Any ideas how I could prevent this.

Here a short snippet of the helper definition:

helper: function() {
    var jqThis = jQuery(this);
    var helper = jQuery('<div class="helper"/>');
    helper.text(jqThis.text().substr(0, 100));
    helper.css('width', jqThis.css('width'));
    return helper;
}
Community
  • 1
  • 1
Thomas
  • 6,325
  • 4
  • 30
  • 65

1 Answers1

0

I just figured it out: I have to set the option back to "invalid" if it is a valid drop.

if (invalidDrop) {
    drag.draggable('option','revert',true);
} else {
    drag.draggable('option','revert','invalid');
}
Thomas
  • 6,325
  • 4
  • 30
  • 65