I have two lists. The goal is to drag items from the first list into the second list. I have stored the correct order in the data attribute.
<ul class="connectedSortable ui-sortable" id="sortable1">
<li data-pos="4" class="ui-sortable-handle">item a</li>
<li data-pos="3" class="ui-sortable-handle">item b</li>
<li data-pos="1" class="ui-sortable-handle">item c</li>
<li data-pos="2" class="ui-sortable-handle">item d</li>
<li data-pos="5" class="ui-sortable-handle">item e</li>
<li data-pos="6" class="ui-sortable-handle">item f</li>
</ul>
<ul class="connectedSortable ui-sortable" id="sortable1">
<li data-pos="0" class="ui-sortable-handle">top item</li>
<li data-pos="7" class="ui-sortable-handle">bottom item</li>
</ul>
When the second list is changed, I loop over the items to see if they are in the correct order:
$("#sortable2").sortable({
change: function () {
var solved = false;
console.log("-----------");
//:not(.ui-sortable-placeholder)
$.each($("#sortable2 .ui-sortable-handle"), function (key, val) {
console.log("item key: " + key + " - data: " + $(val).data('pos'));
});
}
});
When I drag the first item over, the output will read:
item key: 0 - data: 0
item key: 1 - data: undefined
item key: 2 - data: 8
But I can see in the source code that there are three items in the list. Subsequent drag&drops will show the correct index, with the first still not showing in the loop. I tried to exclude the placeholder from the loop, with no luck.
ul>in given markup has the sameidofsortable1and in script you've specified#sortable2Obviously it'll not work as well as it's invalid markup. I wonder how you're saying it's working..!