From f3b9693ad949081eee1e8a984dd28d8c5147d3ae Mon Sep 17 00:00:00 2001 From: Kevin Brown Date: Sun, 3 Jan 2016 18:34:59 -0500 Subject: [PATCH] Fixed existing selections not being respected with array data This fixes an edge case that occurred pretty much whenever anyone would use array data with existing selections along with a placeholder. This caused the existing selections to be discarded, because the `selected` property was not being transferred over to the new option. This was based the new data was being preferred over the data that could be inferred from the option, and the new data typically did not include the selected state. As a result, the option was assumed to not be selected. This was not cause by existing tests because all of the existing tests only covered cases where the selected option was the first option, and that was not affected by this bug. --- src/js/select2/data/array.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/select2/data/array.js b/src/js/select2/data/array.js index 1c9e1bb2..b8899662 100644 --- a/src/js/select2/data/array.js +++ b/src/js/select2/data/array.js @@ -52,7 +52,7 @@ define([ var $existingOption = $existing.filter(onlyItem(item)); var existingData = this.item($existingOption); - var newData = $.extend(true, {}, existingData, item); + var newData = $.extend(true, {}, item, existingData); var $newOption = this.option(newData);