Skip to main content

Bug Tracker

Side navigation

#13907 closed bug (notabug)

Opened May 17, 2013 06:33PM UTC

Closed May 20, 2013 02:31PM UTC

Last modified May 20, 2013 03:52PM UTC

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

Reported by: brett@fogcreek.com Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 2.0.0
Keywords: Cc: scott_gonzalez
Blocked by: Blocking:
Description

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:

http://jsfiddle.net/8Qe8T/4/

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.

Attachments (0)
Change History (5)

Changed May 17, 2013 08:12PM UTC by dmethvin comment:1

cc: → scott_gonzalez

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?

Changed May 20, 2013 01:49PM UTC by anonymous comment:2

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.

Changed May 20, 2013 02:13PM UTC by scottgonzalez comment:3

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

This is a valid use. I've reduced the fiddle and added a call to sortable's .refresh() method: http://jsfiddle.net/8Qe8T/9/

Changed May 20, 2013 02:31PM UTC by scottgonzalez comment:4

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/

Changed May 20, 2013 03:52PM UTC by anonymous comment:5

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.