Merge pull request #3122 from cristi-badila/master
Fixes issues with inputData module. When unselecting an item it would previously unselect all items
This commit is contained in:
commit
b917754e55
4
dist/js/select2.amd.full.js
vendored
4
dist/js/select2.amd.full.js
vendored
@ -5115,14 +5115,14 @@ define('select2/compat/inputData',[
|
||||
this.current(function (allData) {
|
||||
var values = [];
|
||||
|
||||
for (var d = 0; d < allData; d++) {
|
||||
for (var d = 0; d < allData.length; d++) {
|
||||
var item = allData[d];
|
||||
|
||||
if (data.id == item.id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
values.push(data.id);
|
||||
values.push(item.id);
|
||||
}
|
||||
|
||||
self.$element.val(values.join(self._valueSeparator));
|
||||
|
4
dist/js/select2.full.js
vendored
4
dist/js/select2.full.js
vendored
@ -5554,14 +5554,14 @@ define('select2/compat/inputData',[
|
||||
this.current(function (allData) {
|
||||
var values = [];
|
||||
|
||||
for (var d = 0; d < allData; d++) {
|
||||
for (var d = 0; d < allData.length; d++) {
|
||||
var item = allData[d];
|
||||
|
||||
if (data.id == item.id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
values.push(data.id);
|
||||
values.push(item.id);
|
||||
}
|
||||
|
||||
self.$element.val(values.join(self._valueSeparator));
|
||||
|
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
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
4
src/js/select2/compat/inputData.js
vendored
4
src/js/select2/compat/inputData.js
vendored
@ -82,14 +82,14 @@ define([
|
||||
this.current(function (allData) {
|
||||
var values = [];
|
||||
|
||||
for (var d = 0; d < allData; d++) {
|
||||
for (var d = 0; d < allData.length; d++) {
|
||||
var item = allData[d];
|
||||
|
||||
if (data.id == item.id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
values.push(data.id);
|
||||
values.push(item.id);
|
||||
}
|
||||
|
||||
self.$element.val(values.join(self._valueSeparator));
|
||||
|
@ -34,7 +34,7 @@ test('test that options can be selected', function (assert) {
|
||||
);
|
||||
});
|
||||
|
||||
test('test that options can be unselected', function (assert) {
|
||||
test('unselect the single selected option clears the value', function (assert) {
|
||||
var options = new Options({
|
||||
data: [
|
||||
{
|
||||
@ -59,6 +59,39 @@ test('test that options can be unselected', function (assert) {
|
||||
);
|
||||
});
|
||||
|
||||
test('options can be unselected individually', function (assert) {
|
||||
var options = new Options({
|
||||
data: [
|
||||
{
|
||||
id: 'test',
|
||||
text: 'Test'
|
||||
},
|
||||
{
|
||||
id: 'test2',
|
||||
text: 'Test2'
|
||||
},
|
||||
{
|
||||
id: 'test3',
|
||||
text: 'Test3'
|
||||
}
|
||||
]
|
||||
});
|
||||
var $element = $('<input />');
|
||||
$element.val('test,test2,test3');
|
||||
|
||||
var adapter = new InputAdapter($element, options);
|
||||
|
||||
adapter.unselect({
|
||||
id: 'test2'
|
||||
});
|
||||
|
||||
assert.equal(
|
||||
$element.val(),
|
||||
'test,test3',
|
||||
'The value should contain all the still selected options'
|
||||
);
|
||||
});
|
||||
|
||||
test('default values can be set', function (assert) {
|
||||
expect(4);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user