Ticket #6054 (open bug)

Opened 4 years ago

Last modified 13 months ago

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:
Blocking: Blocked by:

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

Change History

comment:1 follow-up: ↓ 2 Changed 3 years ago by scott.gonzalez

Can you provide an example of when this occurs?

comment:2 in reply to: ↑ 1 Changed 3 years ago by tos1121

Replying to scott.gonzalez:

Can you provide an example of when this occurs?

Yes, This is the sample program.

 http://jsfiddle.net/jjgYf/

comment:3 follow-up: ↓ 4 Changed 3 years ago by scott.gonzalez

  • Owner set to tos1121
  • Status changed from new to pending

I'm not seeing any errors in the example.

comment:4 in reply to: ↑ 3 Changed 3 years ago by tos1121

  • Status changed from pending to new

Replying to 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.

comment:5 Changed 3 years ago by tranver

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)

comment:6 Changed 3 years ago by scott.gonzalez

#7560 is a duplicate of this ticket.

comment:7 Changed 2 years ago by jdmarshall

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.

comment:8 Changed 23 months ago by scott.gonzalez

#8340 is a duplicate of this ticket.

comment:9 Changed 19 months ago by scott.gonzalez

  • Milestone changed from TBD to 2.0.0

comment:10 Changed 18 months ago by mikesherov

  • Status changed from new to open
  • Summary changed from "this.placeholder[0].parentNode is null" on sortable line 1032 to Sortable: "this.placeholder[0].parentNode is null"

comment:11 Changed 14 months ago by tj.vantoll

  • Summary changed from Sortable: "this.placeholder[0].parentNode is null" to 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]);

comment:12 Changed 14 months ago by tj.vantoll

#7977 is a duplicate of this ticket.

comment:13 Changed 13 months ago by mebur

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]) {
Note: See TracTickets for help on using tickets.