Search code examples
ruby-on-railsformtastic

Adding a class to Formtastic radio button


I have a Formtastic radio button collection which is populated by a number of types:

<%= f.input :type_id, :validate => true, :as => :radio, :collection => Type.where(:object_type => 'Post') %>

However, I want to conditionally add a class to each choice, since some of the radio buttons need to be disabled depending on a certain condition.

For example, a :member_class => param would be ideal, but I don't believe it exists like :member_label and :member_value.

Does Formtastic have the ability to allow this?


Solution

  •     <%= f.input :type_id, :validate => true, :as => :radio,
           :collection => Type.where(:object_type => 'Post'), 
           :input_html => { :class => (:class_name if condition_goes_here)  } %>
    

    or

        <%= f.input :type_id, :validate => true, :as => :radio,
            :collection => Type.where(:object_type => 'Post'),
            :input_html => { :disabled => (:disabled if condition_goes_here)  } %>