1
0
mirror of synced 2024-11-22 21:16:10 +03:00

Fixes issues with inputData module. When unselecting an item it would previously unselect all items

This commit is contained in:
Cristi Badila 2015-03-10 11:02:59 +02:00
parent fff04c3f0c
commit 24f3c4777d
6 changed files with 42 additions and 9 deletions

View File

@ -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));

View File

@ -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));

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -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));

View File

@ -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);