From b18b9aecd81459a2a16581119804770d2448572f Mon Sep 17 00:00:00 2001 From: Igor Vaynberg Date: Mon, 26 Mar 2012 23:45:08 -0700 Subject: [PATCH] support removing elements that have non-numeric ids --- select2.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/select2.js b/select2.js index bc5a1e08..f5114d29 100755 --- a/select2.js +++ b/select2.js @@ -65,6 +65,24 @@ } }; + function indexOf(value, array) { + var i = 0, l = array.length, v; + + if (value.constructor === String) { + for (; i < l; i++) if (value.localeCompare(array[i]) === 0) return i; + } else { + for (; i < l; i++) { + v = array[i]; + if (v.constructor === String) { + if (v.localeCompare(value) === 0) return i; + } else { + if (v === value) return i; + } + } + } + return -1; + } + function getSideBorderPadding(element) { return element.outerWidth() - element.width(); } @@ -970,7 +988,7 @@ throw "Invalid argument: " + selected + ". Must be .select2-search-choice"; } - index = val.indexOf(selected.data("select2-data").id); + index = indexOf(selected.data("select2-data").id, val); if (index >= 0) { val.splice(index, 1);