draggable items stack on top of each other in a sortable
So, I'm not exactly sure if it's an intended behavior based on my code or if it's a bug within jquery-ui. I created two lists as sortable and each list item within those lists as draggable. Whenever I would drag and drop items rapidly, they would end up stacking on top of each other and creating empty spaces within the lists. It did not matter if I was doing dragging and dropping within the list or between the two, the same behavior would be produced.
Here's the code:
- <div id="available-group" class="noselect">
- <h1 class="group-header ui-widget-header">Group 1</h1>
- <ul class="sortable">
- <li class="draggable ui-state-default">Item 6</li>
- <li class="draggable ui-state-default">Item 7</li>
- <li class="draggable ui-state-default">Item 8</li>
- <li class="draggable ui-state-default">Item 9</li>
- <li class="draggable ui-state-default">Item 10</li>
- </ul>
- </div>
-
- <div id="selected-group" class="noselect">
- <h1 class="group-header ui-widget-header">Group 2</h1>
- <ul class="sortable">
- <li class="draggable ui-state-default">Item 1</li>
- <li class="draggable ui-state-default">Item 2</li>
- <li class="draggable ui-state-default">Item 3</li>
- <li class="draggable ui-state-default">Item 4</li>
- <li class="draggable ui-state-default">Item 5</li>
- </ul>
- </div>
- .sortable {
- list-style-type: none;
- margin: 0px 0px 10px 0px;
- padding: 0;
- border: 1px solid black;
- min-height: 40px;
- }
-
- .sortable>li {
- margin: 1px;
- padding: 5px;
- }
-
- #available-group, #selected-group {
- width: 170px;
- user-select: none;
- margin: 10px 150px 10px 0px;
- min-height: 300px;
- float: left;
- }
- $(".sortable").sortable({
- revert: "invalid"
- });
-
- $(".draggable").draggable({
- connectToSortable: ".sortable",
- revert: "invalid"
- });
- Uncaught TypeError: Cannot read property '0' of null
- jquery-ui.js:5679$.widget._clear
- jquery-ui.js:5679(anonymous function)
- jquery-ui.js:415$.widget._mouseStop
- jquery-ui.js:4946(anonymous function)
- jquery-ui.js:415(anonymous function)
- jquery-ui.js:2403jQuery.extend.each
- jquery.js:657$.ui.plugin.add.drag
- jquery-ui.js:2304$.ui.plugin.call
- jquery-ui.js:304$.widget._trigger
- jquery-ui.js:2218(anonymous function)
- jquery-ui.js:415$.widget._mouseDrag
- jquery-ui.js:1799(anonymous function)
- jquery-ui.js:415$.widget._mouseMove
- jquery-ui.js:992(anonymous function)
- jquery-ui.js:415_mouseMoveDelegate
- jquery-ui.js:955jQuery.event.dispatch
- jquery.js:5095elemData.handle
After much contemplating and testing, I was able to fix it by removing revert: "invalid" from sortable:
- $(".sortable").sortable({
- revert: "invalid"
- });
I'm not sure if it's a bug or intended behavior, but after removing that line, everything began functioning as intended.