bootstrap-ruby / bootstrap_form

Official repository of the bootstrap_form gem, a Rails form builder that makes it super easy to create beautiful-looking forms using Bootstrap 5.
MIT License
1.64k stars 352 forks source link

Allow to configure default form attributes #562

Closed sharshenov closed 4 years ago

sharshenov commented 4 years ago

This PR adds ability to configure bootstrap_form default form options

# config/initializers/bootstrap_form.rb
BootstrapForm.configure do |c|
  c.default_form_attributes = { something: "custom" }
end

Current 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 {}

BootstrapForm.configure do |c|
  c.default_form_attributes = {}
end

Closes #561 Closes #560

sharshenov commented 4 years ago

@lcreid

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)?

No. Default configuration still makes role="form" attribute be rendered. So this change is not breaking. It allows to set default_form_attributes with custom hash (like {})

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).

I think, the best way is to declare a Github milestone and create an issue to drop role: "form" from BootstrapForm::Configuration::DEFAULT and then link the issue to the milestone. I could also add a post_install_message to announce this breaking change in upcoming major version. WDTY? Should I?

I'd like to give a little more information to the reader around configuration

Updated in https://github.com/bootstrap-ruby/bootstrap_form/pull/562/commits/ce7bc3d64d2eb71603dffadf2f5e100a9177a933 (I'll squash to first commit if it is approved)

sharshenov commented 4 years ago

@lcreid Now configuration raises error if unsupported value is given for default_form_attributes. I've also added post install message. I'd like to squash all commits if you consider PR good enough.

P.S. Travis fails because of unrelated problem with rubocop configuration