I just updated a very old project and the CSS exploded for my forms.
Took me a while to realize that it all came from:
= simple_form_for user, html: { class: ('compact' if request.xhr?) }
In which the html: { class: ('compact' if request.xhr?) } actually replaced the default class from the config file:
config.default_form_class = 'ui form'
because if request.xhr? is false, then html[:class] is nil, but it still overrides the default class from the config file.
Alright I thought, maybe it comes from having html[:class] as nil, so I changed my code to only pass the html[:class] bit if request.xhr? is true.
That's kind of annoying, but why not.
But then I realized that when request.xhr? is actually true, I also have my forms go unstyled.
So when request.xhr? is true, I have to specify that I want the compact css class, but also to explicitly specify that I still want to keep the default one.
This doesn't look very DRY to me, because I have to repeat the default form class everywhere I want to add an extra class to the default.
I just updated a very old project and the CSS exploded for my forms.
Took me a while to realize that it all came from:
In which the
html: { class: ('compact' if request.xhr?) }
actually replaced the default class from the config file:because if
request.xhr?
isfalse
, thenhtml[:class]
isnil
, but it still overrides the default class from the config file.Alright I thought, maybe it comes from having
html[:class]
asnil
, so I changed my code to only pass thehtml[:class]
bit ifrequest.xhr?
istrue
. That's kind of annoying, but why not.But then I realized that when
request.xhr?
is actuallytrue
, I also have my forms go unstyled.So when
request.xhr?
istrue
, I have to specify that I want thecompact
css class, but also to explicitly specify that I still want to keep the default one.This doesn't look very DRY to me, because I have to repeat the default form class everywhere I want to add an extra class to the default.
It all originate from here it seems: https://github.com/heartcombo/simple_form/commit/1e8bba7eb378da86cabb3d6a0ece9b34998c58e2
And I wonder if it was actually a good move to accept this behavior.
What do you think? Should we revert to an additive behavior instead of substitutive?