-
-
Notifications
You must be signed in to change notification settings - Fork 457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Destroy sortable not removing event listeners. #512
Comments
I agree that this is an issue. Could you please send a PR to fix this? |
A fix is to turn off the I'll send a pull request with This does not solve the issue that event listeners are not removed from the sortable element. The 'dragstart' and 'dragend' events are easy to deal with. We can simply add The 'dragenter' listener is problematic. Two listeners are added for 'dragenter'. One in here: addEventListener(sortableElement, 'dragenter', function (e) { var target = getEventTarget(e); var sortableContainer = findSortable(target, e); ... and the second here: addEventListener(listItems.concat(sortableElement), 'dragenter', onDragOverEnter); The callback is stored using the event name element.addEventListener(eventName, callback); store(element).setData("event" + eventName, callback); Which causes one to overwrite the other. Now only one callback can be retrieved for removal element.removeEventListener(eventName, store(element).getData("event" + eventName)); store(element).deleteData("event" + eventName); A fix could be to remove this line altogether. addEventListener(listItems.concat(sortableElement), 'dragenter', onDragOverEnter); Dragging would still be caught by the 'dragover' event listener in the adjacent line. Is there a reason why we need both 'dragover' and 'dragenter'? |
Hey @lachdoug, I would have to look into why this is done this way. It may be a bug but I think there is a reason. However I would appreciate if you could send multiple small PRs, because this makes merging easier and faster. E.g. removing isSortable or setting it to false as suggested (and nothing else), could be one PR that is easy to merge. 'dragstart' and 'dragend' could be a second PR And the last has to be figured out first and could be a third one in the end. Maybe with a bugfix first. |
Will do. |
I'm opening this issue because:
sortable( '.my-list', 'destroy' ) does not remove event listeners for
This causes errors to be logged when using HTML5Sortable with with nested lists.
supporting information:
How can the issue be reproduce the problem?
Codepen example here
On a page with a nested list...
sortable( ?, 'destroy' )
The error message is
TypeError: options is undefined
fromvar items = _filter(sortableElement.children, options.items);
The text was updated successfully, but these errors were encountered: