Skip to content

Commit

Permalink
Restore <form data-remote="true">+<turbo-frame> behavior from 7.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
seanpdoyle committed Oct 6, 2022
1 parent 1b780ba commit 753a7f9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 19 deletions.
11 changes: 1 addition & 10 deletions src/observers/form_submit_observer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { getAttribute } from "../util"

export interface FormSubmitObserverDelegate {
willSubmitForm(form: HTMLFormElement, submitter?: HTMLElement): boolean
formSubmitted(form: HTMLFormElement, submitter?: HTMLElement): void
Expand Down Expand Up @@ -43,10 +41,10 @@ export class FormSubmitObserver {
form &&
submissionDoesNotDismissDialog(form, submitter) &&
submissionDoesNotTargetIFrame(form, submitter) &&
submissionDoesNotIntegrateWithUJS(form, submitter) &&
this.delegate.willSubmitForm(form, submitter)
) {
event.preventDefault()
event.stopImmediatePropagation()
this.delegate.formSubmitted(form, submitter)
}
}
Expand All @@ -68,10 +66,3 @@ function submissionDoesNotTargetIFrame(form: HTMLFormElement, submitter?: HTMLEl

return true
}

function submissionDoesNotIntegrateWithUJS(form: HTMLFormElement, submitter?: HTMLElement): boolean {
const value = getAttribute("data-remote", submitter, form)
const remote = /true/i.test(value || "")

return !remote
}
9 changes: 1 addition & 8 deletions src/observers/link_click_observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class LinkClickObserver {
if (event instanceof MouseEvent && this.clickEventIsSignificant(event)) {
const target = (event.composedPath && event.composedPath()[0]) || event.target
const link = this.findLinkFromClickTarget(target)
if (link && doesNotTargetIFrame(link) && doesNotIntegrateWithUJS(link)) {
if (link && doesNotTargetIFrame(link)) {
const location = this.getLocationForLink(link)
if (this.delegate.willFollowLinkToLocation(link, location, event)) {
event.preventDefault()
Expand Down Expand Up @@ -78,10 +78,3 @@ function doesNotTargetIFrame(anchor: HTMLAnchorElement): boolean {

return true
}

function doesNotIntegrateWithUJS(anchor: HTMLAnchorElement): boolean {
const value = anchor.getAttribute("data-remote")
const remote = /true/i.test(value || "")

return !remote
}
6 changes: 5 additions & 1 deletion src/tests/functional/ujs_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ test.beforeEach(async ({ page }) => {

test("test clicking a [data-remote=true] anchor within a turbo-frame", async ({ page }) => {
await assertRequestLimit(page, 1, async () => {
assert.equal(await page.textContent("#frame h2"), "Frames: #frame")

await page.click("#frame a[data-remote=true]")
await noNextEventOnTarget(page, "frame", "turbo:frame-load")

Expand All @@ -17,10 +19,12 @@ test("test clicking a [data-remote=true] anchor within a turbo-frame", async ({

test("test submitting a [data-remote=true] form within a turbo-frame", async ({ page }) => {
await assertRequestLimit(page, 1, async () => {
assert.equal(await page.textContent("#frame h2"), "Frames: #frame")

await page.click("#frame form[data-remote=true] button")
await noNextEventOnTarget(page, "frame", "turbo:frame-load")

assert.equal(await page.textContent("#frame h2"), "Frames: #frame", "does not navigate the target frame")
assert.equal(await page.textContent("#frame h2"), "Frame: Loaded", "navigates the target frame")
})
})

Expand Down

0 comments on commit 753a7f9

Please sign in to comment.