view_component-form
view_component-form copied to clipboard
`label` option for CheckBoxComponent & RadioButtonComponent
Instead of writing:
= f.label :admin
= f.check_box :admin
= f.label :civility, value: "mr"
= f.radio_button :civility, "mr"
= f.label :civility, value: "mrs"
= f.radio_button :civility, "mrs"
you could write:
= f.check_box :admin, label: true
= f.radio_button :civility, "mr", label: true
= f.radio_button :civility, "mrs", label: true
Or maybe it would be better to do it with a group component...
= f.group :admin
= f.check_box :admin
But in the case of radio buttons, we want 1 radio button = 1 label (and no <label> in the group, just the label text). How to do that? Use nested groups?
= f.group :civility, label: false
= f.group :civility, value: "mr"
= f.radio_button :civility, "mr"
= f.group :civility, value: "mr"
= f.radio_button :civility, "mrs"
Interesting approach from GOV.UK:
- https://govuk-form-builder.netlify.app/introduction/labels-captions-hints-and-legends/#radio-buttons-with-a-fully-customised-legend
- https://govuk-form-builder.netlify.app/form-elements/checkboxes/#generating-a-collection-of-checkboxes