mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-22 23:00:56 +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 fieldName = this.id;
|
||||||
let feedbackData = [];
|
let feedbackData = [];
|
||||||
this.querySelector("lion-validation-feedback")?.remove();
|
this.querySelector("lion-validation-feedback")?.remove();
|
||||||
const doValidate = async function(validator)
|
const doValidate = async function(validator, value)
|
||||||
{
|
{
|
||||||
if(validator.config.fieldName)
|
if(validator.config.fieldName)
|
||||||
{
|
{
|
||||||
@ -443,7 +443,7 @@ export class Et2Select extends Et2WithSearchMixin(Et2WidgetWithSelect)
|
|||||||
}
|
}
|
||||||
// @ts-ignore [allow-protected]
|
// @ts-ignore [allow-protected]
|
||||||
const message = await validator._getMessage({
|
const message = await validator._getMessage({
|
||||||
modelValue: this.value,
|
modelValue: value,
|
||||||
formControl: this,
|
formControl: this,
|
||||||
fieldName,
|
fieldName,
|
||||||
});
|
});
|
||||||
@ -451,16 +451,21 @@ export class Et2Select extends Et2WithSearchMixin(Et2WidgetWithSelect)
|
|||||||
}.bind(this);
|
}.bind(this);
|
||||||
const resultPromises = validators.map(async validator =>
|
const resultPromises = validators.map(async validator =>
|
||||||
{
|
{
|
||||||
const result = validator.execute(this.value, validator.param, {node: this});
|
let values = this.value;
|
||||||
if(result === true)
|
if (!Array.isArray(values)) values = [values];
|
||||||
{
|
if (!values.length) values = ['']; // so required validation works
|
||||||
await doValidate(validator);
|
values.forEach(async value => {
|
||||||
}
|
const result = validator.execute(value, validator.param, {node: this});
|
||||||
else
|
if(result === true)
|
||||||
{
|
{
|
||||||
result.then(doValidate(validator));
|
await doValidate(validator, value);
|
||||||
return result;
|
}
|
||||||
}
|
else if (result !== false && typeof result.then === 'function')
|
||||||
|
{
|
||||||
|
result.then(doValidate(validator, value));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
await Promise.all(resultPromises);
|
await Promise.all(resultPromises);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user