Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Unable to supply nil value to name attribute #808

Closed
mhuggins opened this Issue · 5 comments

3 participants

@mhuggins

When using a faux model, I should be able to create an input element that does not have a name attribute. In plain old Rails, I can do this via:

text_field_tag(:username, nil, :name => nil)
# <input id="username" type="text"/>

Unfortunately, this nil value seems to be getting overridden when trying to accomplish the same with Formtastic:

<%= f.input :username, :as => :string, :html_input => {:id => 'username', :name => nil} %>
# <input id="username" name="user[username]" type="text">

Am I missing something, or is there some options.merge happening somewhere that is overwriting (or not assigning) my value of nil? (I also tried using false with no luck.)

@justinfrench

text_field_tag is not comparable to anything in Formtastic. A better comparison is f.text_field, which is the form builder version, which means it's bound to the form object. Formtastic is a FormBuilder, thus bound to an object. Incidentally, you can still use both text_field_tag and f.text_field within the Formtastic DSL, but to answer your question...

If you really want no name attribute:

  1. I think :html_input should be :input_html in your example, but if that's just a typo...
  2. I thought your sample would have worked, but if it doesn't (sounds like we're merging options somewhere a little too aggressively)...
  3. Perhaps a blank string would work (:name => ""), or else
  4. Please send a patch :)
@mhuggins

That was just a typo, sorry. ;) I gave empty string a try, and that is good enough for my needs as a workaround, even though it still generates the name="" in the HTML. Thanks!

@mhuggins

Also, after digging into it. f.text_field has the same behavior as Formtastic in this regards, so I guess it's not a Formtastic issue, sorry! :)

@nashby

<3

@nashby

Fixed in rails. :heart:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.