Skip to content

Commit aa8f4cc

Browse files
authored
Merge pull request #180 from d-georgiev-91/ig-combo-issue-172
Fixed igCombo bug #172 - model does not get updated when multiple sel…
2 parents 8c1a857 + 37e55ed commit aa8f4cc

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

src/igniteui.angular2.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2319,7 +2319,9 @@ export class IgComboComponent extends IgControlBase<IgCombo> implements ControlV
23192319
jQuery(this._el).on(this._widgetName.toLowerCase() + "selectionchanged", function (evt, ui) {
23202320
var items = ui.items;
23212321
if (items.length > 0 && that._model) {
2322-
that._model.viewToModelUpdate(items[0].data[that._config.valueKey]);
2322+
that._model.viewToModelUpdate(items.map(function(item) {
2323+
return item.data[that._config.valueKey];
2324+
}));
23232325
}
23242326
});
23252327
this._dataSource = jQuery.extend(true, [], this._config.dataSource);

tests/unit/igcombo/combo.spec.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,29 @@ export function main() {
8282
$("#combo1").igCombo("select", elem, {}, true);
8383
fixture.detectChanges();
8484
setTimeout(function () {
85-
expect(fixture.componentInstance.combo.value1).toBe(1);
85+
expect(fixture.componentInstance.combo.value1).toEqual([1]);
86+
done();
87+
}, 10);
88+
});
89+
});
90+
91+
it('the ngModel should be updated correctly if the combo selection is updated and multiple items are selected', (done) => {
92+
var template = '<div><ig-combo [(widgetId)]="comboID" [(options)]="optionsMultipleSelection" [changeDetectionInterval]="cdi" [(ngModel)]="combo.value1"></ig-combo></div>';
93+
TestBed.overrideComponent(TestComponent, {
94+
set: {
95+
template: template
96+
}
97+
});
98+
TestBed.compileComponents().then(() => {
99+
let fixture = TestBed.createComponent(TestComponent);
100+
fixture.detectChanges();
101+
var $firstThreeItems = $(".ui-igcombo-listitem:lt(3)");
102+
103+
$("#combo1").igCombo("select", $firstThreeItems, {}, true);
104+
105+
fixture.detectChanges();
106+
setTimeout(function () {
107+
expect(fixture.componentInstance.combo.value1).toEqual([1, 2, 3]);
86108
done();
87109
}, 10);
88110
});
@@ -142,6 +164,7 @@ export function main() {
142164
})
143165
class TestComponent {
144166
private options: IgCombo;
167+
private optionsMultipleSelection: IgCombo;
145168
public northwind: any;
146169
public combo: any;
147170
private comboID: string
@@ -158,6 +181,16 @@ class TestComponent {
158181
dataSource: this.northwind,
159182
width: "100%"
160183
};
184+
185+
this.optionsMultipleSelection = $.extend({
186+
multiSelection: {
187+
enabled: true,
188+
addWithKeyModifier: false,
189+
showCheckboxes: true,
190+
itemSeparator: ', '
191+
}
192+
}, this.options);
193+
161194
this.combo = {
162195
value1: 20
163196
}

0 commit comments

Comments
 (0)