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

Links with method not work if used inside another form #340

Closed
davidgil opened this issue Aug 17, 2021 · 3 comments
Closed

Links with method not work if used inside another form #340

davidgil opened this issue Aug 17, 2021 · 3 comments

Comments

@davidgil
Copy link
Contributor

davidgil commented Aug 17, 2021

I detect an issue with the data-turbo-method attribute on links that are included inside another form, this is a follow up of:
#299

In session.ts:
`
convertLinkWithMethodClickToFormSubmission(link: Element) {
const linkMethod = link.getAttribute("data-turbo-method")

if (linkMethod) {
  const form = document.createElement("form")
  form.method = linkMethod
  form.action = link.getAttribute("href") || "undefined"

  link.parentNode?.insertBefore(form, link)
  return dispatch("submit", { cancelable: true, target: form })
} else {
  return false
}

}
`
the "virtual" form created is injected in the parent node of the link, the problem is that if the link is inside another form this functionality dont work. The solution could be to inject the form at the end of body?

`
convertLinkWithMethodClickToFormSubmission(link: Element) {
const linkMethod = link.getAttribute("data-turbo-method")

if (linkMethod) {
  const form = document.createElement("form")
  form.method = linkMethod
  form.action = link.getAttribute("href") || "undefined"

  document.body.appendChild(form)

  return dispatch("submit", { cancelable: true, target: form })
} else {
  return false
}

}
`

@dhh
Copy link
Member

dhh commented Aug 17, 2021

I like that idea. Do make a PR for it 👍

@davidgil
Copy link
Contributor Author

My first PR so...
#341

@dhh dhh closed this as completed Aug 19, 2021
@Intrepidd
Copy link
Contributor

Intrepidd commented Oct 5, 2021

@dhh Can we reopen this issue ? The commit was reverted (#362) so we are still facing this issue. I would be glad to give it a swing, any pointers on the way you would like to see it done ?

Edit: looks like it's being dealt with in #411

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants