Search code examples
ruby-on-railsformssimple-form-for

make simple form radio buttons hidden


How can I get a hidden radio button using simple-form?

I know that simple-form has a :as => :hidden to hide a form field, and a :as => :radio_buttons to display a radio button option... but I can't have two as options on a field... :)

How can I go about this?

What I've tried:

= form.input :type, 
  :as => :radio_buttons,
  :hidden => true, 
  :checked => ...

= form.input :type, 
  :as => [:radio_buttons, :hidden]
  :checked => ...

= form.input :type, 
  :as => :radio_buttons,
  :as => :hidden,
  :checked => ...

Solution

  • "hidden" is a different form of input altogether - it's the same as hidden_field. If you just want to hide a radio from the user (maybe you want to show it again later) you can use "display: none" in the html for the wrapper.

    = form.input :type
      as: radio_buttons
      wrapper_html: { style: "display: none" }
    

    If the input should never be displayed to the user then I'd just leave it out of the page altogether. You're never going to be able to selected it after all.