Validation changes:

- Fix multiplying messages on focus/blur
- Server-side (Manual) messages do not block submit.  Server set it, we'll let server check it.
This commit is contained in:
nathan 2023-04-13 15:06:31 -06:00
parent e4592e822e
commit 3423e680b8

View File

@ -285,7 +285,17 @@ const Et2InputWidgetMixin = <T extends Constructor<LitElement>>(superclass : T)
}
// Collect any ManualMessages
this._messagesHeldWhileFocused = (this.validators || []).filter((validator) => (validator instanceof ManualMessage));
this._messagesHeldWhileFocused = (this.validators || []).filter(
(validator) => (validator instanceof ManualMessage)
);
// Remove ManualMessages from validators list
for(let i = 0; i < this.validators.length; i++)
{
if(this._messagesHeldWhileFocused.indexOf(this.validators[i]) != -1)
{
this.validators.splice(i, 1);
}
}
this.updateComplete.then(() =>
{
@ -501,8 +511,10 @@ const Et2InputWidgetMixin = <T extends Constructor<LitElement>>(superclass : T)
*
* We handle validation errors from the server with ManualMessages, which always "fail".
* If the value is empty, we only validate if the field is required.
*
* @param skipManual Do not run any manual validators, used during submit check. We don't want manual validators to block submit.
*/
async validate()
async validate(skipManual = false)
{
if(this.readonly)
{
@ -562,9 +574,12 @@ const Et2InputWidgetMixin = <T extends Constructor<LitElement>>(superclass : T)
// Run manual validation messages just once, doesn't usually matter what the value is
if(validator instanceof ManualMessage)
{
if(!skipManual)
{
doCheck(values, validator);
}
}
// Only validate if field is required, or not required and has a value
// Don't bother to validate empty fields
else if(this.required || !this.required && this.getValue() != '')