This project is archived and is in readonly mode.

#2044 ✓stale
chris finne

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

Reported by chris finne | February 22nd, 2009 @ 07:48 PM | in 3.x

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'}

Comments and changes to this ticket

  • chris finne
  • chris finne
  • Cristi Balan

    Cristi Balan February 25th, 2009 @ 02:30 PM

    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 }

  • Philip Hallstrom

    Philip Hallstrom April 21st, 2009 @ 09:19 PM

    • 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?

  • Philip Hallstrom

    Philip Hallstrom April 21st, 2009 @ 10:06 PM

    This patch works on the following:

    Rails version 2.3.2 Edge Rails revision 165d9f13ce4212468b5c2399e0560f23444d9590

  • chris finne

    chris finne April 22nd, 2009 @ 01:07 AM

    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.

  • Arthur Klepchukov
  • blaisdellk (at gmail)
  • Babar O'Cap
  • Ignacio Carrera

    Ignacio Carrera September 24th, 2009 @ 03:19 AM

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

  • ivanoats
  • ivanoats

    ivanoats October 5th, 2009 @ 11:55 PM

    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;}
    
  • Philip Hallstrom

    Philip Hallstrom October 6th, 2009 @ 12:28 AM

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

  • ivanoats

    ivanoats October 6th, 2009 @ 12:44 AM

    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.

  • adevadeh

    adevadeh October 15th, 2009 @ 04:49 AM

    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.

  • billyjr

    billyjr October 15th, 2009 @ 04:57 AM

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

  • Joff Williams

    Joff Williams March 9th, 2010 @ 04:26 PM

    "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.

  • Jeremy Kemper

    Jeremy Kemper May 4th, 2010 @ 06:48 PM

    • Milestone changed from 2.x to 3.x
  • Jeff Kreeftmeijer

    Jeff Kreeftmeijer October 19th, 2010 @ 07:07 AM

    • Tag cleared.

    Automatic cleanup of spam.

  • rails

    rails April 30th, 2011 @ 01:00 AM

    • 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.

  • rails

    rails April 30th, 2011 @ 01:00 AM

    • State changed from “open” to “stale”
  • csnk

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Referenced by

Pages