From b823b6d84bd04976144183bf6fbd06889afd40a9 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 22 Mar 2021 12:10:46 -0400 Subject: [PATCH] LP1904036 Combobox supports freetext startId entries Signed-off-by: Bill Erickson Signed-off-by: Jane Sandberg Signed-off-by: Galen Charlton --- .../src/app/share/combobox/combobox.component.ts | 29 +++++++++++++++------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts b/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts index 3f8182e895..735f44a64f 100644 --- a/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts +++ b/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts @@ -427,8 +427,7 @@ export class ComboboxComponent // Apply a default selection where needed applySelection() { - if (this.startId !== null && - this.entrylist && !this.defaultSelectionApplied) { + if (this.entrylist && !this.defaultSelectionApplied) { const entry = this.entrylist.filter(e => e.id === this.startId)[0]; @@ -477,13 +476,25 @@ export class ComboboxComponent if (typeof this.selected === 'string') { if (this.allowFreeText && this.selected !== '') { - // Free text entered which does not match a known entry - // translate it into a dummy ComboboxEntry - this.selected = { - id: null, - label: this.selected, - freetext: true - }; + const freeText = this.entrylist.filter(e => e.id === null)[0]; + + if (freeText) { + + // If we already had a free text entry, just replace + // the label with the new value + freeText.label = this.selected; + this.selected = freeText; + + } else { + + // Free text entered which does not match a known entry + // translate it into a dummy ComboboxEntry + this.selected = { + id: null, + label: this.selected, + freetext: true + }; + } } else { -- 2.11.0