simple_form's collection_radio_button and custom label class

前端 未结 2 698
北恋
北恋 2020-12-30 12:26

I\'m trying to make a star rating form with radio collection using FontAwesome, for this I actually need to change the label classes of the collection_radio_button input gen

2条回答
  •  暖寄归人
    2020-12-30 13:18

    In case anyone wonders how to add class to label wrapping radiobutton input when you set boolean_style = :nested here is what I came with:

    You can set option called :item_label_class when calling your input, f.e.:

    <%= f.input :type, as: :radio_buttons,
                       collection: Listing::TYPES.map{ |type| [Listing.translate_type(type), type] },
                       label: false,
                       item_label_class: 'radio' %>
    

    I wanted to automate this stuff, so I defined custom CollectionRadioButtonsInput class. You need to add to method apply_default_collection_options!:

    def apply_default_collection_options!(options)
      super(options)
      options[:item_label_class] == 'radio' if input_type == :radio_buttons
    end
    

提交回复
热议问题