From 3e80b18160a357634180b4fd595effdf32355142 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 --- .../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 c2c23335c4..e7b8d51966 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 @@ -363,8 +363,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]; @@ -412,13 +411,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