From ae4344a196c7e2f4e5ca56d398507f486c9b2b3c Mon Sep 17 00:00:00 2001 From: Jordan Cannon Date: Wed, 1 Nov 2023 04:06:51 -0500 Subject: [PATCH 1/2] Fix unintended submissions in Firefox caused by undefined value --- src/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 2713e30..36e30f7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -860,7 +860,9 @@ export class ValidationService { // Firefox fix: redispatch 'submit' after finished handling this event await new Promise(resolve => setTimeout(resolve, 0)); - this.handleValidated(form, success, e); + if (e) { + this.handleValidated(form, success, e); + } }).catch(error => { this.logger.log('Validation error', error); }).finally(() => { From 2f2096ef4cf00c0683e9249f52dfa9eef7d16da8 Mon Sep 17 00:00:00 2001 From: Jordan Cannon Date: Wed, 1 Nov 2023 16:45:56 -0500 Subject: [PATCH 2/2] Move check for undefined inside handleValidated --- src/index.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/index.ts b/src/index.ts index 36e30f7..f013c99 100644 --- a/src/index.ts +++ b/src/index.ts @@ -697,9 +697,11 @@ export class ValidationService { * @param success The validation result. * @param submitEvent The `SubmitEvent`. */ - handleValidated = (form: HTMLFormElement, success: boolean, submitEvent: SubmitEvent) => { + handleValidated = (form: HTMLFormElement, success: boolean, submitEvent?: SubmitEvent) => { if (success) { - this.submitValidForm(form, submitEvent); + if (submitEvent) { + this.submitValidForm(form, submitEvent); + } } else { this.focusFirstInvalid(form); @@ -860,9 +862,7 @@ export class ValidationService { // Firefox fix: redispatch 'submit' after finished handling this event await new Promise(resolve => setTimeout(resolve, 0)); - if (e) { - this.handleValidated(form, success, e); - } + this.handleValidated(form, success, e); }).catch(error => { this.logger.log('Validation error', error); }).finally(() => {