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

form_with doesn't render closing tag if no block is given (causing 'confusion' in the browser) #34282

Open
koenhandekyn opened this issue Oct 22, 2018 · 2 comments

Comments

@koenhandekyn
Copy link

koenhandekyn commented Oct 22, 2018

Steps to reproduce

i'm using a table with an HTML5 form in a hidden column per row and references to the form from the input elements according to the HTML5 spec. in this case no 'block' is needed as we just want to have the form tag in isolation.

Expected behavior

form_with should always render a proper form tag and form closing also when no block is passed

Actual behavior

form_with renders the form tag with the standard hidden fields in the first row but it fails to render the closing tag, causing the browsers to get confused.

not closing the form tag

      td.hide
        =form_with model: window, :html => { :id => "window_form_#{window.id}" } 

closing the form tag (empty block)

      td.hide
         =form_with model: window, :html => { :id => "window_form_#{window.id}" } do |f|

key use case

empty forms might seem strange but in modern html it's possible to refer to a form from a button that is not nested within the form itself, which is often really handy to avoid form nesting, or have issues with form/table combinations.

System configuration

Rails version: 5.2.1
Ruby version: 2.5.1

still an issue on

Rails version: 7.0.5
Ruby version: 3.2.2

@OvidiuToma
Copy link

@koenhandekyn, I've managed to reproduced the issue and i've fixed it, I'll create a pull request.

The issue can also be reproduced using the form_tag helper. Basically, what happens is that form_with and form_tag doesn't return a </form> string at the end, and I think the browser deals with the issue by removing the second form for some reason.

@koenhandekyn
Copy link
Author

Ah great to hear!

@koenhandekyn koenhandekyn changed the title form_with doesn't render form tag itself when no block is passed from second call onward form_with doesn't render closing tag if no block is given (causing 'confusion' in the browser) May 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants