mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-06-26 12:51:52 +02:00
Fix Et2Select / Et2LinkEntry clear button did nothing
Automatic select first entry was re-setting the value after clearing
This commit is contained in:
parent
9f4ce778cc
commit
23f9015331
@ -130,10 +130,15 @@ export class Et2Select extends Et2WithSearchMixin(Et2InvokerMixin(Et2WidgetWithS
|
|||||||
{
|
{
|
||||||
super.firstUpdated(changedProperties);
|
super.firstUpdated(changedProperties);
|
||||||
|
|
||||||
// if _inputNode was not available by the time set_value() got called
|
// If no value is set, choose the first option
|
||||||
if(this.getValue() !== this.value)
|
// Only do this on firstUpdated() otherwise it is impossible to clear the field
|
||||||
|
const valueArray = Array.isArray(this.value) ? this.value : (!this.value ? [] : this.value.toString().split(','));
|
||||||
|
// value not in options AND NOT (having an empty label and value)
|
||||||
|
if(this.select_options.length > 0 && this.select_options.filter((option) => valueArray.find(val => val == option.value)).length === 0 &&
|
||||||
|
!(typeof this.empty_label !== 'undefined' && (this.value || "") === ""))
|
||||||
{
|
{
|
||||||
this.set_value(this.modelValue);
|
// --> use first option
|
||||||
|
this.value = "" + this.select_options[0]?.value; // ""+ to cast value of 0 to "0", to not replace with ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,14 +247,6 @@ export class Et2Select extends Et2WithSearchMixin(Et2InvokerMixin(Et2WidgetWithS
|
|||||||
|
|
||||||
if(changedProperties.has('select_options') || changedProperties.has("value") || changedProperties.has('empty_label'))
|
if(changedProperties.has('select_options') || changedProperties.has("value") || changedProperties.has('empty_label'))
|
||||||
{
|
{
|
||||||
const valueArray = Array.isArray(this.value) ? this.value : (!this.value ? [] : this.value.toString().split(','));
|
|
||||||
// value not in options AND NOT (having an empty label and value)
|
|
||||||
if(this.select_options.length > 0 && this.select_options.filter((option) => valueArray.find(val => val == option.value)).length === 0 &&
|
|
||||||
!(typeof this.empty_label !== 'undefined' && (this.value || "") === ""))
|
|
||||||
{
|
|
||||||
// --> use first option
|
|
||||||
this.value = "" + this.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.value = this.value || "";
|
this.value = this.value || "";
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user