3

How can I specify the label class when using f.association instead of f.input in simple_form?

For example, this works:

f.input :name, :label_html => { :class => 'some-class' }

But this doesn't

f.association :periods, :as => :check_boxes, :label_html => { :class => 'some-class' }

Meaning that the label related to :name will have some-class as part of its class, but the label related to :periods won't. Any way to do this without changing f.association to f.input? Thank!

5
  • Hey, what version of SimpleForm are you using? Commented Sep 13, 2012 at 19:06
  • Hi, I'm using simple_form 2.0.2 Commented Sep 13, 2012 at 19:08
  • that's strange. It works on new app, I've just tested it. Could you show your simple_form.rb initializer? Commented Sep 13, 2012 at 19:14
  • not sure what you are expecting to see but label_html adds that custom class only to attribute's input not to every checkboxes. Commented Sep 13, 2012 at 19:17
  • You're right, nash, it adds that class to the attribute's input and not to every checkbox. I would like to add the class to all the checkboxes Commented Sep 21, 2012 at 22:47

1 Answer 1

1

I think you can't add custom class to each label but you can do it for each item wrapper, e.g:

<%= simple_form_for(@user) do |f| %>
  <%= f.association :group, as: :check_boxes, item_wrapper_class: 'custom-class' %>
  <%= f.button :submit %>
<% end %>
Sign up to request clarification or add additional context in comments.

2 Comments

This no longer works in the latest version and adds a custom class to another wrapper span :/ - any solution to changing the label class? :(
Hackeron Try with input_html: { class: 'yourclass'}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.