Skip to content

Commit

Permalink
Merge branch 'main' into turbo-7-2-0
Browse files Browse the repository at this point in the history
* main:
  Don't assume fetchOptions has a `body` (#384)
  • Loading branch information
dhh committed Sep 19, 2022
2 parents 48d0731 + fb519d5 commit 8cdacc1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/turbo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3996,7 +3996,7 @@ function encodeMethodIntoRequestBody(event) {
if (event.target instanceof HTMLFormElement) {
const {target: form, detail: {fetchOptions: fetchOptions}} = event;
form.addEventListener("turbo:submit-start", (({detail: {formSubmission: {submitter: submitter}}}) => {
const method = submitter && submitter.formMethod || fetchOptions.body.get("_method") || form.getAttribute("method");
const method = submitter && submitter.formMethod || fetchOptions.body && fetchOptions.body.get("_method") || form.getAttribute("method");
if (!/get/i.test(method)) {
if (/post/i.test(method)) {
fetchOptions.body.delete("_method");
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/turbo/fetch_requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export function encodeMethodIntoRequestBody(event) {
const { target: form, detail: { fetchOptions } } = event

form.addEventListener("turbo:submit-start", ({ detail: { formSubmission: { submitter } } }) => {
const method = (submitter && submitter.formMethod) || fetchOptions.body.get("_method") || form.getAttribute("method")
const method = (submitter && submitter.formMethod) || (fetchOptions.body && fetchOptions.body.get("_method")) || form.getAttribute("method")

if (!/get/i.test(method)) {
if (/post/i.test(method)) {
Expand Down

0 comments on commit 8cdacc1

Please sign in to comment.