Skip to main content

Search and Top Navigation

#3541 closed bug (fixed)

Opened November 06, 2008 12:52AM UTC

Closed November 24, 2008 01:49PM UTC

Last modified January 17, 2010 06:00AM UTC

Events removed on sortable elements

Reported by: antin Owned by: paul
Priority: critical Milestone: 1.7
Component: ui.sortable Version: 1.6rc2
Keywords: sortable event lost removed Cc:
Blocked by: Blocking:
Description

This bug is related to ticket #3023 which has been marked as closed. I have also attached the description to that ticket.

The issue is that once a sortable element has been dragged it removes all events that were bound via jquery for all children of the sorted element.

For example with the following html:

<ul>
 <li>
    <a>One</a>
 </li>
 <li>
    <a>Two</a>
 </li>
</ul>

The issue only arises when the events are bound to any child of the items being sorted (in the example above if you use jquery to bind a click event to the li then the event will be preserved after sort, however if you bind a click event to the a tag then it will be lost). This bug was introduced into jquery ui when the createPlaceholder function was reworked.

The issue is in the createPlaceholder function (line 306 in my version):

el.innerHTML = self.currentItem[0].innerHTML;

Previous versions of the createPlaceholder function merely placed an empty div, whereas the new version copies all the nested elements across. The issue arises once the element is dragged, when the clear function is called and the placeholder is removed from the dom (line 733):

this.placeholder.remove();

The issue is that the 'expando' attribute that jquery uses to tag elements gets copied across to the temporary placeholder element, and then when remove is called jquery finds that an event was bound for the same id and mistakenly deletes it from the real element.

Commenting out the offending line in createPlaceholder fixes the issue, alternatively when the innerHTML is copied all expando attributes could be stripped.

Attachments (0)
Change History (3)

Changed November 06, 2008 03:14AM UTC by scottgonzalez comment:1

component: ui.coreui.sortable
milestone: TBD1.6
priority: majorcritical

Changed November 24, 2008 01:42PM UTC by paul comment:2

The issue can only be reproduced in IE - it seems to copy all DOM attributes as raw html attributes when using innerHTML :/

Changed November 24, 2008 01:49PM UTC by paul comment:3

resolution: → fixed
status: newclosed

Fixed in r1002 by an ugly regex that removes the expando attribute.