Skip to content

Commit ed8dcd9

Browse files
authored
Merge pull request #223 from MayaKirova/model-clear-issue-combo
Updating model value when there are no selected items.
2 parents 8a4fa9e + 64b2ecb commit ed8dcd9

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/igcombo/igcombo.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export class IgComboComponent extends IgControlBase<IgCombo> implements ControlV
3030
var items = ui.items;
3131

3232
if (items.length <= 0 || !that._model) {
33+
that._model.viewToModelUpdate(ui.owner.value());
3334
return;
3435
}
3536

tests/unit/igcombo/combo.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,30 @@ export function main() {
6767
});
6868
});
6969

70+
it('should be updated correctly if the ngModel value is cleared.', (done) => {
71+
var template = '<div><ig-combo [(widgetId)]="comboID" [(options)]="options" [changeDetectionInterval]="cdi" [(ngModel)]="combo.value1"></ig-combo></div>';
72+
TestBed.overrideComponent(TestComponent, {
73+
set: {
74+
template: template
75+
}
76+
});
77+
TestBed.compileComponents().then(() => {
78+
let fixture = TestBed.createComponent(TestComponent);
79+
fixture.detectChanges();
80+
fixture.componentInstance.combo.value1 = 1;
81+
fixture.detectChanges();
82+
setTimeout(function () {
83+
//clear
84+
$("#combo1").parents("ig-combo").find(".ui-igcombo-clearicon").click();
85+
fixture.detectChanges();
86+
setTimeout(function(){
87+
expect(fixture.componentInstance.combo.value1 instanceof Array && fixture.componentInstance.combo.value1.length === 0).toBeTruthy();
88+
done();
89+
}, 10);
90+
}, 10);
91+
});
92+
});
93+
7094
it('the ngModel should be updated correctly if the combo selection is updated', (done) => {
7195
var template = '<div><ig-combo [(widgetId)]="comboID" [(options)]="options" [changeDetectionInterval]="cdi" [(ngModel)]="combo.value1"></ig-combo></div>';
7296
TestBed.overrideComponent(TestComponent, {

0 commit comments

Comments
 (0)