-
Notifications
You must be signed in to change notification settings - Fork 355
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Allow to configure default form attributes #562
Allow to configure default form attributes #562
Conversation
9cd6c52
to
8d3c786
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this PR. Nice work!
So if I have an application using bootstrap_form
version 4.4.0 (the current released version), and something in my app that depends on forms having role="form"
, will the app break if I just bundle update
to version 4.5.0 (if it includes this PR)?
If so, we need to think of the most practical way to maintain version 4 behaviour, and then make no role="form"
the default for version 5 (the Bootstrap 5 version).
Thanks again for the great work. Don't be discouraged by my comments. We try really hard to make sure we don't break existing applications, except at major version upgrades (which are Bootstrap major version upgrades).
@@ -150,6 +150,18 @@ in `form_with`. | |||
|
|||
`form_with` has some important differences compared to `form_for` and `form_tag`, and these differences apply to `bootstrap_form_with`. A good summary of the differences can be found at: https://m.patrikonrails.com/rails-5-1s-form-with-vs-old-form-helpers-3a5f72a8c78a, or in the [Rails documentation](api.rubyonrails.org). | |||
|
|||
|
|||
## Configuration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to give a little more information to the reader around configuration. I suggest something like a first paragraph that says:
bootstrap_form
can be used out-of-the-box without any configuration. However,bootstrap_form
does have an optional configuration file atconfig/initializers/bootstrap_form.rb
for setting options that affect all generated forms in an application.The current configuration options are:
default_form_attributes
bootstrap_form
versions 4.4.0 and older added arole="form"
attribute to all forms. The W3C validator will raise a warning on forms with arole="form"
attribute.
The actual example will depend on the path we choose for maintaining compatibility for version 4, and enabling the new default for version 5 (which will be the Bootstrap v5 version). See my comments on the pull request.
No. Default configuration still makes
I think, the best way is to declare a Github milestone and create an issue to drop
Updated in ce7bc3d (I'll squash to first commit if it is approved) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! Thanks for clearing up my confusion. I was staring at the file that had the initialization, but it didn't sink in what I was seeing. I just have one more question/suggestion with part A and B. Take a look and let me know what you think.
I really appreciate this PR. It's really nice and clean. Thanks!
options[:html] ||= {} | ||
options[:html][:role] ||= "form" | ||
options[:html].reverse_merge!(BootstrapForm.config.default_form_attributes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to make this work reasonably if the user sets default_form_attributes = nil
. Extra bonus marks if we nicely handle if the user sets default_form_attributes
to something other than a hash. Throwing an error on start-up might be better than waiting until the app actually tries to render a form.
21fa0f9
to
5d2d6a7
Compare
@lcreid Now configuration raises error if unsupported value is given for P.S. Travis fails because of unrelated problem with rubocop configuration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work. Thanks for the PR!
@@ -15,6 +15,8 @@ Gem::Specification.new do |s| | |||
"easy to create beautiful-looking forms using Bootstrap 4" | |||
s.license = "MIT" | |||
|
|||
s.post_install_message = "Default form attribute role=\"form\" will be dropped in 5.0.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -0,0 +1,23 @@ | |||
# frozen_string_literal: true | |||
|
|||
module BootstrapForm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice.
This PR adds ability to configure
bootstrap_form
default form optionsCurrent default value is
{role: "form"}
which is not semantically correct as described in #560. In order to resolve original issue,default_form_attributes
should be set to{}
Closes #561
Closes #560