Skip to content

Commit 1ce8cf8

Browse files
marcos.sousascottgonzalez
marcos.sousa
authored andcommitted
Sortable: Make sure we have a placeholder before trying to remove it during a cancel. Fixes #6879 - Sortable: Calling cancel when there is no sort occurring throws an error.
(cherry picked from commit f165c93)
1 parent 465c4c2 commit 1ce8cf8

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

ui/jquery.ui.sortable.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -378,21 +378,23 @@ $.widget("ui.sortable", $.ui.mouse, {
378378

379379
}
380380

381-
//$(this.placeholder[0]).remove(); would have been the jQuery way - unfortunately, it unbinds ALL events from the original node!
382-
if(this.placeholder[0].parentNode) this.placeholder[0].parentNode.removeChild(this.placeholder[0]);
383-
if(this.options.helper != "original" && this.helper && this.helper[0].parentNode) this.helper.remove();
384-
385-
$.extend(this, {
386-
helper: null,
387-
dragging: false,
388-
reverting: false,
389-
_noFinalSort: null
390-
});
381+
if (this.placeholder) {
382+
//$(this.placeholder[0]).remove(); would have been the jQuery way - unfortunately, it unbinds ALL events from the original node!
383+
if(this.placeholder[0].parentNode) this.placeholder[0].parentNode.removeChild(this.placeholder[0]);
384+
if(this.options.helper != "original" && this.helper && this.helper[0].parentNode) this.helper.remove();
385+
386+
$.extend(this, {
387+
helper: null,
388+
dragging: false,
389+
reverting: false,
390+
_noFinalSort: null
391+
});
391392

392-
if(this.domPosition.prev) {
393-
$(this.domPosition.prev).after(this.currentItem);
394-
} else {
395-
$(this.domPosition.parent).prepend(this.currentItem);
393+
if(this.domPosition.prev) {
394+
$(this.domPosition.prev).after(this.currentItem);
395+
} else {
396+
$(this.domPosition.parent).prepend(this.currentItem);
397+
}
396398
}
397399

398400
return this;

0 commit comments

Comments
 (0)