From eff1f1048434a7050c5bb21092ecc38aee6ab23c Mon Sep 17 00:00:00 2001 From: ralf Date: Mon, 28 Feb 2022 15:21:23 +0200 Subject: [PATCH] fix sometimes first non-empty label used for empty value seems update got triggered before empty_label was set --- api/js/etemplate/Et2Select/Et2Select.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/api/js/etemplate/Et2Select/Et2Select.ts b/api/js/etemplate/Et2Select/Et2Select.ts index a1214df1be..6d64da8fda 100644 --- a/api/js/etemplate/Et2Select/Et2Select.ts +++ b/api/js/etemplate/Et2Select/Et2Select.ts @@ -231,11 +231,13 @@ export class Et2Select extends Et2WidgetWithSelect ); } } - if(changedProperties.has('select_options') || changedProperties.has("value")) + if (changedProperties.has('select_options') || changedProperties.has("value") || changedProperties.has('empty_label')) { - if(this.get_select_options().length > 0 && this.get_select_options().filter((option) => option.value == this.modalValue).length === 0) + // value not in options AND NOT (having an empty label and value) + if (this.get_select_options().length > 0 && this.get_select_options().filter((option) => option.value == this.modalValue).length === 0 && + !(typeof this.empty_label !== 'undefined' && (this.modalValue||"") === "")) { - // Not in list, use first option + // --> use first option this.modalValue = this.get_select_options()[0]?.value || ""; } // Re-set value, the option for it may have just shown up