Saif
Saif

Reputation: 7042

Jquery UI Draggable clone disappearing

I am trying to use the jquery-ui draggable to make some element draggable. I set the helper option to clone the current element.
It's making the clone correctly but when I drop the clone disappears. It doesn't stay at the dragged place.

See this for Demo Fiddle Link

$('#drag').draggable({
helper: function (e, ui) {
    return $(this).clone();
}
});

What am I missing ?

Upvotes: 0

Views: 4280

Answers (2)

Julien Grégoire
Julien Grégoire

Reputation: 17124

There maybe a simpler way, but through data of draggable, you can target a property that deals with this. Like this:

stop : function(e, ui){
         $('#drag').draggable().data()["ui-draggable"].cancelHelperRemoval = true;
    }

fiddle: http://jsfiddle.net/n10ucrLd/

Upvotes: 7

uglycode
uglycode

Reputation: 3082

I think there's been a lot of troubles with helper: 'clone'. I always got it to work, when I defined a droppable as well. E.g.:

HTML:

<div id="drag">Drag This</div>
<div class="container"></div>

JavScript:

$('#drag').draggable({
helper: function (e, ui) {
    return $(this).clone(true);
}
});

 $( ".container" ).droppable({
    drop: function (event, ui) {
       ui.draggable.clone().appendTo($(this)).draggable();
    }
 });

Live example: http://jsbin.com/vibeqaganu/1/edit?html,css,js,output

Upvotes: 3

Related Questions