diff --git a/src/core/drive/form_submission.ts b/src/core/drive/form_submission.ts index 7c31ad53c..460c9ba0e 100644 --- a/src/core/drive/form_submission.ts +++ b/src/core/drive/form_submission.ts @@ -80,9 +80,12 @@ export class FormSubmission { get action(): string { const formElementAction = typeof this.formElement.action === "string" ? this.formElement.action : null - return ( - this.submitter?.getAttribute("formaction") || this.formElement.getAttribute("action") || formElementAction || "" - ) + + if (this.submitter?.hasAttribute("formaction")) { + return this.submitter.getAttribute("formaction") || "" + } else { + return this.formElement.getAttribute("action") || formElementAction || "" + } } get body() { diff --git a/src/tests/fixtures/form.html b/src/tests/fixtures/form.html index 30eb182dd..35f958dea 100644 --- a/src/tests/fixtures/form.html +++ b/src/tests/fixtures/form.html @@ -94,6 +94,11 @@

Form

+
+
+ +
+

diff --git a/src/tests/functional/form_submission_tests.ts b/src/tests/functional/form_submission_tests.ts index 244cf4551..f8b6b2a78 100644 --- a/src/tests/functional/form_submission_tests.ts +++ b/src/tests/functional/form_submission_tests.ts @@ -330,6 +330,14 @@ export class FormSubmissionTests extends TurboDriveTestCase { this.assert.deepEqual(await this.getAllSearchParams("button"), []) } + async "test submitter with blank formaction submits to the current page"() { + await this.clickSelector("#blank-formaction button") + await this.nextBody + + this.assert.ok(await this.hasSelector("#blank-formaction"), "overrides form[action] navigation") + this.assert.equal(await this.pathname, "/src/tests/fixtures/form.html") + } + async "test input named action with no action attribute"() { await this.clickSelector("#action-input form.no-action [type=submit]") await this.nextBody