Search code examples
ruby-on-railsrubyruby-on-rails-3simple-form

Disabled radio button in simple_form with an array


What is the best way to place two radio button inside a simple_form, where one button is by default disabled and another is selected!

f.input_field :listing_type, as: :radio_buttons, collection: [ "lease", "sale"], :item_wrapper_class => 'inline'

this is giving me two buttons where both are enabled and selected. I want sale to be disabled and lease to be selected by default.


Solution

  • Then you have to make them separately with the same name so that one of them can be disabled.

    <%= f.input :listing_type,     as: :radio_buttons, :disabled: true, input_html: { value: 'lease' } %>
    <%= f.input :listing_type,     as: :radio_buttons, input_html: { value: 'sale' } %>