-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Allow overriding of default configured form_class #1109
Allow overriding of default configured form_class #1109
Conversation
👍 This is a simple solution that does exactly what Boostrap needs. Example: I have an "inline" login form in my nav bar, however every other form on my application is "horizontal". Before this, an entire new helper would be needed just to change the form class. Now, all that would need to change is one variable - simple and prepared for future simple_form versions. |
I'm reluctant to add a new option to set the form class. This will cause confusion with the What we could improve is, if |
I'd be all for that. Plus, it would also better mimic the behavior of the I'd be happy to turn this pull-request into that implementation if you're open to it. |
Please go ahead. It just can't happen in a 3.x version since it may break other people application. Maybe if we want to release in the next 3.x version we should add an option to enable and disable this new behaviour. I don't like the idea of adding a new global option but I don't have a better idea. |
@rafaelfranca One more thing. If we make this change, I think Perhaps in the interim for 3.x, why don't we add In other words, here's how I would configure my application for now in 3.x: # config/initializers/simple_form.rb
config.default_form_class = "form-horizontal"
config.form_class = :simple_form # possibility for a deprecation warning now Result: # defaults
simple_form_for @thing
# <form class="simple_form form-horizontal" ... >
# inline override
simple_form_for @thing, html: { class: "form-inline" }
# <form class="simple_form form-inline" ... > |
Excellent idea 👍 |
This is especially useful with bootstrap forms where you might want to switch to a `form-inline` layout even though the default is a `form-horizontal`. This deprecates SimpleForm.form_class in favor of SimpleForm.default_form_class. e.g. config.default_form_class = "form-horizontal" simple_form_for @user, html: { class: "form-inline" }
@rafaelfranca Pull-request force-pushed to cover the new I made an update to the changelog too, but as a separate commit in case you didn't want me to make that update. |
@rafaelfranca Any word on whether you think this pull-request can make it in before an official 3.1.0 release? |
For me it is good. I remember @carlosantoniodasilva has some concerns but I don't remember what. I'll merge as soon I have time to work on Simple Form. |
Loved to see this merged 👍 |
Allow overriding of default configured form_class
Thanks ❤️ 💚 💙 💛 💜 |
…e new config option "default_form_class". For more about the rationale behind the change, see: heartcombo/simple_form#1109
I was surprised to see that there’s no link between this PR and the issue #1217. Well, now there is :-) |
This is especially useful with bootstrap forms where you might want to switch to a
form-inline
layout even though the default is aform-horizontal
.e.g.
I recognize that this was (somewhat) already proposed and closed in #657 and #639, but I feel like this new implementation is more straight forward, cleaner, and more discoverable without passing around non-standard html attributes. It's merely a config override.
Just throwing this out there.