Update the selected
property on objects
This fixes the results display so they prefer the `selected` property on objects over checking if the `id` matches the value of the underlying select. We only ignore the `selected` property if it is null, at that point we compare against the `id` property. This closes https://github.com/select2/select2/issues/3163.
This commit is contained in:
parent
a6999990b0
commit
9d359c9b38
9
dist/js/select2.full.js
vendored
9
dist/js/select2.full.js
vendored
@ -828,7 +828,8 @@ S2.define('select2/results',[
|
||||
// id needs to be converted to a string when comparing
|
||||
var id = '' + item.id;
|
||||
|
||||
if ($.inArray(id, selectedIds) > -1) {
|
||||
if (item.selected ||
|
||||
(item.selected == null && $.inArray(id, selectedIds) > -1)) {
|
||||
$option.attr('aria-selected', 'true');
|
||||
} else {
|
||||
$option.attr('aria-selected', 'false');
|
||||
@ -2865,7 +2866,9 @@ S2.define('select2/data/select',[
|
||||
SelectAdapter.prototype.select = function (data) {
|
||||
var self = this;
|
||||
|
||||
// If data.element is a DOM nose, use it instead
|
||||
data.selected = true;
|
||||
|
||||
// If data.element is a DOM node, use it instead
|
||||
if ($(data.element).is('option')) {
|
||||
data.element.selected = true;
|
||||
|
||||
@ -2907,6 +2910,8 @@ S2.define('select2/data/select',[
|
||||
return;
|
||||
}
|
||||
|
||||
data.selected = false;
|
||||
|
||||
if ($(data.element).is('option')) {
|
||||
data.element.selected = false;
|
||||
|
||||
|
6
dist/js/select2.full.min.js
vendored
6
dist/js/select2.full.min.js
vendored
File diff suppressed because one or more lines are too long
9
dist/js/select2.js
vendored
9
dist/js/select2.js
vendored
@ -828,7 +828,8 @@ S2.define('select2/results',[
|
||||
// id needs to be converted to a string when comparing
|
||||
var id = '' + item.id;
|
||||
|
||||
if ($.inArray(id, selectedIds) > -1) {
|
||||
if (item.selected ||
|
||||
(item.selected == null && $.inArray(id, selectedIds) > -1)) {
|
||||
$option.attr('aria-selected', 'true');
|
||||
} else {
|
||||
$option.attr('aria-selected', 'false');
|
||||
@ -2865,7 +2866,9 @@ S2.define('select2/data/select',[
|
||||
SelectAdapter.prototype.select = function (data) {
|
||||
var self = this;
|
||||
|
||||
// If data.element is a DOM nose, use it instead
|
||||
data.selected = true;
|
||||
|
||||
// If data.element is a DOM node, use it instead
|
||||
if ($(data.element).is('option')) {
|
||||
data.element.selected = true;
|
||||
|
||||
@ -2907,6 +2910,8 @@ S2.define('select2/data/select',[
|
||||
return;
|
||||
}
|
||||
|
||||
data.selected = false;
|
||||
|
||||
if ($(data.element).is('option')) {
|
||||
data.element.selected = false;
|
||||
|
||||
|
4
dist/js/select2.min.js
vendored
4
dist/js/select2.min.js
vendored
File diff suppressed because one or more lines are too long
6
src/js/select2/data/select.js
vendored
6
src/js/select2/data/select.js
vendored
@ -30,7 +30,9 @@ define([
|
||||
SelectAdapter.prototype.select = function (data) {
|
||||
var self = this;
|
||||
|
||||
// If data.element is a DOM nose, use it instead
|
||||
data.selected = true;
|
||||
|
||||
// If data.element is a DOM node, use it instead
|
||||
if ($(data.element).is('option')) {
|
||||
data.element.selected = true;
|
||||
|
||||
@ -72,6 +74,8 @@ define([
|
||||
return;
|
||||
}
|
||||
|
||||
data.selected = false;
|
||||
|
||||
if ($(data.element).is('option')) {
|
||||
data.element.selected = false;
|
||||
|
||||
|
3
src/js/select2/results.js
vendored
3
src/js/select2/results.js
vendored
@ -109,7 +109,8 @@ define([
|
||||
// id needs to be converted to a string when comparing
|
||||
var id = '' + item.id;
|
||||
|
||||
if ($.inArray(id, selectedIds) > -1) {
|
||||
if (item.selected ||
|
||||
(item.selected == null && $.inArray(id, selectedIds) > -1)) {
|
||||
$option.attr('aria-selected', 'true');
|
||||
} else {
|
||||
$option.attr('aria-selected', 'false');
|
||||
|
Loading…
Reference in New Issue
Block a user