Skip to content

Commit f165c93

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.
1 parent cf0c32f commit f165c93

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
@@ -377,21 +377,23 @@ $.widget("ui.sortable", $.ui.mouse, {
377377

378378
}
379379

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

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

397399
return this;

0 commit comments

Comments
 (0)