Hidden Fields #119

jduarte opened this Issue Nov 18, 2009 · 12 comments

4 participants


It's impossible to pass a value to a hidden field even if we specify something like:

<%= f.input :object_id, :as => :hidden, :input_html => {:value => @object.id} %>

By the way,

Great work on the plugin! It's becoming really useful!


This works:

<%= f.input :object_id, :as => :hidden, :value => @object.id %>

...but I can agree that this is a bit inconsistent. What do you think Justin?




I think this should be possible to set the value using html_options. My argument is that it's confusing that only hidden_input lacks the html_options hash just because it's not a visible input.


So you've made the API the same as, say, string input?


Uhm, not sure what you mean, but see the spec. The only input_html-option that works is :value - so that people don't get stuck like jduarte did above. This might need a bit more reflection maybe, but I just pushed this so we got something physical (digital). =)


jduarte said:

It's a little bit off-topic but since we're talking of hidden inputs.
For me it doesn't make sense an hidden input being wrapped in a li tag by default.
I think it can mess up uneccessarely with the CSS.
What do you think?


Yes, maybe hidden fields should be placed in a hidden div in the form header just like Rails does this. Should be straight-forward to do with the content_for helper. Makes sense to me.


Hidden fields cannot be rendered without the LI wrapper because it's invalid to have child elements of an OL or UL that are not an LI, which is why we render them within an LI, and why the default stylesheets supplied with formtastic hide li.hidden inputs. Closing.


But did you reflect on my last suggestion? Se how the security token gets attached to a Rails form. My suggestion would be to stack them all like that.


Ah, I missed the content_for bit of your message. Absolutely, feel free to have a play!

pzi commented Jan 8, 2015

Hello! Has there ever been a solution for this? I'd prefer not having "empty" lis in my source... This also messes with screenreaders.


@pzi on which bit of this thread? Moving the hidden inputs of the list to avoid empty LIs? No progress AFAIK. Feel free to explore this in a PR (preferred) or raise a new issue, there's a high chance that I'd merge this if it were solved, but a low chance that I'll be motivated to do the work myself in the near term :)

pzi commented Jan 8, 2015

Yeah, the bit that adds the hidden fields into div of the form, like rails does, as suggested by @grimen.

Unfortunately, I am no Ruby developer. So chances that I can do it myself are very slim. I can raise a new issue for sure though... :)

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment