Skip to content

Commit 13af7bd

Browse files
lcreidtaylorthurlowthimodonvcseelus
authored
Change main branch to Bootstrap 5 (bootstrap-ruby#611)
* Start README for Bootstrap 5 * Preliminary support for Bootstrap 5 (bootstrap-ruby#567) * Switch demo bootstrap JS include URL * Remove "custom-control" support from radios and check boxes In 5.0 they are consolidated into the .form-check class, and no longer need to be treated as separate cases. Relevant tests will be fixed or removed in the next commit. * Remove "custom-control" tests for radios and check boxes * Rename ".custom-file" to ".form-file" * Change all ".form-group" uses to ".mb-3" Bootstrap 5 is now recommending using bottom margin utilities to control group spacing, and has removed ".form-group" entirely. * Replace ".form-row" with gutter utils (".g-3") Some methods in FormGroup were refactored to meet a RuboCop lint complexity requirement. I don't personally think the refactor is necessary but it won't pass CI without it. * Replace ".form-inline" where necessary Bootstrap 5 removes ".form-inline" in favor of the usage of ".col-auto" and the new gutter utilities. * Remove wrapper divs for elements prepended/appended to input groups Bootstrap 5 removes ".input-group-prepend" and ".input-group-append", they are no longer necessary. You can now add buttons and ".input-group-text" as direct children of the input groups. * Add ".form-label" to all generated label tags * Fix broken tests after label class change * Fix switch style check boxes My heavy-handedness with the previous commits removed the ability to use switch style checkboxes when I removed the custom check box classes. * Update switch checkbox syntax in README.md * Add anchors for stricter #classes_include_gutters? * Handle string or array of classes for check boxes and radio buttons The Rails view helpers that accept a `class` option accept both single strings and arrays of strings, so this change makes the CSS class array builder agnostic to the input type. I'm now also noticing that the result already had `#flatten` called on it, so this probably wasn't an issue, but this is nicer! * Use only form-check-label class for check box and radio button labels Thanks to @thimo for catching this one. * Change select box class from "form-control" to "form-select" This required some extra effort because all the select forms inherited their control class from the base input class. * Add upgrade doc and update gemspec * Remove role="form" (bootstrap-ruby#571) * Fix tests in bootstrap-5 branch. Fixes bootstrap-ruby#582 (bootstrap-ruby#583) * Fix tests for Rails updates * Fix Rubocop offenses Dangerfile:48:3: C: [Correctable] Style/SoleNestedConditional: Consider merging nested conditions into outer if conditions. if IO.read("CHANGELOG.md").scan(/^\s*[-\*] Your contribution here/i).count < 3 ^^ Dangerfile:48:42: C: [Correctable] Style/RedundantRegexpEscape: Redundant escape inside regexp literal if IO.read("CHANGELOG.md").scan(/^\s*[-\*] Your contribution here/i).count < 3 ^^ bootstrap_form.gemspec:27:3: W: Lint/ConstantDefinitionInBlock: Do not define constants this way within a block. (https://rubystyle.guide#no-constant-definition-in-block) REQUIRED_RAILS_VERSION = ">= 5.2".freeze ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ demo/config/puma.rb:7:21: C: [Correctable] Style/RedundantFetchBlock: Use fetch("RAILS_MAX_THREADS", 5) instead of fetch("RAILS_MAX_THREADS") { 5 }. (https://github.com/JuanitoFatas/fast-ruby#hashfetch-with-argument-vs-hashfetch--block-code) threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ demo/config/puma.rb:12:17: C: [Correctable] Style/RedundantFetchBlock: Use fetch("PORT", 3000) instead of fetch("PORT") { 3000 }. (https://github.com/JuanitoFatas/fast-ruby#hashfetch-with-argument-vs-hashfetch--block-code) port ENV.fetch("PORT") { 3000 } ^^^^^^^^^^^^^^^^^^^^^^ lib/bootstrap_form.rb:5:11: C: [Correctable] Style/StringConcatenation: Prefer string interpolation to string concatenation. (https://rubystyle.guide#string-interpolation) require Gem::Specification.find_by_name("actiontext").gem_dir + ... ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lib/bootstrap_form/components/validation.rb:17:22: C: [Correctable] Style/ClassEqualityComparison: Use instance_of?(Class) instead of comparing classes. (https://rubystyle.guide#instance-of-vs-class-comparison) target = obj.class == Class ? obj : obj.class ^^^^^^^^^^^^^^ lib/bootstrap_form/form_builder.rb:48:5: W: [Correctable] Lint/RedundantCopDisableDirective: Unnecessary disabling of Metrics/AbcSize. # rubocop:disable Metrics/AbcSize ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lib/bootstrap_form/form_group_builder.rb:24:9: C: [Correctable] Style/ExplicitBlockArgument: Consider using explicit block argument in the surrounding method's signature over yield. (https://rubystyle.guide#block-argument) form_group(method, form_group_options) { yield } ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lib/bootstrap_form/form_group_builder.rb:32:59: C: [Correctable] Style/SoleNestedConditional: Consider merging nested conditions into outer unless conditions. options[:required] = form_group_required(options) if options.key?(:skip_required) ^^ lib/bootstrap_form/form_group_builder.rb:60:7: C: [Correctable] Style/RedundantAssignment: Redundant assignment before returning detected. hash = { ... ^^^^^^^^ lib/bootstrap_form/helpers/bootstrap.rb:25:44: W: [Correctable] Lint/RedundantCopDisableDirective: Unnecessary disabling of Metrics/AbcSize. def alert_message(title, options={}) # rubocop:disable Metrics/AbcSize ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ test/test_helper.rb:7:18: C: [Correctable] Style/RedundantFileExtensionInRequire: Redundant .rb file extension detected. (https://rubystyle.guide#no-explicit-rb-to-require) require_relative "../demo/config/environment.rb" * Update CHANGELOG * Add gemfile for Rails 6.1 * Run Travis against latest Ruby versions * Update tests to both handle Rails 5.2/6 and Rails 6.1 * Step down 1 minor version for Ruby as Travis is not yet ready * Update changelog * Support Bootstrap 5 floating labels. Fixes bootstrap-ruby#573 (bootstrap-ruby#584) * Support floating labels * Add tests for floating labels * Update demo app with floating labels section * Add floating labels to CHANGELOG * Describe floating labels in README * Fix rubop offense for block length lib/bootstrap_form/inputs/base.rb:8:7: C: Metrics/BlockLength: Block has too many lines. [26/25] class_methods do ... ^^^^^^^^^^^^^^^^ * Fix capitalization * Use <<~ instead of strip_heredoc * Simplify rendering of file_field for Bootstrap 5. Fixes bootstrap-ruby#572 (bootstrap-ruby#581) * Use Bootstrap 5 beta 3 CDN libraries in demo app Links to both CSS and JS libraries taken from https://getbootstrap.com/docs/5.0/getting-started/introduction/ * Remove linking ../images Folder doesn’t exist and causes the error "ActionView::Template::Error (link_tree argument must be a directory)" * Cleanup generated HTML for file upload as per Bootstrap 5 See bootstrap-ruby#572 * Update tests for new file upload rendering * Add changelog entry * Fix Rubocop offense on whitespace lib/bootstrap_form/inputs/file_field.rb:10:52: C: [Correctable] Layout/SpaceAroundEqualsInParameterDefault: Surrounding space detected in default value assignment. (https://rubystyle.guide#spaces-around-equals) def file_field_with_bootstrap(name, options = {}) ^^^ Co-authored-by: Larry Reid <[email protected]> * Get rid of `heredoc` on `bootstrap-5` branch (bootstrap-ruby#591) * Ignore RubyMine config directory * Initial setup of GitHb Actions * Run tests for rails 5 and rails 6 * Run tests for rails 5 and rails 6 + run lint job * GH Actions: Correct gemfile names * GH Actions: Only run the test task in the matrix. rubocop is run in the separate Lint job. * GH Actions: Separate the Danger run for better output * GH Actions: Run rubocop directly instead of as a Rake task. Allow autocorrectable offences. * GH Actions: Only run Danger for pull requests * GH Actions: Try to calm RuboCop * Use the default Gemfile to pick up rubocop.yml * GH Actions: Ignore the vendor directory for rubocop * Forward the options as keyword arguments * Test Rails 6.1 and skip Rails 5.2 + Ruby 3.0 * Fix Rails 6.1 tests on master (bootstrap-ruby#586) * Fix tests for Rails 6.1 * Fix Rubocop offenses bootstrap_form.gemspec:27:29: C: Gemspec/RequiredRubyVersion: required_ruby_version (2.5, declared in bootstrap_form.gemspec) and TargetRubyVersion (2.7, which may be specified in .rubocop.yml) should be equal. s.required_ruby_version = ">= 2.5" ^^^^^^^^ lib/bootstrap_form/form_group.rb:14:30: C: [Correctable] Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line. (https://rubystyle.guide#no-double-indent) :input_group_class, :label_col, :control_col, ^^^^^^^^^^^^^^^^^^ lib/bootstrap_form/form_group.rb:15:30: C: [Correctable] Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line. (https://rubystyle.guide#no-double-indent) :add_control_col_class, :layout, :prepend)) do ^^^^^^^^^^^^^^^^^^^^^^ test/bootstrap_form_test.rb:123:103: C: [Correctable] Style/IfUnlessModifier: Modifier form of if makes the line too long. (https://rubystyle.guide#if-as-a-modifier) <form accept-charset="UTF-8" action="/users" method="post" role="form" #{'data-remote="true"' if ::Rails::VERSION::STRING < "6.1"}> ^^ test/bootstrap_form_test.rb:123:133: C: [Correctable] Style/StringLiteralsInInterpolation: Prefer single-quoted strings inside interpolations. <form accept-charset="UTF-8" action="/users" method="post" role="form" #{'data-remote="true"' if ::Rails::VERSION::STRING < "6.1"}> ^^^^^ test/bootstrap_rich_text_area_test.rb:23:54: C: [Correctable] Style/StringLiteralsInInterpolation: Prefer single-quoted strings inside interpolations. "http://test.host/rails/active_storage/blobs/#{"redirect/" if ::Rails::VERSION::STRING >= "6.1"}:signed_id/:filename" ^^^^^^^^^^^ test/bootstrap_rich_text_area_test.rb:23:97: C: [Correctable] Style/StringLiteralsInInterpolation: Prefer single-quoted strings inside interpolations. "http://test.host/rails/active_storage/blobs/#{"redirect/" if ::Rails::VERSION::STRING >= "6.1"}:signed_id/:filename" ^^^^^ * Include Rails 6.1 in Travis tests + update Ruby versions * Update CHANGELOG * Rails Edge requires Ruby 2.7+ * Remove rubocop_todo and fix Rubocop offenses * Replace strip_heredoc with <<~ (bootstrap-ruby#587) * Replace strip_heredoc with <<~ Also fix newly detected Rubocop offenses on indentation * Update CHANGELOG * Simplify Dockerfile and add documentation (bootstrap-ruby#588) * Simplify Dockerfile and add documentation * A few more additions to .gitignore * Ignore gems placed when using Dockerfile (bootstrap-ruby#590) * Fix formatting and heredoc * Fix bad merge Co-authored-by: Uwe Kubosch <[email protected]> Co-authored-by: Uwe Kubosch <[email protected]> Co-authored-by: Thimo Jansen <[email protected]> * Cherry pick some commits from `main` (bootstrap-ruby#594) * Change default branch to `main` (bootstrap-ruby#592) * Change default branch to `main` * Add GitHub token for Danger * Change default branch to `main` (bootstrap-ruby#592) * Change default branch to `main` * Add GitHub token for Danger * Fix deprecation that I broke again * Errors on invalid feedback (bootstrap-ruby#580) * Use "invalid-feedback" class name for errors_on * Add custom class option for errors_on helper * Improve tests, docs and changelog Co-authored-by: Larry Reid <[email protected]> * README: Use GH Actions badge, drop Travis badge, configuration file (bootstrap-ruby#600) * README: Use GH Actions badge, drop Travis badge * Delete unused TravisCI configuration file * Update README for release of 5.0 Co-authored-by: Taylor Thurlow <[email protected]> Co-authored-by: Thimo Jansen <[email protected]> Co-authored-by: Uwe Kubosch <[email protected]> Co-authored-by: Uwe Kubosch <[email protected]> Co-authored-by: Chrıs Seelus <[email protected]> Co-authored-by: Olle Jonsson <[email protected]>
1 parent 0e763b7 commit 13af7bd

34 files changed

+769
-1012
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@
66

77
### New features
88

9+
* [#572](https://github.com/bootstrap-ruby/bootstrap_form/issues/572): Simplify the formatting of the file upload control to follow the new Bootstrap 5 styles
10+
* [#573](https://github.com/bootstrap-ruby/bootstrap_form/issues/573): Add support for Bootstrap 5's floating labels
11+
12+
### Bugfixes
13+
14+
* [#582](https://github.com/bootstrap-ruby/bootstrap_form/issues/582): Fix tests in bootstrap-5 branch, removes Rubocop offenses, and adds testing with Rails 6.1.
15+
16+
## [5.0.0.alpha1][]
17+
18+
### Breaking changes
19+
20+
* [#569] Remove `role="form"` from the default generated form HTML so forms pass W3C validation. (Only a breaking change if you depended on the `form` attribute. `bootstrap_form` doesn't depend on it.)
21+
22+
### New features
23+
924
* Your contribution here!
1025

1126
### Bugfixes

Dangerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ end
4444
# ------------------------------------------------------------------------------
4545
# Did you remove the CHANGELOG's "Your contribution here!" line?
4646
# ------------------------------------------------------------------------------
47-
if has_changelog_changes && (IO.read("CHANGELOG.md").scan(/^\s*[-*] Your contribution here/i).count < 3)
47+
if has_changelog_changes && IO.read("CHANGELOG.md").scan(/^\s*[-*] Your contribution here/i).count < 3
4848
raise(
4949
"Please put the `- Your contribution here!` line back into CHANGELOG.md.",
5050
sticky: false

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ gemspec path: __dir__
55
# Uncomment and change rails version for testing purposes
66
# gem "rails", "~> 5.2.0"
77
# gem "rails", "~> 6.0.0"
8+
# gem "rails", "~> 6.1.0"
89
# gem "rails", git: "https://github.com/rails/rails.git"
910

1011
group :development do
@@ -17,7 +18,6 @@ group :development do
1718
end
1819

1920
group :test do
20-
# can relax version requirement for Rails 5.2.beta3+
2121
gem "diffy"
2222
gem "equivalent-xml"
2323
gem "mocha"

README.md

Lines changed: 61 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
If you are using Bootstrap v3, refer to the legacy [legacy-2.7](https://github.com/bootstrap-ruby/bootstrap_form/tree/legacy-2.7) branch.
2-
3-
This is a new take on the `bootstrap_form` README. Please leave comments at: #520. You can go back to the traditional [README](/OLD-README.md).
4-
5-
---
6-
71
# bootstrap_form
82

93
[![Ruby](https://github.com/bootstrap-ruby/bootstrap_form/actions/workflows/ruby.yml/badge.svg)](https://github.com/bootstrap-ruby/bootstrap_form/actions/workflows/ruby.yml)
104
[![Gem Version](https://badge.fury.io/rb/bootstrap_form.svg)](https://rubygems.org/gems/bootstrap_form)
115

12-
`bootstrap_form` is a Rails form builder that makes it super easy to integrate Bootstrap v4-style forms into your Rails application. It provides form helpers that augment the Rails form helpers. `bootstrap_forms`'s form helpers generate the form field and its label and all the Bootstrap mark-up required for proper Bootstrap display. `bootstrap_form` also provides:
6+
`bootstrap_form` is a Rails form builder that makes it super easy to integrate Bootstrap v5-style forms into your Rails application. It provides form helpers that augment the Rails form helpers. `bootstrap_forms`'s form helpers generate the form field and its label and all the Bootstrap mark-up required for proper Bootstrap display. `bootstrap_form` also provides:
137

148
* [Validation error messages](#validation-and-errors) below the field they correspond to, by default. You can also put the error messages after the label, or turn off `bootstrap_form`'s validation error handling and do it yourself. _Note that this applies to Rails-generated validation messages._ HTML 5 client-side validation and Rails validation out of the box don't really work well together. One discussion of the challenges and some solutions is [here](https://www.jorgemanrubia.com/2019/02/16/form-validations-with-html5-and-modern-rails/)
159
* Automatic [mark-up for the `required` attribute](#required-fields) on required fields.
@@ -33,14 +27,14 @@ Some other nice things that `bootstrap_form` does for you are:
3327

3428
* Ruby 2.5+
3529
* Rails 5.2+
36-
* Bootstrap 4.0+
30+
* Bootstrap 5.0+
3731

3832
## Installation
3933

4034
Add it to your Gemfile:
4135

4236
```ruby
43-
gem "bootstrap_form", "~> 4.0"
37+
gem "bootstrap_form", "~> 5.0"
4438
```
4539

4640
Then:
@@ -79,12 +73,12 @@ This generates the following HTML:
7973

8074
```html
8175
<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post">
82-
<div class="form-group">
83-
<label for="user_email">Email</label>
76+
<div class="mb-3">
77+
<label class="form-label" for="user_email">Email</label>
8478
<input class="form-control" id="user_email" name="user[email]" type="email">
8579
</div>
86-
<div class="form-group">
87-
<label for="user_password">Password</label>
80+
<div class="mb-3">
81+
<label class="form-label" for="user_password">Password</label>
8882
<input class="form-control" id="user_password" name="user[password]" type="password">
8983
</div>
9084
<div class="form-check">
@@ -125,14 +119,14 @@ To get started, just use the `bootstrap_form_with` helper in place of `form_with
125119
This generates:
126120

127121
```html
128-
<form role="form" action="/users" accept-charset="UTF-8" method="post">
122+
<form action="/users" accept-charset="UTF-8" method="post">
129123
<input name="utf8" type="hidden" value="&#x2713;" />
130-
<div class="form-group">
131-
<label class="required" for="user_email">Email</label>
124+
<div class="mb-3">
125+
<label class="form-label required" for="user_email">Email</label>
132126
<input class="form-control" type="email" value="[email protected]" name="user[email]" />
133127
</div>
134-
<div class="form-group">
135-
<label for="user_password">Password</label>
128+
<div class="mb-3">
129+
<label class="form-label" for="user_password">Password</label>
136130
<input class="form-control" type="password" name="user[password]" />
137131
<small class="form-text text-muted">A good password should be at least six characters long</small>
138132
</div>
@@ -150,7 +144,6 @@ in `form_with`.
150144

151145
`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).
152146

153-
154147
## Configuration
155148

156149
`bootstrap_form` can be used out-of-the-box without any configuration. However, `bootstrap_form` does have an optional configuration file at `config/initializers/bootstrap_form.rb` for setting options that affect all generated forms in an application.
@@ -159,14 +152,14 @@ The current configuration options are:
159152

160153
| Option | Default value | Description |
161154
|---------------------------|------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
162-
| `default_form_attributes` | `{role: "form"}` | version [2.2.0](https://github.com/bootstrap-ruby/bootstrap_form/blob/main/CHANGELOG.md#220-2014-09-16) added a role="form" attribute to all forms. The W3C validator will raise a **warning** on forms with a role="form" attribute. Set this option to `{}` to make forms be W3C compliant. |
163-
155+
| `default_form_attributes` | | `bootstrap_form` versions 3 and 4 added a role="form" attribute to all forms. The W3C validator will raise a **warning** on forms with a role="form" attribute. `bootstrap_form` version 5 drops this attribute by default. Set this option to `{ role: "form" }` to make forms non-compliant with W3C, but generate the `role="form"` attribute like `bootstrap_form` versions 3 and 4. |
164156

165157
Example:
158+
166159
```ruby
167160
# config/initializers/bootstrap_form.rb
168161
BootstrapForm.configure do |c|
169-
c.default_form_attributes = {} # to make forms W3C compliant
162+
c.default_form_attributes = { role: "form" } # to make forms non-compliant with W3C.
170163
end
171164
```
172165

@@ -319,7 +312,7 @@ To add a class to the input group wrapper, use the `:input_group_class` option.
319312

320313
### Additional Form Group Attributes
321314

322-
Bootstrap mark-up dictates that most input field types have the label and input wrapped in a `div.form-group`.
315+
Bootstrap mark-up dictates that most input field types have the label and input wrapped in a `div.mb-3`.
323316

324317
If you want to add an additional CSS class or any other attribute to the form group div, you can use the `wrapper: { class: 'additional-class', data: { foo: 'bar' } }` option.
325318

@@ -330,8 +323,8 @@ If you want to add an additional CSS class or any other attribute to the form gr
330323
Which produces the following output:
331324

332325
```erb
333-
<div class="form-group has-warning" data-foo="bar">
334-
<label class="form-control-label" for="user_name">Id</label>
326+
<div class="mb-3 has-warning" data-foo="bar">
327+
<label class="form-label form-control-label" for="user_name">Id</label>
335328
<input class="form-control" id="user_name" name="user[name]" type="text">
336329
</div>
337330
```
@@ -404,10 +397,10 @@ Check boxes and radio buttons are wrapped in a `div.form-check`. You can add cla
404397

405398
### Switches
406399

407-
To render checkboxes as switches with Bootstrap 4.2+, use `custom: :switch`:
400+
To render checkboxes as switches with Bootstrap 4.2+, use `switch: true`:
408401

409402
```erb
410-
<%= f.check_box :remember_me, custom: :switch %>
403+
<%= f.check_box :remember_me, switch: true %>
411404
```
412405

413406
### Collections
@@ -440,8 +433,8 @@ You can create a static control like this:
440433
Here's the output for a horizontal layout:
441434

442435
```html
443-
<div class="form-group">
444-
<label class="col-sm-2 form-control-label" for="user_email">Email</label>
436+
<div class="mb-3">
437+
<label class="form-label col-sm-2 form-control-label" for="user_email">Email</label>
445438
<div class="col-sm-10">
446439
<input class="form-control-plaintext" id="user_email" name="user[email]" readonly="readonly" type="text" value="[email protected]"/>
447440
</div>
@@ -553,8 +546,8 @@ If you're using Rails 6, `bootstrap_form` supports the `rich_text_area` helper.
553546
will be rendered as:
554547

555548
```html
556-
<div class="form-group">
557-
<label for="user_life_story">Life story</label>
549+
<div class="mb-3">
550+
<label class="form-label" for="user_life_story">Life story</label>
558551
<input type="hidden" name="user[life_story]" id="user_life_story_trix_input_user"/>
559552
<trix-editor id="user_life_story" data-blob-url-template="http://test.host/rails/active_storage/blobs/:signed_id/:filename" data-direct-upload-url="http://test.host/rails/active_storage/direct_uploads" input="user_life_story_trix_input_user" class="trix-content form-control"/>
560553
</trix-editor>
@@ -700,6 +693,21 @@ The `custom` option can be used to replace the browser default styles for check
700693
<% end %>
701694
```
702695

696+
### Floating Labels
697+
698+
The `floating` option can be used to enable Bootstrap 5's floating labels. This option is supported on text fields
699+
and dropdowns. Here's an example:
700+
701+
```erb
702+
<%= bootstrap_form_for(@user) do |f| %>
703+
<%= f.email_field :email, floating: true %>
704+
<%= f.password_field :password, floating: true %>
705+
<%= f.password_field :password, floating: true %>
706+
<%= f.select :status, [["Active", 1], ["Inactive", 2]], include_blank: "Select a value", floating: true %>
707+
<%= f.submit "Log In" %>
708+
<% end %>
709+
```
710+
703711
## Validation and Errors
704712

705713
Rails normally wraps fields with validation errors in a `div.field_with_errors`, but this behaviour isn't consistent with Bootstrap 4 styling. By default, `bootstrap_form` generations in-line errors which appear below the field. But it can also generate errors on the label, or not display any errors, leaving it up to you.
@@ -710,8 +718,8 @@ By default, fields that have validation errors will be outlined in red and the
710718
error will be displayed below the field. Here's an example:
711719

712720
```html
713-
<div class="form-group">
714-
<label class="form-control-label" for="user_email">Email</label>
721+
<div class="mb-3">
722+
<label class="form-label form-control-label" for="user_email">Email</label>
715723
<input class="form-control is-invalid" id="user_email" name="user[email]" type="email" value="">
716724
<small class="invalid-feedback">can't be blank</small>
717725
</div>
@@ -788,8 +796,7 @@ Which outputs:
788796

789797
### Errors On
790798

791-
If you want to display a custom inline error for a specific attribute not
792-
represented by a form field, use the `errors_on` helper.
799+
If you want to display a custom inline error for a specific attribute not represented by a form field, use the `errors_on` helper.
793800

794801
```erb
795802
<%= f.errors_on :tasks %>
@@ -798,7 +805,7 @@ represented by a form field, use the `errors_on` helper.
798805
Which outputs:
799806

800807
```html
801-
<div class="alert alert-danger">Tasks can't be blank.</div>
808+
<div class="invalid-feedback">Tasks can't be blank.</div>
802809
```
803810

804811
You can hide the attribute name like this:
@@ -810,7 +817,19 @@ You can hide the attribute name like this:
810817
Which outputs:
811818

812819
```html
813-
<div class="alert alert-danger">can't be blank.</div>
820+
<div class="invalid-feedback">can't be blank.</div>
821+
```
822+
823+
You can also use a custom class for the wrapping div, like this:
824+
825+
```erb
826+
<%= f.errors_on :tasks, custom_class: 'custom-error' %>
827+
```
828+
829+
Which outputs:
830+
831+
```html
832+
<div class="custom-error">can't be blank.</div>
814833
```
815834

816835
## Required Fields
@@ -874,6 +893,10 @@ If you're considering contributing to bootstrap_form,
874893
please review the [Contributing](/CONTRIBUTING.md)
875894
document first.
876895

896+
## Previous Version
897+
898+
If you're looking for `bootstrap_form` for Bootstrap 4, go [here](https://github.com/bootstrap-ruby/bootstrap_form/tree/bootstrap-4).
899+
877900
## License
878901

879-
MIT License. Copyright 2012-2020 Stephen Potenza (https://github.com/potenza) and others
902+
MIT License. Copyright 2012-2021 Stephen Potenza (https://github.com/potenza) and others

UPGRADE-5.0.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Upgrading to `bootstrap_form` 5.0
2+
3+
We made every effort to make the upgrade from `bootstrap_form` v4 (Bootstrap 4) to `bootstrap_form` 5.0 (Bootstrap 5) as easy as possible. However, Bootstrap 5 is fundamentally different from Bootstrap 4, so some changes may be necessary in your code.
4+
5+
## Bootstrap 5 Changes
6+
7+
Upgrading `bootstrap_form` to version 5 means you must upgrade your whole application to Bootstrap 5. Read the [Bootstrap 5 migration guide](https://v5.getbootstrap.com/docs/5.0/migration/) to see what changes you have to make to your views. This will also help you understand changes you might have to make to your `bootstrap_form` code.
8+
9+
## `bootstrap_form` Version 5 Changes
10+
11+
## No `role="form"` Attribute
12+
13+
As explained in #560, the `role="form"` attribute generated by `bootstrap_4` caused the W3C validator to output a warning. The `role="form"` attribute was deprecated in the 4.5.0 and is being remove completely in 5.0.0. This has no impact on `bootstrap_form` code itself, but may affect your application if it depended on a form having this attribute set. (Issue #569)
14+
15+
## Different behavior for `errors_on` helper
16+
17+
The `errors_on` helper now wraps the error message in a CSS class `invalid-feedback`, instead of `alert` and `alert-danger`, as before.
18+
19+
This will display the error as any other [Bootstrap inline form error](https://getbootstrap.com/docs/5.0/forms/validation/#server-side), instead of displaying it as an [Bootstrap alert](https://getbootstrap.com/docs/5.0/components/alerts/).
20+
21+
You can use the `custom_class` options for this helper with `alert alert-danger` to restore the old behaviour:
22+
23+
```erb
24+
<%= f.errors_on :tasks, custom_class: 'alert alert-danger' %>
25+
```

bootstrap_form.gemspec

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@ Gem::Specification.new do |s|
1212
1313
s.homepage = "https://github.com/bootstrap-ruby/bootstrap_form"
1414
s.summary = "Rails form builder that makes it easy to style forms using "\
15-
"Bootstrap 4"
15+
"Bootstrap 5"
1616
s.description = "bootstrap_form is a rails form builder that makes it super "\
17-
"easy to create beautiful-looking forms using Bootstrap 4"
17+
"easy to create beautiful-looking forms using Bootstrap 5"
1818
s.license = "MIT"
1919

20-
s.post_install_message = "Default form attribute role=\"form\" will be dropped in 5.0.0"
21-
2220
s.files = `git ls-files -z`.split("\x0").reject do |f|
2321
f.match(%r{^(test)/})
2422
end

demo/app/assets/stylesheets/actiontext.scss

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,3 @@
3636
}
3737
}
3838
}
39-
label.required {
40-
&:after {
41-
color: red;
42-
content: '*';
43-
}
44-
}
45-
input[required="required"]{
46-
border: 1px solid red;
47-
}

demo/app/views/bootstrap/form.html.erb

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,3 @@
1-
<h3>Required fields test</h3>
2-
3-
<%= form_with_source do %>
4-
<%= bootstrap_form_with model: @user, layout: :horizontal, local: true do |form| %>
5-
<%= form.text_field :email, placeholder: "Enter Email", label: "Email address", help: "Email pressence true" %>
6-
<%= form.text_field :email, placeholder: "Enter Email", label: "Email address", help: "Email pressence true with required false", required: false %>
7-
<%= form.text_field :email, placeholder: "Enter Email", label: "Email address", help: "Email pressence true with skip required false", skip_required: false %>
8-
<%= form.text_field :email, placeholder: "Enter Email", label: "Email address", help: "Email pressence true with skip required true", skip_required: true %>
9-
<%= form.text_field :misc, placeholder: "Enter Misc", label: "Misc", help: "Misc not required by model" %>
10-
<%= form.text_field :misc, placeholder: "Enter Misc", label: "Misc", help: "Misc not required by model with required true", required: true %>
11-
<%= form.text_field :misc, placeholder: "Enter Misc", label: "Misc", help: "Misc not required by model with required false", required: false %>
12-
<%= form.submit %>
13-
<% end %>
14-
<% end %>
15-
161
<h3>Horizontal Form</h3>
172

183
<%= form_with_source do %>
@@ -67,3 +52,16 @@
6752
<%= form.submit %>
6853
<% end %>
6954
<% end %>
55+
56+
<h3>Floating Labels</h3>
57+
58+
<%= form_with_source do %>
59+
<%= bootstrap_form_for @user do |form| %>
60+
<%= form.email_field :email, placeholder: "Enter Email", label: "Email address", help: "We'll never share your email with anyone else", floating: true %>
61+
<%= form.password_field :password, placeholder: "Password", floating: true %>
62+
<%= form.text_field :misc, floating: true %>
63+
<%= form.text_area :comments, floating: true %>
64+
<%= form.select :status, [["Active", 1], ["Inactive", 2]], include_blank: "Select a value", floating: true %>
65+
<%= form.submit %>
66+
<% end %>
67+
<% end %>

demo/app/views/layouts/application.html.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
77

88
<!-- Bootstrap CSS -->
9-
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
9+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
1010

1111
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.33.0/codemirror.min.css">
1212

@@ -44,8 +44,8 @@
4444
<!-- Optional JavaScript -->
4545
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
4646
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
47-
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
48-
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
47+
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-SR1sx49pcuLnqZUnnPwx6FCym0wLsk5JZuNx2bPPENzswTNFaQU1RDvt3wT4gWFG" crossorigin="anonymous"></script>
48+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/js/bootstrap.min.js" integrity="sha384-j0CNLUeiqtyaRmlzUHCPZ+Gy5fQu0dQ6eZ/xAww941Ai1SxSY+0EQqNXNE6DZiVc" crossorigin="anonymous"></script>
4949

5050
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.33.0/codemirror.min.js"></script>
5151
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.33.0/mode/htmlmixed/htmlmixed.min.js"></script>

0 commit comments

Comments
 (0)