views:

2079

answers:

1

This is my code for a draggable connected to a sortable. The thing is, I am creating an LI with a bunch of attributes. BUT when I drag an item to the droppable div, the sortable creates a new li tag and wraps my created li with it.

It looks something like this:

<ul>
<li class="ui-draggable" style="display: list-item;">
    <li class="X" onclick="myFunc()"> My LI</li>
<li>
</ul>

While my intention is to have something like this:

<ul>
    <li class="X" onclick="myFunc()"> My LI</li>
</ul>

So how do i do this?

And the code:

$(document).ready(function() {

$('.draggable_text > li').draggable({
    helper: function(event, ui) {
        return '<div class="placeholder_sortable">&nbsp</div>'
    },
    connectToSortable:'#stagerows'
});

$('#stagerows').sortable({
    handle: '.drag_handle',
    placeholder: 'placeholder_sortable'
});

/**
 * When item is dropped from the Add <Stuff>
 */
$('#stagerows').droppable({
    drop: function(event, ui){
        return ui.draggable.html('<li class="X" onclick="myFunc()"> My LI</li>')
    }
});

});
+2  A: 

Try using this:

$('#stagerows').droppable({
    drop: function(event, ui){
        return ui.draggable.html('My LI').addClass('X').click( myFunc );
    }
});
tvanfosson
thanks tvanfosson. But by the looks of the code, I would have to remove the li-tags I created. return ui.draggable.html(createHTML()); //the code above, i explicitly added the html to make it more readable.
wenbert