From 66778fdc554f3a57aead23d0460d191326fe7d2e Mon Sep 17 00:00:00 2001 From: Alexandr Litovchenko Date: Sat, 6 Jun 2015 12:39:51 +0300 Subject: [PATCH] Fixed, resolve todc/todc-select2#13 * Fix from original selec2 commit: https://github.com/select2/select2/commit/9035dfcb9381abe6ed0f41ca324e633b23bf0a0b * Small fix of function equal(a, b) --- select2.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/select2.js b/select2.js index 55531ae3b8..88ff950981 100644 --- a/select2.js +++ b/select2.js @@ -103,7 +103,9 @@ the specific language governing permissions and limitations under the Apache Lic function indexOf(value, array) { var i = 0, l = array.length; - for (; i < l; i = i + 1) if (value === array[i]) return i; + for (; i < l; i = i + 1) { + if (equal(value, array[i])) return i; + } return -1; } @@ -113,7 +115,12 @@ the specific language governing permissions and limitations under the Apache Lic * @param b */ function equal(a, b) { - return a===b; + if (a === b) return true; + if (a === undefined || b === undefined) return false; + if (a === null || b === null) return false; + if (a.constructor === String) return a + '' === b; + if (b.constructor === String) return b + '' === a; + return false; } /**