Skip to content

Commit b18b9ae

Browse files
committed
support removing elements that have non-numeric ids
1 parent 339c7a8 commit b18b9ae

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

select2.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,24 @@
6565
}
6666
};
6767

68+
function indexOf(value, array) {
69+
var i = 0, l = array.length, v;
70+
71+
if (value.constructor === String) {
72+
for (; i < l; i++) if (value.localeCompare(array[i]) === 0) return i;
73+
} else {
74+
for (; i < l; i++) {
75+
v = array[i];
76+
if (v.constructor === String) {
77+
if (v.localeCompare(value) === 0) return i;
78+
} else {
79+
if (v === value) return i;
80+
}
81+
}
82+
}
83+
return -1;
84+
}
85+
6886
function getSideBorderPadding(element) {
6987
return element.outerWidth() - element.width();
7088
}
@@ -970,7 +988,7 @@
970988
throw "Invalid argument: " + selected + ". Must be .select2-search-choice";
971989
}
972990

973-
index = val.indexOf(selected.data("select2-data").id);
991+
index = indexOf(selected.data("select2-data").id, val);
974992

975993
if (index >= 0) {
976994
val.splice(index, 1);

0 commit comments

Comments
 (0)