Bug Tracker

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#13907 closed bug (notabug)

jQuery 2.0.0 breaks jQuery-ui sortable when items are removed and re-added to the sortable

Reported by: [email protected] Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 2.0.0
Keywords: Cc: scott_gonzalez
Blocked by: Blocking:


Our application uses jQuery UI Sortable and removes elements from the sortable container and re-adds them as part of our render process. With jQuery 1.9.1, this works fine - here is a demonstration using the sortable demo and jQuery 1.9 in jsfiddle: http://jsfiddle.net/8Qe8T/3/

With jQuery 2.0.0, the first drag after the remove/re-add fails, and subsequent drags succeed. It seems as though other handlers are affected, as well:


The changeset that breaks this is the rewrite of data.js at https://github.com/jquery/jquery/commit/7f94a5cc3a167a710576c008da2c186a98ce2dd4

It seems like there is something new and undesirable happening with remove and event handlers, and that the effects will probably not be confined to sortables.

Change History (5)

comment:1 Changed 10 years ago by dmethvin

Cc: scott_gonzalez added

When you .remove() elements from the document it destroys all data and events attached. Seems likely that an initialized sortable has stuff that shouldn't be removed. When I use .detach() the example seems to work fine.

I'd be curious as to why the behavior changed but first I'd like to know if this example is valid or not. Scott do you want to weigh in?

comment:2 Changed 10 years ago by anonymous

But the mousedown handler is on the container, not the elements within the container, and that's what appears to not be triggered on the first drag.

comment:3 Changed 10 years ago by scottgonzalez

This is a valid use. I've reduced the fiddle: http://jsfiddle.net/8Qe8T/8/

Version 0, edited 10 years ago by scottgonzalez (next)

comment:4 Changed 10 years ago by scottgonzalez

Resolution: notabug
Status: newclosed

My reduced test case was missing an .end() for the .appendTo(). This is working fine when calling sortable( "refresh" ): http://jsfiddle.net/8Qe8T/10/

comment:5 Changed 10 years ago by anonymous

Ah, okay, so the fact that this worked without needing a call to 'refresh' prior to jQuery 2.0.0 would fall into the 'happened to work' rather than the 'supposed to work' category.

Note: See TracTickets for help on using tickets.