diff --git a/src/observers/form_submit_observer.ts b/src/observers/form_submit_observer.ts index 5ffd960ba..3c31fe7ce 100644 --- a/src/observers/form_submit_observer.ts +++ b/src/observers/form_submit_observer.ts @@ -1,3 +1,5 @@ +import { getAttribute } from "../util" + export interface FormSubmitObserverDelegate { willSubmitForm(form: HTMLFormElement, submitter?: HTMLElement): boolean formSubmitted(form: HTMLFormElement, submitter?: HTMLElement): void @@ -41,6 +43,7 @@ export class FormSubmitObserver { form && submissionDoesNotDismissDialog(form, submitter) && submissionDoesNotTargetIFrame(form, submitter) && + submissionDoesNotIntegrateWithUJS(form, submitter) && this.delegate.willSubmitForm(form, submitter) ) { event.preventDefault() @@ -65,3 +68,10 @@ 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 218eb2ba1..a01969bbc 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)) { + if (link && doesNotTargetIFrame(link) && doesNotIntegrateWithUJS(link)) { const location = this.getLocationForLink(link) if (this.delegate.willFollowLinkToLocation(link, location, event)) { event.preventDefault() @@ -78,3 +78,10 @@ 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/fixtures/ujs.html b/src/tests/fixtures/ujs.html new file mode 100644 index 000000000..3696d0fa4 --- /dev/null +++ b/src/tests/fixtures/ujs.html @@ -0,0 +1,24 @@ + + +
+ +