Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Sortable: Fix a bug of removing an item while iterating an array #727

Closed
wants to merge 1 commit into from

2 participants

@zhizhangchen

No description provided.

@scottgonzalez

As mentioned in your other pull request, we need bug reports and reduced test cases before pull requests.

@zhizhangchen

Problem: in some cases, iterating this.items will cause out of range problem, for example:
http://jsfiddle.net/7zT9C/2/
If you try to drag the $('.sortable.sortableItem'), there will be an error message in console:
Uncaught TypeError: Cannot read property 'item' of undefined

Solution:
http://jsfiddle.net/MLghp/1/

Should I open a bug report in http://bugs.jqueryui.com ?

@scottgonzalez

Thanks for the test case. If you can file a bug on that bug tracker, I'll update your commit message to reference the ticket and land your patch.

@scottgonzalez

Thanks, landed in 77a4aaf. Sorry for the delay, we had to get 1.9.0 out first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 5 additions and 6 deletions.
  1. +5 −6 ui/jquery.ui.sortable.js
View
11 ui/jquery.ui.sortable.js
@@ -562,14 +562,13 @@ $.widget("ui.sortable", $.ui.mouse, {
var list = this.currentItem.find(":data(" + this.widgetName + "-item)");
- for (var i=0; i < this.items.length; i++) {
-
+ this.items = $.grep(this.items, function (item) {
for (var j=0; j < list.length; j++) {
- if(list[j] == this.items[i].item[0])
- this.items.splice(i,1);
+ if(list[j] == item.item[0])
+ return false;
};
-
- };
+ return true;
+ });
},
Something went wrong with that request. Please try again.