From 3423e680b8ae5f4540eb731a1e86d7852178c44b Mon Sep 17 00:00:00 2001 From: nathan Date: Thu, 13 Apr 2023 15:06:31 -0600 Subject: [PATCH] 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. --- .../Et2InputWidget/Et2InputWidget.ts | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/api/js/etemplate/Et2InputWidget/Et2InputWidget.ts b/api/js/etemplate/Et2InputWidget/Et2InputWidget.ts index 4069116432..6949425432 100644 --- a/api/js/etemplate/Et2InputWidget/Et2InputWidget.ts +++ b/api/js/etemplate/Et2InputWidget/Et2InputWidget.ts @@ -285,7 +285,17 @@ const Et2InputWidgetMixin = >(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 = >(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) { @@ -563,7 +575,10 @@ const Et2InputWidgetMixin = >(superclass : T) // Run manual validation messages just once, doesn't usually matter what the value is if(validator instanceof ManualMessage) { - doCheck(values, validator); + 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