Reputation: 17522
I have the following...
<ul>
<li>Item</li>
<li>Item</li>
<li>Item</li>
</ul>
<ul>
<li>Item</li>
<li>Item</li>
<li>Item</li>
</ul>
<ul>
<li>Item</li>
<li>Item</li>
<li>Item</li>
</ul>
I need to drag each item from one ul
to another, but avoid duplications in the same ul
and just add the item to the dropped ul.
using jQuery i have tried many things but there is always something that messes it up.
any ideas ? thnx
Upvotes: 1
Views: 3707
Reputation: 5194
try to remove duplications before add
$( "li" ).draggable({
appendTo: "ul",
helper: "clone"
});
$( "ul" ).droppable({
activeClass: "ui-state-default",
hoverClass: "ui-state-hover",
accept: ":not(.ui-sortable-helper)",
drop: function( event, ui ) {
$( this ).find( "li:contains('" + ui.draggable.text() + "')" ).remove();
$( "<li></li>" ).text( ui.draggable.text() ).appendTo( this );
}
})
Upvotes: 0
Reputation: 636
This is complicated because you have multiple sortables and it's tricky to get working. I have done it using the sortable controller with the connectTo option specifying the other possible targets.
Upvotes: 0
Reputation: 10490
you could use the jqueryui http://jqueryui.com/demos/sortable/
makes it very easy to dragdrop/resize/drop...
Upvotes: 1