简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM