From 415a8e76a81d284556bf1aa2f8fee3453eb21b3b Mon Sep 17 00:00:00 2001 From: Keith Dahlby Date: Tue, 14 Feb 2023 13:25:14 -0600 Subject: [PATCH 1/5] Check callback directly --- src/index.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index c2584e1..6fec852 100644 --- a/src/index.ts +++ b/src/index.ts @@ -712,9 +712,8 @@ export class ValidationService { validate.then(success => { this.logger.log('Validated (success = %s)', success, form); - let isProgrammaticValidate = !e; if (success) { - if (isProgrammaticValidate) { + if (callback) { callback(true); return; } @@ -736,7 +735,7 @@ export class ValidationService { }); form.dispatchEvent(validationEvent); - if (isProgrammaticValidate) { + if (callback) { callback(false); } else { From 32d5848259acd462e054968aa01e674387f8a8c1 Mon Sep 17 00:00:00 2001 From: Keith Dahlby Date: Tue, 14 Feb 2023 13:41:54 -0600 Subject: [PATCH 2/5] A form without inputs is valid --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 6fec852..6386437 100644 --- a/src/index.ts +++ b/src/index.ts @@ -572,7 +572,7 @@ export class ValidationService { private getFormValidationTask(formUID: string) { let formInputUIDs = this.formInputs[formUID]; if (!formInputUIDs || formInputUIDs.length === 0) { - return null; + return Promise.resolve(true); } let formValidators: Validator[] = []; From 79ff0c1a5a1cc3504109666fd14db9afd7e2be1b Mon Sep 17 00:00:00 2001 From: Keith Dahlby Date: Tue, 14 Feb 2023 14:06:37 -0600 Subject: [PATCH 3/5] Clarify types --- src/index.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/index.ts b/src/index.ts index 6386437..ba8c112 100644 --- a/src/index.ts +++ b/src/index.ts @@ -49,6 +49,11 @@ export type ValidationDirective = { */ export type ValidationProvider = (value: string, element: HTMLInputElement, params: StringKeyValuePair) => boolean | string | Promise; +/** + * Callback to receive the result of validating a form. + */ +export type ValidatedCallback = (success: boolean) => void; + /** * A callback method signature that kickstarts a new validation task for an input element, as a Boolean Promise. */ @@ -385,7 +390,7 @@ export class ValidationService { /** * A key-value map for element UID to its trigger element (submit event for
, input event for