Daniel
Daniel

Reputation: 245

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?

Upvotes: 1

Views: 2286

Answers (1)

Mikhail Nikalyukin
Mikhail Nikalyukin

Reputation: 11967

    <%= 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)  } %>

Upvotes: 3

Related Questions