Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Patch to add html options to the div that wraps the authenticity_token input field

#2044

The DIV tag generated inside form_for and form_tag by default has the style 'margin:0;padding:0' and the input fields inside it (_method and authenticity_token) are hidden, so it usually has no effect on the HTML page, but sometimes you need to have a CSS class on it to avoid some layout/float issues.

This patch adds a configuration option that can be used like this:


config.action_view.html_options_for_extra_tag_in_form = {:class=>'hideMe'}
config.action_view.html_options_for_extra_tag_in_form = {:class=>'hideMe', :style=>'display:none'}

Reported by chris finne · February 22nd, 2009 @ 07:48 PM

State: stale
Milestone: 3.x
Assigned to: nobody
Importance: none

Activity

  1. chris finne
  2. chris finne
  3. Cristi Balan
    Cristi Balan

    I think just having a display: inline on the div, or using a span tag, would solve most of the layout issues.

    Also, I recently came across an issue with this when the form had display: inline and the div caused a linebreak. However, this is sometimes fixable. I was able to style that by adding a class on the form because I didn't have other divs in there:

    form.blah div { display: inline }

    February 25th, 2009 @ 02:30 PM

  4. Philip Hallstrom
    Philip Hallstrom
    • Tag changed from form_for, form_tag, form_tag_helper, patch to authenticity_token, form_for, form_tag, form_tag_helper, patch

    I just ran into this myself. In looking into it I began to wonder why the hidden field is wrapped in a tag at all? My understanding is that hidden fields are inline and don't take up any room in the layout by default so why wrap it?

    At the very least the div tag should have a class added to it and/or have display:none set to remove it from the layout completely.

    But unless there is a reason to wrap it in the first place, why not simply remove the div wrapper entirely?

    April 21st, 2009 @ 09:19 PM

  5. Philip Hallstrom
    Philip Hallstrom

    This patch works on the following:

    Rails version 2.3.2 Edge Rails revision 165d9f13ce4212468b5c2399e0560f23444d9590

    April 21st, 2009 @ 10:06 PM

  6. chris finne
    chris finne

    I don't know the specifics by heart, but my FireFox HTML validator plugin complains if I have an INPUT tag inside a form that isn't wrapped by a DIV or P tag.

    April 22nd, 2009 @ 01:07 AM

  7. Arthur Klepchukov
  8. blaisdellk (at gmail)
  9. Babar O'Cap
  10. Ignacio Carrera
    Ignacio Carrera

    what about simply adding :class => "authenticityTokenWrapper" so you can style it as you like with plain old CSS?

    September 24th, 2009 @ 03:19 AM

  11. ivanoats
  12. ivanoats
    ivanoats

    Although, you can already use CSS to select by the name attribute of the element:

     form#new_model div input[name="authenticity_token"] { display: none; background-color: #fff;}
    

    October 5th, 2009 @ 11:55 PM

  13. Philip Hallstrom
    Philip Hallstrom

    We need to be able to target the DIV though, not the hidden input within it.

    October 6th, 2009 @ 12:28 AM

  14. ivanoats
    ivanoats

    Ok, yeah, I definitely see that. It would be an improvement to have an id on it. I guess you could do this:

    form#new_model div[style="margin: 0pt; padding: 0pt; display: inline;"]
    

    but that seems kinda creaky and not future-proof. It should be by design. The above is just another work-around.

    October 6th, 2009 @ 12:44 AM

  15. adevadeh
    adevadeh

    we've run into the same issue. worked around by copying the output of the form helper into the view, replacing the urls with url_for, and deleting the wrap around div (we have our own div). I would prefer the simple solution of including a className in order to style if needed.

    October 15th, 2009 @ 04:49 AM

  16. billyjr
    billyjr

    Yup, including a className would be the best solution for most of the cases.

    October 15th, 2009 @ 04:57 AM

  17. Joff Williams
    Joff Williams

    "The div is for HTML4.01/XHTML1.0 strict compliance." There's more info about this in the old Rails Trac: http://dev.rubyonrails.org/ticket/10422.

    Adding inline margin/padding is bad practice as it doesn't separate markup from style.
    Although not a perfect solution, my vote would be to add :class => "authenticityTokenWrapper" and perhaps display:none as the default.

    March 9th, 2010 @ 04:26 PM

  18. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  19. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • Tag cleared.

    Automatic cleanup of spam.

    October 19th, 2010 @ 07:07 AM

  20. rails
    rails
    • State changed from new to open

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    April 30th, 2011 @ 01:00 AM

  21. rails
    rails
    • State changed from open to stale

    April 30th, 2011 @ 01:00 AM