Skip to content

Commit

Permalink
Fixing ArrayAdapter optgroup children data binding
Browse files Browse the repository at this point in the history
ArrayAdapter.convertToOptions fails to create item data for optgroup children, not binding it to the select options.  
This results in a bug, where the passed data element to select(data) is not initialized and normalized, thus element is null and id is an integer. Therefore the select function can't find the corresponding <option> while comparing an integer id with string <option>[value]
  • Loading branch information
5andr0 committed May 7, 2024
1 parent ed1761a commit 8dd4f49
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/js/select2/data/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,8 @@ define([
};

ArrayAdapter.prototype.select = function (data) {
var $option = this.$element.find('option').filter(function (i, elm) {
return elm.value == data.id.toString();
});

if ($option.length === 0) {
$option = this.option(data);

this.addOptions($option);
if (!data.element) {
this.addOptions(this.option(data));
}

ArrayAdapter.__super__.select.call(this, data);
Expand Down Expand Up @@ -68,9 +62,11 @@ define([
var $option = this.option(item);

if (item.children) {
var $children = this.convertToOptions(item.children);

$option.append($children);
item.children.forEach(function(child, index, children) {
var $child = self.convertToOptions([child]);
children[index] = self.item($child[0]);
$option.append($child);
})
}

$options.push($option);
Expand Down

0 comments on commit 8dd4f49

Please sign in to comment.