Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input as radio_buttons: label: false not working but label: "" does. #1788

Open
james-em opened this issue Aug 17, 2022 · 1 comment
Open

Comments

@james-em
Copy link

Environment

  • Ruby 3.1.0
  • Rails 7.0.3.1
  • Simple Form 5.1.0

Current behavior

<%= f.input :change_nature_quebec,
            as: :radio_buttons,
            collection: [[bool_to_text(true), true] ,[bool_to_text(false), false]],
            wrapper: :vertical_collection_inline,
            label: false %>

[BAD]=> Will display "Change nature quebec" as label

<%= f.input :change_nature_quebec,
            as: :radio_buttons,
            collection: [[bool_to_text(true), true] ,[bool_to_text(false), false]],
            wrapper: :vertical_collection_inline,
            label: "" %>
[GOOD]=> Will not display a label

Expected behavior

To never show the label when the value is false.

@martinodonnell
Copy link

martinodonnell commented Nov 18, 2022

I came across this issue while trying to set vertical radio button and checkboxes labels to false. When you add label: false, the label does not get removed. You must do legend_tag: false. This isn't included in the readme.

I noticed in the simple forms bootstrap initializers, the vertical collections create the label using a legend_tag wrapper.

config.wrappers :vertical_collection, item_wrapper_class: 'form-check', item_label_class: 'form-check-label', tag: 'fieldset', class: 'mb-3' do |b| 
   b.use :html5 
   b.optional :readonly 
   b.wrapper :legend_tag, tag: 'legend', class: 'col-form-label pt-0' do |ba| 
     ba.use :label_text 
   end 
   b.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid' 
   b.use :full_error, wrap_with: { class: 'invalid-feedback d-block' } 
   b.use :hint, wrap_with: { class: 'form-text' } 
 end 

The vertical_collection and vertical_collection_inline templates create labels differently. I would propose updating the file to make them follow the same format.

# vertical input for radio buttons and check boxes 
 config.wrappers :vertical_collection, item_wrapper_class: 'form-check', item_label_class: 'form-check-label', tag: 'fieldset', class: 'mb-3' do |b| 
   b.use :html5 
   b.optional :readonly 
   b.use :label, class: 'col-form-label pt-0' <----- Update to this
   b.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid' 
   b.use :full_error, wrap_with: { class: 'invalid-feedback d-block' } 
   b.use :hint, wrap_with: { class: 'form-text' } 
 end 
  
 # vertical input for inline radio buttons and check boxes 
 config.wrappers :vertical_collection_inline, item_wrapper_class: 'form-check form-check-inline', item_label_class: 'form-check-label', tag: 'fieldset', class: 'mb-3' do |b| 
   b.use :html5 
   b.optional :readonly 
   b.use :label, class: 'col-form-label pt-0' <----- Update to this
   b.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid' 
   b.use :full_error, wrap_with: { class: 'invalid-feedback d-block' } 
   b.use :hint, wrap_with: { class: 'form-text' } 
 end 

This means you would update your format to use these.

# Old Syntax
f.input :field, as: :radio_buttons, legend_tag: :false

# Now Syntax
f.input :field, as: :radio_buttons, label: :false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants