Skip to main content

Search and Top Navigation

#8180 open bug ()

Opened March 09, 2012 10:12PM UTC

Last modified March 16, 2013 08:22PM UTC

Sortable: Error when there are items in the sortable container that are already a sortable

Reported by: diego.parra@bizagi.com Owned by:
Priority: minor Milestone: 2.0.0
Component: ui.sortable Version: 1.8.18
Keywords: Cc:
Blocked by: Blocking:
Description

In this example --> http://jsfiddle.net/4p8b6/

We configure some containers and items, and apply only the sortable widget to the containers, but one container is also "sortable", so we can move items between all containers.

Everything works ok, except when I move the inner container outside the parent boundaries, then the inner container dissapears and the following exception occur "5779Uncaught Error: HIERARCHY_REQUEST_ERR: DOM Exception 3"

I tried to solve it adding some conditions to _clean method in sortable widget

Original:

if (!this._noFinalSort && this.currentItem[0].parentNode) this.placeholder.before(this.currentItem);

Changed

if (!this._noFinalSort && 
            this.currentItem[0].parentNode && 
            this.currentItem[0].parentNode && 
            this.currentItem[0].parentNode.tagName != null &&
            this.placeholder[0].parentNode[$.expando] != this.currentItem[0][$.expando]) {
                
        this.placeholder.before(this.currentItem);
    }

Hope this helps.

Thanks in advance

Regards

Diego Parra

Attachments (0)
Change History (3)

Changed October 11, 2012 02:56PM UTC by scottgonzalez comment:1

milestone: 1.9.02.0.0

Changed November 04, 2012 09:45PM UTC by petersendidit comment:2

status: newopen

Changed March 16, 2013 08:22PM UTC by tj.vantoll comment:3

summary: Sortable does not work properly when there are items in the sortable container that are already a sortableSortable: Error when there are items in the sortable container that are already a sortable

Updated test case against master: http://jsfiddle.net/tj_vantoll/CPEG8/. Drag the inner container outside of the outer container to see the error.

I can confirm that the error is coming from this line in

_clear
on this line https://github.com/jquery/jquery-ui/blob/44d07173db32b498e5f83f60db290ff1463daee3/ui/jquery.ui.sortable.js#L1155.

The error is occurring because the plugin ends up trying to append the item to itself. To avoid this the following check could be added:

{{{this.placeholder[0].parentNode !== this.currentItem[0]}}

I can't think of any adverse effects of this.