Based on your sample i can use
Hi Alex,Thank you for your feedback!Since the drop-down selection event contains a reference to the whole `IDropDownItemBase` item, you can bind the whole object reference to item's `value` property and then handle which property you want to write to the DB service.
public handleSelectionChange(event: ISelectionEventArgs) { /** * `selectedItem.value` can contain a reference to the **data entry**, * thus containing **all** of the needed properties * Only the appropriate `valueKey` property (in this case - `id`) * can still be passed to the selection by doing the following: */ this.dbService.selectItem(event.newSelection.value.id); }
public ngAfterViewInit() { requestAnimationFrame(() => { this.dbService.selectedItem.pipe(takeUntil(this.destroy$)).subscribe((selected: any) => { this.dropDown.selectItem(this.dropDown.items.find(item => item.value.id === selected)); }); }) }
<div class="display-type"> From Value </div> <div class="display-field"> {{dropdown.selectedItem?.value.text }} </div>
<div class="display-type"> Element Text </div> <div class="display-field"> {{dropdown.selectedItem?.element.nativeElement.innerHTML }} </div>
/** * @param allItems: the collection of items from which the selected item text should be extracted * @param valueKey: the property of the entry that is written to the DB * @param displayKey: the property of the entry that should be displayed * @param selectedValue: the value currently marked as selected in the DB Service */ @Pipe({ name: 'value' }) export class ValuePipe implements PipeTransform { transform(allItems: any[], valueKey: any, displayKey: any, selectedValue: any): any { if (valueKey === null || valueKey === undefined || displayKey === null || displayKey === undefined || allItems.length === 0) { return ''; } else { return selectedValue !== null && selectedValue !== undefined ? allItems.find(e => e[valueKey] === selectedValue)[displayKey] : ''; } } }
<div class="display-type"> From Service </div> <div class="display-field"> {{ items | value:"id":"text":(dbService.selectedItem | async) }} </div>
Thanks that was somewhat helpful. I could not find any info on that in your docs . So lets say i am using 2 diffrent fields a value and a text in this dropdown where i want to show the user the text but store the value in db which i have covered. How would i go about populating the displayed text when i open an existing form which has this control. If i have a value of 3 for example stored and set the the control to 3 it will show 3 and not the text.
Hi Alex,
Thanks for reaching out!In the above scenario, you can access the selected item's text using one of the following approaches:1. Set the item's value to `[value]="selectedOption"` and access it via `dropDown.selectedItem?.value.text`2. With the value input being as is, access the inner text of the selected drop-down item with `dropDown.selectedItem?.element.nativeElement.innerText`You can see both of the above cases in this StackBlitz Example.The drop-down items do not have a specific input for their displayed text, as that is fully templatable and not necessarily only dependent on the `value` object.Hope this was helpful!