Browse Source

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.
Kevin Brown 9 years ago
parent
commit
f3b9693ad9
1 changed files with 1 additions and 1 deletions
  1. 1 1
      src/js/select2/data/array.js

+ 1 - 1
src/js/select2/data/array.js

@@ -52,7 +52,7 @@ define([
         var $existingOption = $existing.filter(onlyItem(item));
         var $existingOption = $existing.filter(onlyItem(item));
 
 
         var existingData = this.item($existingOption);
         var existingData = this.item($existingOption);
-        var newData = $.extend(true, {}, existingData, item);
+        var newData = $.extend(true, {}, item, existingData);
 
 
         var $newOption = this.option(newData);
         var $newOption = this.option(newData);