diff --git a/api/js/etemplate/Et2Select/Et2WidgetWithSelectMixin.ts b/api/js/etemplate/Et2Select/Et2WidgetWithSelectMixin.ts index 36c1c7ed50..b948b09b12 100644 --- a/api/js/etemplate/Et2Select/Et2WidgetWithSelectMixin.ts +++ b/api/js/etemplate/Et2Select/Et2WidgetWithSelectMixin.ts @@ -151,6 +151,19 @@ export const Et2widgetWithSelectMixin = dedupeMixin((superclass) => this.__select_options = cleanSelectOptions(new_options); 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') + { + this.set_value(first_option.value); + } } /** diff --git a/api/js/etemplate/Et2Select/FindSelectOptions.ts b/api/js/etemplate/Et2Select/FindSelectOptions.ts index 361aa3cc3a..79e41b168d 100644 --- a/api/js/etemplate/Et2Select/FindSelectOptions.ts +++ b/api/js/etemplate/Et2Select/FindSelectOptions.ts @@ -240,6 +240,14 @@ export function cleanSelectOptions(options : SelectOption[] | string[] | object) } else { + // make sure value is a string + options.forEach(option => + { + if (typeof option.value !== 'string') + { + option.value = option.value.toString(); + } + }) fixed_options = options; }