Skip to content

Commit 90d5234

Browse files
authored
Merge pull request #12967 from IgniteUI/rivanova/fix-12898-master
fix(simple-combo): set value to empty string when the remote data is not present - master
2 parents 07558b2 + fe988ae commit 90d5234

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

projects/igniteui-angular/src/lib/simple-combo/simple-combo.component.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1974,6 +1974,28 @@ describe('IgxSimpleCombo', () => {
19741974
expect(combo.value).toEqual(`${selectedItem[combo.displayKey]}`);
19751975
expect(combo.selection).toEqual([selectedItem[combo.valueKey]]);
19761976
}));
1977+
it('should set combo.value to empty string when bound to remote data and selected item\'s data is not present', (async () => {
1978+
expect(combo.valueKey).toBeDefined();
1979+
expect(combo.valueKey).toEqual('id');
1980+
expect(combo.selection.length).toEqual(0);
1981+
1982+
// current combo data - id: 0 - 9
1983+
// select item that is not present in the data source yet
1984+
combo.select(15);
1985+
1986+
expect(combo.selection.length).toEqual(1);
1987+
expect(combo.value).toEqual('');
1988+
1989+
combo.toggle();
1990+
1991+
// scroll to selected item
1992+
combo.virtualScrollContainer.scrollTo(15);
1993+
await wait();
1994+
fixture.detectChanges();
1995+
1996+
const selectedItem = combo.data[combo.data.length - 1];
1997+
expect(combo.value).toEqual(`${selectedItem[combo.displayKey]}`);
1998+
}));
19771999
});
19782000
});
19792001

projects/igniteui-angular/src/lib/simple-combo/simple-combo.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
487487

488488
this.registerRemoteEntries(oldSelection, false);
489489
this.registerRemoteEntries(newSelection);
490-
return Object.keys(this._remoteSelection).map(e => this._remoteSelection[e])[0];
490+
return Object.keys(this._remoteSelection).map(e => this._remoteSelection[e])[0] || '';
491491
}
492492

493493
/** Contains key-value pairs of the selected valueKeys and their resp. displayKeys */

0 commit comments

Comments
 (0)