Having two lists[A,B,C,D] and [1,2,3,4], I want to provide a user interface for merging them into a new list. In the new list the original order of each list should be maintained. For example any of [A,1,B,2,C,3,D,4]or [A,B,C,D,1,2,3,4]or [A,B,1,C,2,3,4,D]are OK. But [B,A,1,2,3,4,C,D] is not accepted, due to B coming before A.
jQuery UI sortable seems to be a good starting point. But maintaining the original order is not supported (Of course the meaning of sortable is in contrast with my requirement. But the user interface supported with sortable, is very similar to my final goal.)
I think handling receive event and canceling the sort when the order is not maintained, could be the solution. But could not found how to cancel or undo the drag, when receive is complete.
Thanks in advance
you are right. jquery’s sortable will do the trick.
start with using a helper
this won’t drag the item itself but a cloned replica.
next you can use the event “beforeStop” to check the previous and next item.
remember that the appendTo and prependTo and insertAfter and insertBefore function are moving a dom element rather than cloning it. This means this code is valid for playing with the li elements.
html:
jquery:
result: