fix typo modalValue instead of modelValue to get validation (required) working

Had to overwrite formatter as it gave an error for accessing not yet set _inputNode
This commit is contained in:
ralf 2022-03-01 16:51:40 +02:00
parent ac408f4eef
commit 36e3bd5de0
2 changed files with 26 additions and 10 deletions

View File

@ -93,14 +93,14 @@ export class Et2Select extends Et2WidgetWithSelect
if (changedProperties.has('select_options') || changedProperties.has("value") || changedProperties.has('empty_label')) if (changedProperties.has('select_options') || changedProperties.has("value") || changedProperties.has('empty_label'))
{ {
// value not in options AND NOT (having an empty label and value) // value not in options AND NOT (having an empty label and value)
if (this.get_select_options().length > 0 && this.get_select_options().filter((option) => option.value == this.modalValue).length === 0 && if (this.get_select_options().length > 0 && this.get_select_options().filter((option) => option.value == this.modelValue).length === 0 &&
!(typeof this.empty_label !== 'undefined' && (this.modalValue||"") === "")) !(typeof this.empty_label !== 'undefined' && (this.modelValue||"") === ""))
{ {
// --> use first option // --> use first option
this.modalValue = ""+this.get_select_options()[0]?.value; // ""+ to cast value of 0 to "0", to not replace with "" this.modelValue = ""+this.get_select_options()[0]?.value; // ""+ to cast value of 0 to "0", to not replace with ""
} }
// Re-set value, the option for it may have just shown up // Re-set value, the option for it may have just shown up
this._inputNode.value = this.modalValue || ""; this._inputNode.value = this.modelValue || "";
} }
} }
@ -111,13 +111,13 @@ export class Et2Select extends Et2WidgetWithSelect
return html``; return html``;
} }
return html` return html`
<option value="" ?selected=${!this.modalValue}>${this.empty_label}</option>`; <option value="" ?selected=${!this.modelValue}>${this.empty_label}</option>`;
} }
_optionTemplate(option : SelectOption) : TemplateResult _optionTemplate(option : SelectOption) : TemplateResult
{ {
return html` return html`
<option value="${option.value}" title="${option.title}" ?selected=${option.value == this.modalValue}> <option value="${option.value}" title="${option.title}" ?selected=${option.value == this.modelValue}>
${option.label} ${option.label}
</option>`; </option>`;
} }
@ -158,7 +158,7 @@ export class Et2SelectBitwise extends Et2Select
expanded_value.push(right); expanded_value.push(right);
} }
} }
this.modalValue = expanded_value; this.modelValue = expanded_value;
this.requestUpdate("value", oldValue); this.requestUpdate("value", oldValue);
} }

View File

@ -67,14 +67,30 @@ export const Et2widgetWithSelectMixin = dedupeMixin((superclass) =>
} }
} }
/**
* Overwritten as sometimes called before this._inputNode is available
*
* @param {*} v - modelValue: can be an Object, Number, String depending on the
* input type(date, number, email etc)
* @returns {string} formattedValue
*/
formatter(v)
{
if (!this._inputNode)
{
return v;
}
return super.formatter(v);
}
set_value(val) set_value(val)
{ {
let oldValue = this.modalValue; let oldValue = this.modelValue;
// Make sure it's a string // Make sure it's a string
val = "" + val; val = "" + val;
this.modalValue = val this.modelValue = val
this.requestUpdate("value", oldValue); this.requestUpdate("value", oldValue);
} }