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

Should we expect this to work with rails button helper? #390

Open
chrisortman opened this issue Oct 4, 2022 · 2 comments
Open

Should we expect this to work with rails button helper? #390

chrisortman opened this issue Oct 4, 2022 · 2 comments

Comments

@chrisortman
Copy link

There's an example test case here: main...chrisortman:turbo-rails:main

There seem to be a few edge cases depending on your version of rails (different button helper behavior between 6 & 7)

My first question before going into details, should this work? Or is the expectation to create <button formmethod="delete">Delete me!</button> elements without using the FormHelper

@ocarreterom
Copy link

Using the Rails helper for forms submission are not working with formmethod attribute.

This code…

<%= form_with model: @model do |form| %>
  <%= form.button "Delete", formmethod: :delete %>
<% end %>

results in:

<form action="" method="post">
  <input type="hidden" name="_method" value="patch">

  <button type="submit" formmethod="post" name="_method" value="delete">Delete</button>
</form>

According to this function, always "post" will be returned since the value attribute for the <button> submitter is being ignored.

function determineFormMethod(submitter) {
if (submitter instanceof HTMLButtonElement || submitter instanceof HTMLInputElement) {
if (submitter.hasAttribute("formmethod")) {
return submitter.formMethod
} else {
return null
}
} else {
return null
}
}

@ocarreterom
Copy link

ocarreterom commented May 11, 2023

There is an open PR #445

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

2 participants