diff --git a/select2.js b/select2.js index 7c918e99..044bf1e8 100644 --- a/select2.js +++ b/select2.js @@ -2966,21 +2966,18 @@ the specific language governing permissions and limitations under the Apache Lic // multi updateSelection: function (data) { - var ids = [], filtered = [], self = this; + var ids = {}, filtered = [], self = this; // filter out duplicates $(data).each(function () { - if (indexOf(self.id(this), ids) < 0) { - ids.push(self.id(this)); + if (!(self.id(this) in ids)) { + ids[self.id(this)] = 0; filtered.push(this); } }); - data = filtered; this.selection.find(".select2-search-choice").remove(); - $(data).each(function () { - self.addSelectedChoice(this); - }); + this.addSelectedChoice(filtered); self.postprocessResults(); }, @@ -3054,6 +3051,14 @@ the specific language governing permissions and limitations under the Apache Lic }, addSelectedChoice: function (data) { + var val = this.getVal(), self = this; + $(data).each(function () { + val.push(self.createChoice(this)); + }); + this.setVal(val); + }, + + createChoice: function (data) { var enableChoice = !data.locked, enabledItem = $( "