Skip to content

Commit 40fb10f

Browse files
authored
Merge branch 'master' into dkamburov/fix-268
2 parents 2d93765 + c2becae commit 40fb10f

File tree

2 files changed

+56
-36
lines changed

2 files changed

+56
-36
lines changed

src/igcombo/igcombo.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export class IgComboComponent extends IgControlBase<IgCombo> implements ControlV
3232

3333
ngOnInit() {
3434
let that = this;
35-
const valueKey = this["valueKey"] || this.options.valueKey;
3635
if (this._dataSource === null || this._dataSource === undefined) {
3736
this._dataSource = this.options["dataSource"];
3837
}
@@ -45,6 +44,7 @@ export class IgComboComponent extends IgControlBase<IgCombo> implements ControlV
4544
// D.P. #244 only attach selectionchanged handler if there's a model to update
4645
jQuery(this._el).on(this._widgetName.toLowerCase() + "selectionchanged", function (evt, ui) {
4746
var items = ui.items;
47+
const valueKey = ui.owner.options.valueKey;
4848

4949
if (items.length <= 0 && !ui.owner.options.multiSelection.enabled) {
5050
that._model.viewToModelUpdate(null);

tests/unit/igcombo/combo.spec.ts

Lines changed: 55 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -90,29 +90,29 @@ export function main() {
9090
});
9191
});
9292

93-
it('should be updated correctly if the ngModel value is cleared.', (done) => {
94-
var template = '<div><ig-combo [(widgetId)]="comboID" [(options)]="options" [(ngModel)]="combo.value1" [dataSource]="northwind"></ig-combo></div>';
95-
TestBed.overrideComponent(TestComponent, {
96-
set: {
97-
template: template
98-
}
99-
});
93+
it('should be updated correctly if the ngModel value is cleared.', (done) => {
94+
var template = '<div><ig-combo [(widgetId)]="comboID" [(options)]="options" [(ngModel)]="combo.value1" [dataSource]="northwind"></ig-combo></div>';
95+
TestBed.overrideComponent(TestComponent, {
96+
set: {
97+
template: template
98+
}
99+
});
100100
TestBed.compileComponents().then(() => {
101101
let fixture = TestBed.createComponent(TestComponent);
102102
fixture.detectChanges();
103-
fixture.componentInstance.combo.value1 = 1;
104-
fixture.detectChanges();
103+
fixture.componentInstance.combo.value1 = 1;
104+
fixture.detectChanges();
105105
setTimeout(function () {
106-
//clear
107-
$("#combo1").parents("ig-combo").find(".ui-igcombo-clearicon").click();
108-
fixture.detectChanges();
109-
setTimeout(function(){
110-
expect(fixture.componentInstance.combo.value1).toBeNull();
111-
done();
112-
}, 10);
106+
//clear
107+
$("#combo1").parents("ig-combo").find(".ui-igcombo-clearicon").click();
108+
fixture.detectChanges();
109+
setTimeout(function () {
110+
expect(fixture.componentInstance.combo.value1).toBeNull();
111+
done();
112+
}, 10);
113113
}, 10);
114114
});
115-
});
115+
});
116116

117117
it('should be updated correctly if the ngModel value is cleared when multiple selection.', (done) => {
118118
var template = '<div><ig-combo [(widgetId)]="comboID" [(options)]="optionsMultipleSelection" [(ngModel)]="combo.value1" [dataSource]="northwind"></ig-combo></div>';
@@ -122,21 +122,40 @@ export function main() {
122122
}
123123
});
124124
TestBed.compileComponents().then(() => {
125-
let fixture = TestBed.createComponent(TestComponent);
126-
fixture.detectChanges();
127-
fixture.componentInstance.combo.value1 = 1;
128-
fixture.detectChanges();
129-
setTimeout(function () {
130-
//clear
131-
$("#combo1").parents("ig-combo").find(".ui-igcombo-clearicon").click();
125+
let fixture = TestBed.createComponent(TestComponent);
132126
fixture.detectChanges();
133-
setTimeout(function(){
134-
expect(fixture.componentInstance.combo.value1 instanceof Array && fixture.componentInstance.combo.value1.length === 0).toBeTruthy();
135-
done();
127+
fixture.componentInstance.combo.value1 = 1;
128+
fixture.detectChanges();
129+
setTimeout(function () {
130+
//clear
131+
$("#combo1").parents("ig-combo").find(".ui-igcombo-clearicon").click();
132+
fixture.detectChanges();
133+
setTimeout(function () {
134+
expect(fixture.componentInstance.combo.value1 instanceof Array && fixture.componentInstance.combo.value1.length === 0).toBeTruthy();
135+
done();
136+
}, 10);
136137
}, 10);
137-
}, 10);
138+
});
139+
});
140+
141+
it('should apply ngModel when multiple selection and no valueKey set.', (done) => {
142+
var template = '<div><ig-combo [(widgetId)]="comboID" [options]="{multiSelection: {enabled: true, showCheckboxes: true}}" [(ngModel)]="val" [dataSource]="[\'foo\', \'bar\', \'bas\']"></ig-combo></div>';
143+
TestBed.overrideComponent(TestComponent, {
144+
set: {
145+
template: template
146+
}
147+
});
148+
TestBed.compileComponents().then(() => {
149+
let fixture = TestBed.createComponent(TestComponent);
150+
fixture.detectChanges();
151+
var elem = $("#combo1").igCombo("itemsFromIndex", 0)["element"];
152+
$("#combo1").igCombo("select", elem, {}, true);
153+
fixture.detectChanges();
154+
expect(fixture.componentInstance.val.length).toBe(1);
155+
expect(fixture.componentInstance.val[0]).toBe("foo");
156+
done();
157+
});
138158
});
139-
});
140159

141160
it('the ngModel should be updated correctly if the combo selection is updated', (done) => {
142161
var template = '<div><ig-combo [(widgetId)]="comboID" [(options)]="options" [(ngModel)]="combo.value1" [dataSource]="northwind"></ig-combo></div>';
@@ -220,19 +239,19 @@ export function main() {
220239
fixture.detectChanges();
221240
expect($("#combo1").igCombo("value")).toBe(fixture.componentInstance.combo.value1);
222241
expect($("#combo1").val())
223-
.toBe(fixture.componentInstance.northwind[fixture.componentInstance.combo.value1 - 1].ProductName);
242+
.toBe(fixture.componentInstance.northwind[fixture.componentInstance.combo.value1 - 1].ProductName);
224243
done();
225244
}, 10);
226245
});
227246
});
228247

229248
it('should initialize correctly when datasource is remote', (done) => {
230249
$['mockjax']({
231-
url: "myURL/Northwind",
232-
contentType: 'application/json',
233-
dataType: 'json',
234-
responseText: '[{"ProductID": 1, "ProductName": "Chai"}]'
235-
});
250+
url: "myURL/Northwind",
251+
contentType: 'application/json',
252+
dataType: 'json',
253+
responseText: '[{"ProductID": 1, "ProductName": "Chai"}]'
254+
});
236255
var template = '<div><ig-combo [(widgetId)]="comboID" [(options)]="options2" [(ngModel)]="combo.value1"></ig-combo></div>';
237256
TestBed.overrideComponent(TestComponent, {
238257
set: {
@@ -262,6 +281,7 @@ class TestComponent {
262281
public combo: any;
263282
private comboID: string
264283
public data: Array<any> = [];
284+
public val = [];
265285
@ViewChild(Infragistics.IgComboComponent) public viewChild: Infragistics.IgComboComponent;
266286

267287
constructor() {

0 commit comments

Comments
 (0)