Skip to content

Commit c44f9b0

Browse files
committed
fix(simple-combo): set value to empty string when the remote data is not present
1 parent d6da331 commit c44f9b0

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
@@ -2003,6 +2003,28 @@ describe('IgxSimpleCombo', () => {
20032003
expect(combo.value).toEqual(`${selectedItem[combo.displayKey]}`);
20042004
expect(combo.selection).toEqual([selectedItem[combo.valueKey]]);
20052005
}));
2006+
it('should set combo.value to empty string when bound to remote data and selected item\'s data is not present', (async () => {
2007+
expect(combo.valueKey).toBeDefined();
2008+
expect(combo.valueKey).toEqual('id');
2009+
expect(combo.selection.length).toEqual(0);
2010+
2011+
// current combo data - id: 0 - 9
2012+
// select item that is not present in the data source yet
2013+
combo.select(15);
2014+
2015+
expect(combo.selection.length).toEqual(1);
2016+
expect(combo.value).toEqual('');
2017+
2018+
combo.toggle();
2019+
2020+
// scroll to selected item
2021+
combo.virtualScrollContainer.scrollTo(15);
2022+
await wait();
2023+
fixture.detectChanges();
2024+
2025+
const selectedItem = combo.data[combo.data.length - 1];
2026+
expect(combo.value).toEqual(`${selectedItem[combo.displayKey]}`);
2027+
}));
20062028
});
20072029
});
20082030

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
@@ -495,7 +495,7 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
495495

496496
this.registerRemoteEntries(oldSelection, false);
497497
this.registerRemoteEntries(newSelection);
498-
return Object.keys(this._remoteSelection).map(e => this._remoteSelection[e])[0];
498+
return Object.keys(this._remoteSelection).map(e => this._remoteSelection[e])[0] || '';
499499
}
500500

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

0 commit comments

Comments
 (0)