mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-22 14:41:29 +01:00
fix validation in et2-select had problems with value being an array
eg. mail.compose always displayed "Invalid email" running validator now for each array element or "" for an empty array
This commit is contained in:
parent
6c8e85311f
commit
489eb615ac
@ -435,7 +435,7 @@ export class Et2Select extends Et2WithSearchMixin(Et2WidgetWithSelect)
|
||||
let fieldName = this.id;
|
||||
let feedbackData = [];
|
||||
this.querySelector("lion-validation-feedback")?.remove();
|
||||
const doValidate = async function(validator)
|
||||
const doValidate = async function(validator, value)
|
||||
{
|
||||
if(validator.config.fieldName)
|
||||
{
|
||||
@ -443,7 +443,7 @@ export class Et2Select extends Et2WithSearchMixin(Et2WidgetWithSelect)
|
||||
}
|
||||
// @ts-ignore [allow-protected]
|
||||
const message = await validator._getMessage({
|
||||
modelValue: this.value,
|
||||
modelValue: value,
|
||||
formControl: this,
|
||||
fieldName,
|
||||
});
|
||||
@ -451,16 +451,21 @@ export class Et2Select extends Et2WithSearchMixin(Et2WidgetWithSelect)
|
||||
}.bind(this);
|
||||
const resultPromises = validators.map(async validator =>
|
||||
{
|
||||
const result = validator.execute(this.value, validator.param, {node: this});
|
||||
if(result === true)
|
||||
{
|
||||
await doValidate(validator);
|
||||
}
|
||||
else
|
||||
{
|
||||
result.then(doValidate(validator));
|
||||
return result;
|
||||
}
|
||||
let values = this.value;
|
||||
if (!Array.isArray(values)) values = [values];
|
||||
if (!values.length) values = ['']; // so required validation works
|
||||
values.forEach(async value => {
|
||||
const result = validator.execute(value, validator.param, {node: this});
|
||||
if(result === true)
|
||||
{
|
||||
await doValidate(validator, value);
|
||||
}
|
||||
else if (result !== false && typeof result.then === 'function')
|
||||
{
|
||||
result.then(doValidate(validator, value));
|
||||
return result;
|
||||
}
|
||||
});
|
||||
});
|
||||
await Promise.all(resultPromises);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user