Select bugfixes

- If value is changed because it's not a valid option, that might need a refresh
- If empty_label is changed, we need to update that
This commit is contained in:
nathan 2022-07-11 11:01:42 -06:00
parent 2a280c66cf
commit 0ca7508cd3
2 changed files with 3 additions and 1 deletions

View File

@ -216,8 +216,10 @@ export class Et2Select extends Et2WithSearchMixin(Et2WidgetWithSelect)
// value not in options --> use empty_label, if exists, or first option otherwise
if(this.select_options.filter((option) => valueArray.find(val => val == option.value)).length === 0)
{
let oldValue = this.value;
this.value = this.empty_label ? "" : "" + this.select_options[0]?.value;
// ""+ to cast value of 0 to "0", to not replace with ""
this.requestUpdate("value", oldValue);
}
}

View File

@ -109,7 +109,7 @@ export const Et2widgetWithSelectMixin = <T extends Constructor<LitElement>>(supe
}
// Add in actual option tags to the DOM based on the new select_options
if(changedProperties.has('select_options'))
if(changedProperties.has('select_options') || changedProperties.has("empty_label"))
{
// Add in options as children to the target node
if(this._optionTargetNode)