Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I move an item to an empty list using jquery?

Tags:

jquery

I'm working with a demo of two sortable jquery lists... but have a problem when one list is empty, I can no longer drag items onto it, because there is nothing there to drop on. I tried adding space to the margin, padding and line-height of the ul, but nothing seems to work. Any ideas?

<style type="text/css">
#sortable1, #sortable2 {
    list-style-type: none;
    margin: 0;
    padding: 0;
    float: left;
    margin-right: 10px;
}
#sortable1 li, #sortable2 li {
    margin: 0 5px 5px 5px;
    padding: 5px;
    font-size: 1.2em;
    width: 120px;
}
</style>
<script type="text/javascript">
$(function() {
    $("#sortable1, #sortable2").sortable({
        connectWith: '.connectedSortable'
    }).disableSelection();
});
</script>

<ul id="sortable1" class="connectedSortable">
<li class="ui-state-default">Item 1</li>
<li class="ui-state-default">Item 2</li>
<li class="ui-state-default">Item 3</li>
<li class="ui-state-default">Item 4</li>
<li class="ui-state-default">Item 5</li>
</ul>

<ul id="sortable2" class="connectedSortable">
</ul>
like image 707
Adam Morris Avatar asked Feb 25 '10 17:02

Adam Morris


1 Answers

Frederik's answer didnt work for me

solution for me was to add a min-height to the empty ul

ref: http://rolleys.wordpress.com/2010/05/18/cant-get-jquery-sortable-to-drop-on-to-empty-lists/

like image 77
zack Avatar answered Oct 11 '22 13:10

zack