I know I can use label_html: { class: 'my-class' } to adjust the class of the label that appears before the collection of radio buttons, but when I use boolean_style: :inline like this:
= f.input :sex, as: :radio_buttons, collection: ['Male', 'Female'], boolean_style: :inline
I do not understand how I would adjust the classes on the labels that come after each individual radio button.
I thought maybe it'd be something like inline_label_html: { class:'my-class' } but that doesn't do anything.
Similarly, input_html: { class: 'my-class' } simply adds the class to the input itself, not the label following the input.
Is there an ability to adjust the classes given to the labels that appear after the input field for a radio button using boolean_style: :inline ?
For reference, here is the html generated by the above code:
<div class="input radio_buttons optional client_sex">
<label class="radio_buttons optional control-label">Sex</label>
<span class="radio">
<input class="radio_buttons optional" id="client_sex_male" name="client[sex]" type="radio" value="Male" />
<label class="collection_radio_buttons" for="client_sex_male">Male</label>
</span>
<span class="radio">
<input class="radio_buttons optional" id="client_sex_female" name="client[sex]" type="radio" value="Female" />
<label class="collection_radio_buttons" for="client_sex_female">Female</label>
</span>
</div>
Please use the mailing list or StackOverflow for questions/help, where a wider community will be able to help you. We reserve the issues tracker for issues only.
Did you find a solution to this?
No I have not.
I posted two questions about this on stackoverflow, but they yielded nothing:
@hackeron I went ahead and posted a javascript / coffeescript workaround that I have been using. Not sure if you were looking for a similar solution, but I thought I'd post it here in case you were interested:
config/initializers/
module RenderRadioComponentClass
private
def render_component(builder)
builder.radio_button + builder.label(class: @options[:item_label_class] + " collection_radio_buttons")
end
end
module RenderCheckboxComponentClass
private
def render_component(builder)
builder.check_box + builder.label(class: @options[:item_label_class] + " collection_check_boxs")
end
end
SimpleForm::Tags::CollectionRadioButtons.prepend(RenderRadioComponentClass)
SimpleForm::Tags::CollectionCheckBoxes.prepend(RenderCheckboxComponentClass)
Most helpful comment
config/initializers/