Skip to content

Commit

Permalink
Await for confirm method results (#525)
Browse files Browse the repository at this point in the history
  • Loading branch information
excid3 authored May 1, 2022
1 parent 43f9044 commit 933419b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/core/drive/form_submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> {
return Promise.resolve(confirm(message))
}

constructor(
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>) {
FormSubmission.confirmMethod = confirmMethod
}
2 changes: 1 addition & 1 deletion src/tests/functional/form_submission_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]")

Expand Down

0 comments on commit 933419b

Please sign in to comment.