Fix conflict between Et2Select static type options & custom options resulted in losing the type options

This commit is contained in:
nathan 2022-05-31 09:58:49 -06:00
parent 5f7d1c50a2
commit c572fa637d
2 changed files with 15 additions and 4 deletions

View File

@ -237,9 +237,10 @@ export const Et2widgetWithSelectMixin = dedupeMixin((superclass) =>
*/ */
loadFromXML(_node : Element) loadFromXML(_node : Element)
{ {
// Read the option-tags
let options = _node.querySelectorAll("option");
let new_options = []; let new_options = [];
// Read the option-tags, but if not rendered there won't be any yet so check existing options
let options = _node.querySelectorAll("option");
for(let i = 0; i < options.length; i++) for(let i = 0; i < options.length; i++)
{ {
new_options.push({ new_options.push({
@ -252,6 +253,13 @@ export const Et2widgetWithSelectMixin = dedupeMixin((superclass) =>
title: et2_readAttrWithDefault(options[i], "title", "") title: et2_readAttrWithDefault(options[i], "title", "")
}); });
} }
if(options.length == 0 && this.__select_options.length)
{
// Start with any existing options, (static options from type)
// Use a copy since we'll probably be modifying it, and we don't want to change for any other
// widget of the same static type
new_options = [...this.__select_options];
}
if(this.id) if(this.id)
{ {

View File

@ -178,7 +178,10 @@ export function find_select_options(widget, attr_options?, options : SelectOptio
} }
if(!added) if(!added)
{ {
options.splice(parseInt(i), 0, content_options[i]); options.splice(parseInt(i), 0, typeof value == "object" ? value : {
value: value,
label: <string><unknown>content_options[i]
});
} }
} }
content_options = options; content_options = options;