diff --git a/src/observers/form_submit_observer.ts b/src/observers/form_submit_observer.ts index 3c31fe7ce..1ef4ca33d 100644 --- a/src/observers/form_submit_observer.ts +++ b/src/observers/form_submit_observer.ts @@ -1,5 +1,3 @@ -import { getAttribute } from "../util" - export interface FormSubmitObserverDelegate { willSubmitForm(form: HTMLFormElement, submitter?: HTMLElement): boolean formSubmitted(form: HTMLFormElement, submitter?: HTMLElement): void @@ -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) } } @@ -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 -} diff --git a/src/observers/link_click_observer.ts b/src/observers/link_click_observer.ts index a01969bbc..218eb2ba1 100644 --- a/src/observers/link_click_observer.ts +++ b/src/observers/link_click_observer.ts @@ -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() @@ -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 -} diff --git a/src/tests/functional/ujs_tests.ts b/src/tests/functional/ujs_tests.ts index 9188e6cbf..15960620d 100644 --- a/src/tests/functional/ujs_tests.ts +++ b/src/tests/functional/ujs_tests.ts @@ -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") @@ -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") }) })