diff --git a/src/core/drive/form_submission.ts b/src/core/drive/form_submission.ts index ff203f5e7..7c31ad53c 100644 --- a/src/core/drive/form_submission.ts +++ b/src/core/drive/form_submission.ts @@ -51,8 +51,8 @@ export class FormSubmission { state = FormSubmissionState.initialized result?: FormSubmissionResult - static confirmMethod(message: string, _element: HTMLFormElement): boolean { - return confirm(message) + static confirmMethod(message: string, _element: HTMLFormElement): Promise { + return Promise.resolve(confirm(message)) } constructor( @@ -121,7 +121,7 @@ export class FormSubmission { const { initialized, requesting } = FormSubmissionState if (this.needsConfirmation) { - const answer = FormSubmission.confirmMethod(this.confirmationMessage!, this.formElement) + const answer = await FormSubmission.confirmMethod(this.confirmationMessage!, this.formElement) if (!answer) { return } diff --git a/src/core/index.ts b/src/core/index.ts index bac9bc0ee..aba942d45 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -99,6 +99,6 @@ export function setProgressBarDelay(delay: number) { session.setProgressBarDelay(delay) } -export function setConfirmMethod(confirmMethod: (message: string, element: HTMLFormElement) => boolean) { +export function setConfirmMethod(confirmMethod: (message: string, element: HTMLFormElement) => Promise) { FormSubmission.confirmMethod = confirmMethod } diff --git a/src/tests/functional/form_submission_tests.ts b/src/tests/functional/form_submission_tests.ts index 15d2f27b9..34c4e0492 100644 --- a/src/tests/functional/form_submission_tests.ts +++ b/src/tests/functional/form_submission_tests.ts @@ -57,7 +57,7 @@ export class FormSubmissionTests extends TurboDriveTestCase { } async "test from submission with confirmation overriden"() { - await this.remote.execute(() => window.Turbo.setConfirmMethod(() => confirm("Overriden message"))) + await this.remote.execute(() => window.Turbo.setConfirmMethod(() => Promise.resolve(confirm("Overriden message")))) await this.clickSelector("#standard form.confirm input[type=submit]")