Fixed problems with non-string ids
We have to enforce ids being strings as the values of options within a select will always be an id. This fixes an issue that we had with array selections not being highlighted in the results.
This commit is contained in:
parent
ac7e7dae24
commit
27ac50a854
@ -100,6 +100,7 @@ module.exports = function (grunt) {
|
||||
optimize: "none",
|
||||
name: "select2/core",
|
||||
out: "dist/js/select2.amd.js",
|
||||
include: includes,
|
||||
paths: {
|
||||
jquery: "empty:"
|
||||
}
|
||||
|
6
dist/js/select2.amd.full.js
vendored
6
dist/js/select2.amd.full.js
vendored
@ -181,7 +181,9 @@ define('select2/results',[
|
||||
var self = this;
|
||||
|
||||
this.data.current(function (selected) {
|
||||
selected = $.map(selected, function (s) { return s.id; });
|
||||
var selectedIds = $.map(selected, function (s) {
|
||||
return s.id.toString();
|
||||
});
|
||||
|
||||
self.$results.find('.option.selected').removeClass('selected');
|
||||
|
||||
@ -191,7 +193,7 @@ define('select2/results',[
|
||||
var $option = $(this);
|
||||
var item = $option.data('data');
|
||||
|
||||
if (selected.indexOf(item.id.toString()) > -1) {
|
||||
if (selectedIds.indexOf(item.id.toString()) > -1) {
|
||||
$option.addClass('selected');
|
||||
}
|
||||
});
|
||||
|
31
dist/js/select2.amd.js
vendored
31
dist/js/select2.amd.js
vendored
@ -181,7 +181,9 @@ define('select2/results',[
|
||||
var self = this;
|
||||
|
||||
this.data.current(function (selected) {
|
||||
selected = $.map(selected, function (s) { return s.id; });
|
||||
var selectedIds = $.map(selected, function (s) {
|
||||
return s.id.toString();
|
||||
});
|
||||
|
||||
self.$results.find('.option.selected').removeClass('selected');
|
||||
|
||||
@ -191,7 +193,7 @@ define('select2/results',[
|
||||
var $option = $(this);
|
||||
var item = $option.data('data');
|
||||
|
||||
if (selected.indexOf(item.id.toString()) > -1) {
|
||||
if (selectedIds.indexOf(item.id.toString()) > -1) {
|
||||
$option.addClass('selected');
|
||||
}
|
||||
});
|
||||
@ -937,3 +939,28 @@ define('select2/core',[
|
||||
return Select2;
|
||||
});
|
||||
|
||||
define('jquery.select2',[
|
||||
'jquery',
|
||||
'select2/core'
|
||||
], function ($, Select2) {
|
||||
if ($.fn.select2 == null) {
|
||||
$.fn.select2 = function (options) {
|
||||
options = options || {};
|
||||
|
||||
if (typeof options === 'object') {
|
||||
this.each(function () {
|
||||
var instance = new Select2($(this), options);
|
||||
});
|
||||
} else if (typeof options === 'string') {
|
||||
var instance = this.data('select2');
|
||||
|
||||
instance[options](arguments.slice(1));
|
||||
} else {
|
||||
throw new Error('Invalid arguments for Select2: ' + options);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return Select2;
|
||||
});
|
||||
|
||||
|
6
dist/js/select2.full.js
vendored
6
dist/js/select2.full.js
vendored
@ -9719,7 +9719,9 @@ define('select2/results',[
|
||||
var self = this;
|
||||
|
||||
this.data.current(function (selected) {
|
||||
selected = $.map(selected, function (s) { return s.id; });
|
||||
var selectedIds = $.map(selected, function (s) {
|
||||
return s.id.toString();
|
||||
});
|
||||
|
||||
self.$results.find('.option.selected').removeClass('selected');
|
||||
|
||||
@ -9729,7 +9731,7 @@ define('select2/results',[
|
||||
var $option = $(this);
|
||||
var item = $option.data('data');
|
||||
|
||||
if (selected.indexOf(item.id.toString()) > -1) {
|
||||
if (selectedIds.indexOf(item.id.toString()) > -1) {
|
||||
$option.addClass('selected');
|
||||
}
|
||||
});
|
||||
|
2
dist/js/select2.full.min.js
vendored
2
dist/js/select2.full.min.js
vendored
File diff suppressed because one or more lines are too long
6
dist/js/select2.js
vendored
6
dist/js/select2.js
vendored
@ -610,7 +610,9 @@ define('select2/results',[
|
||||
var self = this;
|
||||
|
||||
this.data.current(function (selected) {
|
||||
selected = $.map(selected, function (s) { return s.id; });
|
||||
var selectedIds = $.map(selected, function (s) {
|
||||
return s.id.toString();
|
||||
});
|
||||
|
||||
self.$results.find('.option.selected').removeClass('selected');
|
||||
|
||||
@ -620,7 +622,7 @@ define('select2/results',[
|
||||
var $option = $(this);
|
||||
var item = $option.data('data');
|
||||
|
||||
if (selected.indexOf(item.id.toString()) > -1) {
|
||||
if (selectedIds.indexOf(item.id.toString()) > -1) {
|
||||
$option.addClass('selected');
|
||||
}
|
||||
});
|
||||
|
2
dist/js/select2.min.js
vendored
2
dist/js/select2.min.js
vendored
File diff suppressed because one or more lines are too long
6
src/js/select2/results.js
vendored
6
src/js/select2/results.js
vendored
@ -42,7 +42,9 @@ define([
|
||||
var self = this;
|
||||
|
||||
this.data.current(function (selected) {
|
||||
selected = $.map(selected, function (s) { return s.id; });
|
||||
var selectedIds = $.map(selected, function (s) {
|
||||
return s.id.toString();
|
||||
});
|
||||
|
||||
self.$results.find('.option.selected').removeClass('selected');
|
||||
|
||||
@ -52,7 +54,7 @@ define([
|
||||
var $option = $(this);
|
||||
var item = $option.data('data');
|
||||
|
||||
if (selected.indexOf(item.id.toString()) > -1) {
|
||||
if (selectedIds.indexOf(item.id.toString()) > -1) {
|
||||
$option.addClass('selected');
|
||||
}
|
||||
});
|
||||
|
@ -61,7 +61,8 @@ test('current works with existing selections', function (assert) {
|
||||
val,
|
||||
[{
|
||||
id: '3',
|
||||
text: 'Three'
|
||||
text: 'Three',
|
||||
disabled: false
|
||||
}],
|
||||
'The text and id should match the value and text for the option tag.'
|
||||
);
|
||||
|
@ -16,7 +16,8 @@ test('current gets default for single', function (assert) {
|
||||
val,
|
||||
[{
|
||||
id: 'default',
|
||||
text: 'Default'
|
||||
text: 'Default',
|
||||
disabled: false
|
||||
}],
|
||||
'The first option should be selected by default (by the browser).'
|
||||
);
|
||||
@ -49,7 +50,8 @@ test('current gets options with explicit value', function (assert) {
|
||||
val,
|
||||
[{
|
||||
id: '1',
|
||||
text: 'One'
|
||||
text: 'One',
|
||||
disabled: false
|
||||
}],
|
||||
'The text and id should match the value and text for the option tag.'
|
||||
);
|
||||
@ -68,7 +70,8 @@ test('current gets options with implicit value', function (assert) {
|
||||
val,
|
||||
[{
|
||||
id: '2',
|
||||
text: '2'
|
||||
text: '2',
|
||||
disabled: false
|
||||
}],
|
||||
'The text and id should match the text within the option tag.'
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user