From f0455b2ad2ddf6c235976f20081b97547bb91041 Mon Sep 17 00:00:00 2001 From: nathan Date: Wed, 23 Feb 2022 13:13:14 -0700 Subject: [PATCH] Show empty_label when given a value that is not in the list of options --- api/js/etemplate/Et2Select/Et2Select.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/api/js/etemplate/Et2Select/Et2Select.ts b/api/js/etemplate/Et2Select/Et2Select.ts index b73013802f..5bb61a1ea7 100644 --- a/api/js/etemplate/Et2Select/Et2Select.ts +++ b/api/js/etemplate/Et2Select/Et2Select.ts @@ -78,6 +78,10 @@ export class Et2WidgetWithSelect extends Et2InputWidget(LionSelect) set_value(val) { let oldValue = this.modalValue; + + // Make sure it's a string + val = "" + val; + this.modalValue = val this.requestUpdate("value", oldValue); } @@ -229,6 +233,11 @@ export class Et2Select extends Et2WidgetWithSelect } if(changedProperties.has('select_options') || changedProperties.has("value")) { + if(this.get_select_options().length > 0 && this.get_select_options().filter((option) => option.value == this.modalValue).length === 0) + { + // Not in list, clear it + this.modalValue = ""; + } // Re-set value, the option for it may have just shown up this._inputNode.value = this.modalValue || ""; }