From a9e180a9fbb96e24ded4008ae1695c4a55ed3aa5 Mon Sep 17 00:00:00 2001 From: ralf Date: Thu, 2 Jun 2022 16:12:38 +0200 Subject: [PATCH] fix mixup of this.value, Lion this.modelValue and old get/set_value causing eg. numeric values not to be cast to string and therefore not selecting their option --- api/js/etemplate/Et2Select/Et2Select.ts | 7 +++++- .../Et2Select/Et2WidgetWithSelectMixin.ts | 22 ++----------------- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/api/js/etemplate/Et2Select/Et2Select.ts b/api/js/etemplate/Et2Select/Et2Select.ts index f710778944..5a61e48a12 100644 --- a/api/js/etemplate/Et2Select/Et2Select.ts +++ b/api/js/etemplate/Et2Select/Et2Select.ts @@ -164,7 +164,12 @@ export class Et2Select extends Et2WithSearchMixin(Et2InvokerMixin(Et2WidgetWithS set_value(val) { - this.value = val; + this.value = ""+val; + } + + getValue() + { + return this.value; } /** diff --git a/api/js/etemplate/Et2Select/Et2WidgetWithSelectMixin.ts b/api/js/etemplate/Et2Select/Et2WidgetWithSelectMixin.ts index b948b09b12..245f568155 100644 --- a/api/js/etemplate/Et2Select/Et2WidgetWithSelectMixin.ts +++ b/api/js/etemplate/Et2Select/Et2WidgetWithSelectMixin.ts @@ -128,17 +128,6 @@ export const Et2widgetWithSelectMixin = dedupeMixin((superclass) => return super.formatter(v); } - set_value(val) - { - let oldValue = this.modelValue; - - // Make sure it's a string - val = "" + val; - - this.modelValue = val - this.requestUpdate("value", oldValue); - } - /** * Set the select options * @@ -153,16 +142,9 @@ export const Et2widgetWithSelectMixin = dedupeMixin((superclass) => this.requestUpdate("select_options", old_options); // if single selection and value does not match an option, use the first option - let first_option; - if (!this.multiple && !this.empty_label && !this.__select_options.filter(option => { - if (typeof first_option === 'undefined') - { - first_option = option; - } - return option.value === this.value; - }).length && typeof first_option !== 'undefined') + if (!this.multiple && !this.empty_label && !this.__select_options.filter(option => option.value === this.value).length) { - this.set_value(first_option.value); + this.value = this.__select_options[0].value; } }