Skip to main content

Search and Top Navigation

#6054 open bug ()

Opened September 16, 2010 04:04AM UTC

Last modified August 04, 2015 09:58AM UTC

Sortable: cancel method cannot be called in a beforeStop event handler

Reported by: tos1121 Owned by: tos1121
Priority: minor Milestone: 2.0.0
Component: ui.sortable Version: 1.8.4
Keywords: parentNode Cc:
Blocked by: Blocking:
Description

line 1032 on "jquery.ui.sortable.js"

this.placeholder[0].parentNode is null in some condition.

[WRONG]

this.placeholder[0].parentNode.removeChild(this.placeholder[0]);

[RIGHT]

if(this.placeholder[0].parentNode)

this.placeholder[0].parentNode.removeChild(this.placeholder[0]);

thank you!


Node.parentNode(Mozilla develop center)

https://developer.mozilla.org/En/DOM/Node.parentNode

Attachments (0)
Change History (15)

Changed January 19, 2011 04:03PM UTC by scottgonzalez comment:1

Can you provide an example of when this occurs?

Changed January 19, 2011 11:06PM UTC by tos1121 comment:2

Replying to [comment:1 scott.gonzalez]:

Can you provide an example of when this occurs?

Yes, This is the sample program.

http://jsfiddle.net/jjgYf/

Changed January 20, 2011 04:23AM UTC by scottgonzalez comment:3

owner: → tos1121
status: newpending

I'm not seeing any errors in the example.

Changed January 20, 2011 05:29AM UTC by tos1121 comment:4

status: pendingnew

Replying to [comment:3 scott.gonzalez]:

I'm not seeing any errors in the example.

I'm sorry, I mistook to tell you #6873 and #6054.


「Table header sorting on Chrome break layout」 

http://bugs.jqueryui.com/ticket/6873

I'll comment later about this topic.

Changed July 13, 2011 01:54PM UTC by tranver comment:5

This issue still exists. I've created a simple test case at http://jsfiddle.net/zVpn5/1/

Tested with the following browsers:

  • Google Chrome 12.0.742.122 (Windows 7)
  • Firefox 5.0 (Windows 7, Mac OSX)

Changed July 18, 2011 12:09PM UTC by scottgonzalez comment:6

#7560 is a duplicate of this ticket.

Changed January 14, 2012 12:26AM UTC by jdmarshall comment:7

Based on a comment on http://forum.jquery.com/topic/problem-with-sortable-4-10-2010 I was able to narrow this down a bit.

If you provide a beforeStop callback, and the callback returns false (for instance, to disallow a drag operation based on business rules), this error will happen. Additionally, since there is no error handling in this code, once the error happens stop() is never called. This makes it very challenging to hook behavior on the beginning/end of drag operations.

There is a workaround. If beforeStop() has no return value, everything appears to work as expected. Simply using stop() for the whole operation may not suffice because some fields (eg, ui.helper) get cleared between these two calls. In that case, if you perform your checks in beforeStop() and return the value from stop(), then you can still cancel the actions, and you don't get the error.

Changed June 01, 2012 09:34PM UTC by scottgonzalez comment:8

#8340 is a duplicate of this ticket.

Changed October 11, 2012 09:07PM UTC by scottgonzalez comment:9

milestone: TBD2.0.0

Changed November 06, 2012 03:21AM UTC by mikesherov comment:10

status: newopen
summary: "this.placeholder[0].parentNode is null" on sortable line 1032Sortable: "this.placeholder[0].parentNode is null"

Changed March 11, 2013 02:00AM UTC by tj.vantoll comment:11

summary: Sortable: "this.placeholder[0].parentNode is null"Sortable: cancel method cannot be called in a beforeStop event handler

Test case against master - http://jsfiddle.net/tj_vantoll/dk9A4/.

The issue only occurs if you call the

cancel
method in a
beforeStop
event handler so I'm changing the description to be more indicative of the problem.

The error occurs on this line of the

_clear
method:

this.placeholder[0].parentNode.removeChild(this.placeholder[0]);

Changed March 11, 2013 02:11AM UTC by tj.vantoll comment:12

#7977 is a duplicate of this ticket.

Changed March 25, 2013 01:02PM UTC by mebur comment:13

in IE8 the following statement fails:

if(this.helper[0] !== this.currentItem[0]) {

and needs to be changed to:

if(this.helper!==null && this.helper[0] !== this.currentItem[0]) {

Changed July 22, 2014 02:42PM UTC by scottgonzalez comment:14

#10328 is a duplicate of this ticket.

Changed August 04, 2015 09:58AM UTC by clinisbut comment:15

I'm also experiencing this bug.

In my case I'm just returning a false from beforeStop callback so

''The issue only occurs if you call the cancel method in a beforeStop event handler so I'm changing the description to be more indicative of the problem.''

while it is true, it also happens because returning false from beforeStop makes jQueryUI call the cancel method internally.

The point is _clear method is trying to remove the placeholder parent without checking if this parent still exists:

//$(this.placeholder[0]).remove(); would have been the jQuery way - unfortunately, it unbinds ALL events from the original node!
this.placeholder[0].parentNode.removeChild(this.placeholder[0]);

A simple check would fix this.

if (this.placeholder[0].parentNode) {
    //$(this.placeholder[0]).remove(); would have been the jQuery way - unfortunately, it unbinds ALL events from the original node!
    this.placeholder[0].parentNode.removeChild(this.placeholder[0]);
}