Simple_form: Remove default classes

Created on 25 May 2016  路  10Comments  路  Source: heartcombo/simple_form

I want to remove the default classes generated by simple_form. my problem is that I can't remove the default classes without removing explicitly set class (config.label_class). The problem with that is that either my markup is polluted with lot of generic classes ('password', 'string', etc..).

My config:

config.input_class = 'my-input-class'
config.label_class = 'my-label-class'
config.generate_additional_classes_for = [:label, :input]

Generates:

= f.label :attribute
= f.input_field :attribute
# <label class="string required my-label-class">label</label>
# <input class="string required my-input-class" type="text" required="required"/>

What I want:

= f.label :attribute
= f.input_field :attribute
# <label class="my-label-class">label</label>
# <input class="my-input-class" type="text" required="required" />

All 10 comments

Not sure I follow, I am using generate_additional_classes_for, the problem is that it add a lot of generic classes ('password', 'string', etc..) despite setting the config.input_class

If you don't want these classes you have to remove the :input key from the array generate_additional_classes_for

correct, but then I will lose my explicitly set config.input_class in the process

config.input_class = 'my-input-class'
config.label_class = 'my-label-class'
config.generate_additional_classes_for = []

generate:

= f.label :attribute
= f.input_field :attribute
# <label>label</label>
# <input type="text" required="required" />

'my-input-class' and 'my-label-class' are missing

I see. In this case you should use the :class option in the wrapper definition.

There's no way to do this system-wide? setting up the :class option everywhere is a bit redundant, specially after having set config.input_class

Yes, there is no way to do this system wide. There global options like input_class are even going to be deprecated in favor of the wrappers API options.

In the config, can you set a wrapper for a simple f.input_field or f.label ? what's the mapping attribute?

I don't remember very well but looking in the code input_field uses the same logic to find a wrapper than a f.input, but label don't use any information from the wrappers.

Ah I see here and here.

input_field should get the wrapper based on the type, except I can confirm doesn't get wrapped at all.

I'm not sure what's going on, but there's a wrapper.options.merge(wrapper: false) in the input_field method that seems to remove wrapper and also inherited class from the wrapper.

Was this page helpful?
0 / 5 - 0 ratings