Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails simple_form - is it possible to display radio_buttons with just button labels?

This code:

<%= f.input :exploratory, as: :radio_buttons,
  collection: [['Exploratory', true], ['Preparatory', false]],
  label: false %>

Produces this result:

enter image description here

Which is almost exactly what I want - the only problem is the "Exploratory" label above the radio buttons.

Is there a way to have simple_form omit the label for the radio button set and just display the individual button labels? Or if that is not possible, is there a way that I can set the label to a different value.

I'm using Simple Form 4.1.0 with Rails 5.2.3 and Bootstrap 4.3.1.

like image 868
dlu Avatar asked Oct 16 '25 16:10

dlu


2 Answers

This is an issue with the simple_form_bootstrap wrappers, for collection inputs you have to specify legend_tag: false instead of label: false.

like image 185
Roy Avatar answered Oct 19 '25 13:10

Roy


Try adding label: false

<%= f.input :exploratory, as: :radio_buttons,
    collection: [['Exploratory', true], ['Preparatory', false]],
    label: false %>

This should generate the HTML without label

Tested

enter image description here

Also, you can change the label by adding label: 'Changed label'

<%= f.input :exploratory, as: :radio_buttons,
    collection: [['Exploratory', true], ['Preparatory', false]],
    label: 'Changed Label' %>

enter image description here

like image 31
Deepak Mahakale Avatar answered Oct 19 '25 13:10

Deepak Mahakale