Reputation: 43636
I have the following code:
<%= f.collection_radio_buttons :access_type_id, AccessType.all, :id, :name, group_label_method: 'Access type' %>
and it gives me:
using the following HTML:
<fieldset>
...
<span>
<label for="log_file_access_type_id_1" name="log_file[access_type_id]">
<input id="log_file_access_type_id_1" name="log_file[access_type_id]" type="radio" value="1">
<label class="collection_radio_buttons" for="log_file_access_type_id_1">
public
</label>
</label>
</span>
<span>
<label for="log_file_access_type_id_2" name="log_file[access_type_id]">
<input id="log_file_access_type_id_2" name="log_file[access_type_id]" type="radio" value="2">
<label class="collection_radio_buttons" for="log_file_access_type_id_2">
protected
</label>
</label>
</span>
<span>
<label for="log_file_access_type_id_3" name="log_file[access_type_id]">
<input id="log_file_access_type_id_3" name="log_file[access_type_id]" type="radio" value="3">
<label class="collection_radio_buttons" for="log_file_access_type_id_3">
private
</label>
</label>
</span>
...
</fieldset>
I want to add label
for the radio buttons group. I have try using group_label_method: 'Access type'
but nothing changed.
Is there a way to add such label using simple_form
methods or I should just added as plain HTML?
Upvotes: 0
Views: 2329
Reputation: 12320
try this
simple form http://rubydoc.info/github/plataformatec/simple_form/SimpleForm/FormBuilder:collection_radio_buttons
collection_radio_buttons(:access_type_id, AccessType.all, :id, :name_with_initial) do |b|
b.label(:"data-value" => b.value) { b.radio_button + b.text }
end
Upvotes: 2