diff --git a/src/core/drive/form_submission.ts b/src/core/drive/form_submission.ts index e7f884644..088f08e3b 100644 --- a/src/core/drive/form_submission.ts +++ b/src/core/drive/form_submission.ts @@ -74,7 +74,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 e4c48088d..0e7d2a77f 100644 --- a/src/tests/fixtures/form.html +++ b/src/tests/fixtures/form.html @@ -93,6 +93,11 @@

Form

+
+
+ +
+

diff --git a/src/tests/functional/form_submission_tests.ts b/src/tests/functional/form_submission_tests.ts index 6800477eb..7fa99549b 100644 --- a/src/tests/functional/form_submission_tests.ts +++ b/src/tests/functional/form_submission_tests.ts @@ -283,6 +283,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