From 8afc20d5e47fd3b0075b9e97c0e7cc495989bbec Mon Sep 17 00:00:00 2001 From: Megha Date: Sun, 27 Sep 2015 20:32:37 +0530 Subject: [PATCH] Change multiselect cache structure The existing structure used an Object as a cache where the keys are the values of option elements, and values are the HTML content of the option elements. In Javascript, if a numeric value in the form of a string is assigned as a key, it gets converted to an integer. Optimization routines would then order the object to ensure faster access to elements. For example: cache = {} cache['2'] = "two" cache['1'] = "one" console.log(cache[2]) #=> "two" console.log(cache[1]) #=> "one" console.log(cache) #=> {1: "one", 2: "two"} Note the coercion of strings to ints above. This messes with the ordering of multiselect options list whenever there is a user input. To avoid this from happening, the keys need to have a string that can't be coerced automatically, and then preserve the value of the option element. I chose to use an object that stores the option value and the option HTML as the value of the cache and a string of the format 'o_