convert hierarchical options / optgroups to a flat list and enable search for more than 100 options automatic

fixes timezone selection in preferences
This commit is contained in:
ralf 2022-07-26 18:57:18 +02:00
parent 9fe7b22d1f
commit 9f15169ced
2 changed files with 14 additions and 2 deletions

View File

@ -154,6 +154,11 @@ export const Et2widgetWithSelectMixin = <T extends Constructor<LitElement>>(supe
this.__select_options = cleanSelectOptions(new_options);
if (this.__select_options.length > 100)
{
this.search = true;
}
this.requestUpdate("select_options", old_options);
}

View File

@ -232,15 +232,22 @@ export function cleanSelectOptions(options : SelectOption[] | string[] | object)
}
else
{
// make sure value is a string
// make sure value is a string, and label not an object with sub-options
options.forEach(option =>
{
if (typeof option.value !== 'string')
{
option.value = option.value.toString();
}
if (typeof option.label !== 'string')
{
fixed_options.push(...cleanSelectOptions(option.label));
}
else
{
fixed_options.push(option);
}
})
fixed_options = options;
}
return fixed_options;