Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat blank [formaction] like a blank [action] #529

Merged
merged 1 commit into from
Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/core/drive/form_submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
5 changes: 5 additions & 0 deletions src/tests/fixtures/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ <h1>Form</h1>
<button type="submit" name="button">Submit</button>
</form>
</div>
<div id="blank-formaction">
<form action="/src/tests/fixtures/one.html">
<button formaction="">Submit</button>
</form>
</div>
<hr>
<div id="action-input">
<form class="no-action">
Expand Down
8 changes: 8 additions & 0 deletions src/tests/functional/form_submission_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down