remove removing of empty description and label widgets

also make sure option.value is a string, as sl-select seems to use === to calculate matches so option with value 0 is not selected by a value of '0'
This commit is contained in:
ralf 2022-06-02 13:44:46 +02:00
parent 22f41e7cb4
commit c251e2f185
2 changed files with 21 additions and 0 deletions

View File

@ -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);
}
}
/**

View File

@ -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;
}