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

Set aria-busy on the form element during a form submission #1110

Merged
merged 1 commit into from
Dec 18, 2023
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
4 changes: 3 additions & 1 deletion src/core/drive/form_submission.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FetchRequest, FetchMethod, fetchMethodFromString, fetchEnctypeFromString, isSafe } from "../../http/fetch_request"
import { expandURL } from "../url"
import { dispatch, getAttribute, getMetaContent, hasAttribute } from "../../util"
import { clearBusyState, dispatch, getAttribute, getMetaContent, hasAttribute, markAsBusy } from "../../util"
import { StreamMessage } from "../streams/stream_message"

export const FormSubmissionState = {
Expand Down Expand Up @@ -117,6 +117,7 @@ export class FormSubmission {
this.state = FormSubmissionState.waiting
this.submitter?.setAttribute("disabled", "")
this.setSubmitsWith()
markAsBusy(this.formElement)
dispatch("turbo:submit-start", {
target: this.formElement,
detail: { formSubmission: this }
Expand Down Expand Up @@ -155,6 +156,7 @@ export class FormSubmission {
this.state = FormSubmissionState.stopped
this.submitter?.removeAttribute("disabled")
this.resetSubmitterText()
clearBusyState(this.formElement)
dispatch("turbo:submit-end", {
target: this.formElement,
detail: { formSubmission: this, ...this.result }
Expand Down
2 changes: 1 addition & 1 deletion src/tests/fixtures/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<body>
<h1>Form</h1>
<div id="standard">
<form action="/__turbo/redirect" method="post" class="redirect">
<form id="standard-form" action="/__turbo/redirect" method="post" class="redirect">
<input type="hidden" name="path" value="/src/tests/fixtures/form.html">
<input type="hidden" name="greeting" value="Hello from a redirect">
<input id="standard-post-form-submit" type="submit" value="form[method=post]">
Expand Down
19 changes: 19 additions & 0 deletions src/tests/functional/form_submission_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,25 @@ test("standard POST form submission with redirect response", async ({ page }) =>
)
})


test("sets aria-busy on the form element during a form submission", async ({ page }) => {
await page.click("#standard form.redirect input[type=submit]")

await nextEventNamed(page, "turbo:submit-start")
assert.equal(
await nextAttributeMutationNamed(page, "standard-form", "aria-busy"),
"true",
"sets [aria-busy] on the form element"
)

await nextEventNamed(page, "turbo:submit-end")
assert.equal(
await nextAttributeMutationNamed(page, "standard-form", "aria-busy"),
null,
"removes [aria-busy] from the form element"
)
})

test("standard POST form submission events", async ({ page }) => {
await page.click("#standard-post-form-submit")

Expand Down