bootstrap_form 4.5.0 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +46 -0
- data/.gitignore +16 -1
- data/.rubocop.yml +17 -14
- data/CHANGELOG.md +32 -1
- data/CONTRIBUTING.md +65 -5
- data/Dangerfile +5 -7
- data/Dockerfile +26 -0
- data/Gemfile +4 -3
- data/README.md +63 -40
- data/UPGRADE-4.0.md +1 -1
- data/UPGRADE-5.0.md +25 -0
- data/bootstrap_form.gemspec +8 -6
- data/demo/app/assets/config/manifest.js +1 -2
- data/demo/app/helpers/bootstrap_helper.rb +4 -4
- data/demo/app/views/bootstrap/form.html.erb +13 -0
- data/demo/app/views/layouts/application.html.erb +3 -3
- data/demo/config/environments/development.rb +1 -1
- data/demo/config/puma.rb +2 -2
- data/demo/db/schema.rb +2 -2
- data/docker-compose.yml +70 -0
- data/gemfiles/5.2.gemfile +2 -15
- data/gemfiles/6.0.gemfile +2 -17
- data/gemfiles/6.1.gemfile +4 -0
- data/gemfiles/edge.gemfile +2 -17
- data/lib/bootstrap_form/components/labels.rb +1 -1
- data/lib/bootstrap_form/components/validation.rb +1 -1
- data/lib/bootstrap_form/configuration.rb +1 -2
- data/lib/bootstrap_form/form_builder.rb +2 -4
- data/lib/bootstrap_form/form_group.rb +21 -10
- data/lib/bootstrap_form/form_group_builder.rb +6 -8
- data/lib/bootstrap_form/helpers/bootstrap.rb +11 -10
- data/lib/bootstrap_form/inputs/base.rb +5 -5
- data/lib/bootstrap_form/inputs/check_box.rb +8 -22
- data/lib/bootstrap_form/inputs/collection_select.rb +1 -0
- data/lib/bootstrap_form/inputs/file_field.rb +3 -15
- data/lib/bootstrap_form/inputs/grouped_collection_select.rb +1 -0
- data/lib/bootstrap_form/inputs/radio_button.rb +7 -25
- data/lib/bootstrap_form/inputs/select.rb +1 -0
- data/lib/bootstrap_form/inputs/time_zone_select.rb +1 -0
- data/lib/bootstrap_form/version.rb +1 -1
- data/lib/bootstrap_form.rb +1 -2
- metadata +24 -6
- data/.travis.yml +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a510f995829dd7bbdfa67fa4eeaa73b8cb8a10a73a2d46c89aad425709caf7c2
|
4
|
+
data.tar.gz: 33543b5b3a9dd167ef7896e0ad55c7d86d31a54e4c19072d13e09b332bb5a872
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a703b03f34bb7208380b3370aab0b6444526fb4a33303f473c5b1a78c4c55639701d499c4013d437f79a240554c9da703a1698fc32fe5d91f73f69b919d080c
|
7
|
+
data.tar.gz: 77362e8c4c482ad19a81d63b8c4b55fe213b42e28e44dc66cd716da7106afc2e7509e43428ec135a00f652ed6112cd6fcee4af8bb2e271bb77d3cc187e441045
|
@@ -0,0 +1,46 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ main ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ main ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
Lint:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
steps:
|
13
|
+
- uses: actions/checkout@v2
|
14
|
+
- uses: ruby/setup-ruby@v1
|
15
|
+
with:
|
16
|
+
ruby-version: 2.7.2
|
17
|
+
bundler-cache: true
|
18
|
+
- name: Danger
|
19
|
+
if: ${{ github.event_name == 'pull_request' }}
|
20
|
+
run: |
|
21
|
+
gem install danger
|
22
|
+
export DANGER_GITHUB_API_TOKEN=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
|
23
|
+
danger
|
24
|
+
- name: Rubocop
|
25
|
+
run: bundle exec rubocop --auto-correct
|
26
|
+
Test:
|
27
|
+
runs-on: ubuntu-latest
|
28
|
+
strategy:
|
29
|
+
fail-fast: false
|
30
|
+
matrix:
|
31
|
+
ruby-version: [ '3.0', '2.7', '2.6' ]
|
32
|
+
gemfile: [ '6.1', '6.0', '5.2', 'edge' ]
|
33
|
+
exclude:
|
34
|
+
- { ruby-version: '3.0', gemfile: "5.2" }
|
35
|
+
- { ruby-version: '2.6', gemfile: "edge" }
|
36
|
+
env:
|
37
|
+
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
|
38
|
+
steps:
|
39
|
+
- uses: actions/checkout@v2
|
40
|
+
- name: Set up Ruby
|
41
|
+
uses: ruby/setup-ruby@v1
|
42
|
+
with:
|
43
|
+
ruby-version: ${{ matrix.ruby-version }}
|
44
|
+
bundler-cache: true
|
45
|
+
- name: Run tests
|
46
|
+
run: bundle exec rake test
|
data/.gitignore
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
.bundle/
|
2
|
+
.idea
|
2
3
|
log/*.log
|
3
4
|
pkg/
|
4
5
|
demo/db/*.sqlite3
|
@@ -13,7 +14,7 @@ test/gemfiles/*.lock
|
|
13
14
|
Vagrantfile
|
14
15
|
.vagrant
|
15
16
|
|
16
|
-
|
17
|
+
# For the demo app.
|
17
18
|
|
18
19
|
# Ignore uploaded files in development.
|
19
20
|
demo/storage/*
|
@@ -30,3 +31,17 @@ demo/node_modules
|
|
30
31
|
demo/yarn-error.log
|
31
32
|
demo/yarn-debug.log*
|
32
33
|
demo/.yarn-integrity
|
34
|
+
|
35
|
+
# For stuff that gets created if using the Dockerfile image
|
36
|
+
.bundle/
|
37
|
+
.cache/
|
38
|
+
vendor/bundle
|
39
|
+
|
40
|
+
# or .local/share/pry/pry_history if you need to be more exact
|
41
|
+
.local/
|
42
|
+
.irb_history
|
43
|
+
.byebug_history
|
44
|
+
# For Debian images with Bash
|
45
|
+
.bash_history
|
46
|
+
# For Alpine images
|
47
|
+
.ash_history
|
data/.rubocop.yml
CHANGED
@@ -1,28 +1,37 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require:
|
2
|
+
- rubocop-performance
|
3
|
+
- rubocop-rails
|
4
4
|
|
5
5
|
AllCops:
|
6
6
|
DisplayCopNames: true
|
7
7
|
DisplayStyleGuide: true
|
8
8
|
TargetRubyVersion: 2.5
|
9
|
+
NewCops: enable
|
9
10
|
Exclude:
|
10
|
-
-
|
11
|
+
- bin/*
|
11
12
|
- Capfile
|
12
13
|
- demo/bin/*
|
13
|
-
-
|
14
|
+
- demo/bower_components/**/*
|
14
15
|
- demo/config/boot.rb
|
15
16
|
- demo/config/environment.rb
|
16
17
|
- demo/config/initializers/version.rb
|
17
18
|
- demo/db/schema.rb
|
18
|
-
-
|
19
|
+
- demo/node_modules/**/*
|
19
20
|
- demo/Rakefile
|
20
|
-
-
|
21
|
-
-
|
21
|
+
- demo/tmp/**/*
|
22
|
+
- demo/vendor/**/*
|
22
23
|
- Gemfile
|
23
24
|
- gemfiles/vendor/bundle/**/*
|
25
|
+
- vendor/bundle/**/*
|
24
26
|
- Guardfile
|
25
27
|
- Rakefile
|
28
|
+
- vendor/**/*
|
29
|
+
|
30
|
+
Layout/LineLength:
|
31
|
+
Max: 132
|
32
|
+
Exclude:
|
33
|
+
- "demo/config/**/*"
|
34
|
+
- "demo/db/**/*"
|
26
35
|
|
27
36
|
Layout/SpaceAroundEqualsInParameterDefault:
|
28
37
|
EnforcedStyle: no_space
|
@@ -43,12 +52,6 @@ Metrics/ClassLength:
|
|
43
52
|
- "demo/test/**/*"
|
44
53
|
- "test/**/*"
|
45
54
|
|
46
|
-
Metrics/LineLength:
|
47
|
-
Max: 132
|
48
|
-
Exclude:
|
49
|
-
- "demo/config/**/*"
|
50
|
-
- "demo/db/**/*"
|
51
|
-
|
52
55
|
Metrics/MethodLength:
|
53
56
|
Max: 12
|
54
57
|
Exclude:
|
data/CHANGELOG.md
CHANGED
@@ -12,6 +12,36 @@
|
|
12
12
|
|
13
13
|
* Your contribution here!
|
14
14
|
|
15
|
+
## [5.0.0][] (2021-11-11)
|
16
|
+
|
17
|
+
### Breaking changes
|
18
|
+
|
19
|
+
* Generates markup for Bootstrap 5.
|
20
|
+
|
21
|
+
### New features
|
22
|
+
|
23
|
+
* [#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
|
24
|
+
* [#573](https://github.com/bootstrap-ruby/bootstrap_form/issues/573): Add support for Bootstrap 5's floating labels
|
25
|
+
|
26
|
+
### Bugfixes
|
27
|
+
|
28
|
+
* [#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.
|
29
|
+
|
30
|
+
## [5.0.0.alpha1][]
|
31
|
+
|
32
|
+
### Breaking changes
|
33
|
+
|
34
|
+
* [#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.)
|
35
|
+
|
36
|
+
### New features
|
37
|
+
|
38
|
+
* Your contribution here!
|
39
|
+
|
40
|
+
### Bugfixes
|
41
|
+
|
42
|
+
* [#586](https://github.com/bootstrap-ruby/bootstrap_form/pull/586): Fix Rails 6.1 tests on master - [@thimo](https://github.com/thimo).
|
43
|
+
* [#587](https://github.com/bootstrap-ruby/bootstrap_form/pull/587): Replace `strip_heredoc` with `<<~` - [@thimo](https://github.com/thimo).
|
44
|
+
|
15
45
|
## [4.5.0][] (2020-04-29)
|
16
46
|
|
17
47
|
### New features
|
@@ -292,7 +322,8 @@ Features:
|
|
292
322
|
- Added support for bootstrap_form_tag (@baldwindavid)
|
293
323
|
|
294
324
|
|
295
|
-
[Pending Release]: https://github.com/bootstrap-ruby/bootstrap_form/compare/
|
325
|
+
[Pending Release]: https://github.com/bootstrap-ruby/bootstrap_form/compare/v5.0.0...HEAD
|
326
|
+
[5.0.0]: https://github.com/bootstrap-ruby/bootstrap_form/compare/v4.5.0...v5.0.0
|
296
327
|
[4.5.0]: https://github.com/bootstrap-ruby/bootstrap_form/compare/v4.4.0...v4.5.0
|
297
328
|
[4.4.0]: https://github.com/bootstrap-ruby/bootstrap_form/compare/v4.3.0...v4.4.0
|
298
329
|
[4.3.0]: https://github.com/bootstrap-ruby/bootstrap_form/compare/v4.2.0...v4.3.0
|
data/CONTRIBUTING.md
CHANGED
@@ -10,6 +10,11 @@ There are a number of ways you can contribute to `bootstrap_form`:
|
|
10
10
|
- Add to the documentation
|
11
11
|
- Review pull requests
|
12
12
|
|
13
|
+
*Note:* If you want to work on preparing `bootstrap_form` for Bootstrap 5,
|
14
|
+
please start from the `bootstrap-5` branch.
|
15
|
+
If you're submitting a pull request with code or documentation,
|
16
|
+
target the pull request to the `bootstrap-5` branch.
|
17
|
+
|
13
18
|
## Code Contributions
|
14
19
|
|
15
20
|
Here's a quick guide for code contributions:
|
@@ -58,16 +63,16 @@ You may find the demo application useful for development and debugging.
|
|
58
63
|
### 7. Done!
|
59
64
|
|
60
65
|
Somebody will shortly review your pull request and if everything is good, it will be
|
61
|
-
merged into the
|
66
|
+
merged into the main branch. Eventually the gem will be published with your changes.
|
62
67
|
|
63
68
|
### Coding guidelines
|
64
69
|
|
65
70
|
This project uses [RuboCop](https://github.com/bbatsov/rubocop) to enforce standard Ruby coding
|
66
71
|
guidelines.
|
67
72
|
|
68
|
-
|
69
|
-
|
70
|
-
|
73
|
+
- Test that your contribution passes with `rake rubocop`.
|
74
|
+
- RuboCop is also run as part of the full test suite with `bundle exec rake`.
|
75
|
+
- Note the Travis build will fail and your PR cannot be merged if RuboCop finds offences.
|
71
76
|
|
72
77
|
Note that most editors have plugins to run RuboCop as you type, or when you save a file. You may find it well worth your time to install and configure the RuboCop plugin for your editor. Read the [RuboCop documentation](https://rubocop.readthedocs.io/en/latest/integration_with_other_tools/).
|
73
78
|
|
@@ -77,6 +82,58 @@ The goal of `bootstrap_form` is to support all versions of Rails currently suppo
|
|
77
82
|
|
78
83
|
The Ruby on Rails support policy is [here](https://guides.rubyonrails.org/maintenance_policy.html).
|
79
84
|
|
85
|
+
### Developing with Docker
|
86
|
+
|
87
|
+
This repository includes a `Dockerfile` to build an image with the minimum `bootstrap_form`-supported Ruby environment. To build the image:
|
88
|
+
|
89
|
+
```bash
|
90
|
+
docker build --tag bootstrap_form .
|
91
|
+
```
|
92
|
+
|
93
|
+
This builds an image called `bootstrap_form`. You can change that to any tag you wish. Just make sure you use the same tag name in the `docker run` command.
|
94
|
+
|
95
|
+
If you want to use a different Ruby version, or a smaller Linux distribution (although the distro may be missing tools you need):
|
96
|
+
|
97
|
+
```bash
|
98
|
+
docker build --build-arg "RUBY_VERSION=2.7" --build-arg "DISTRO=slim-buster" --tag bootstrap_form .
|
99
|
+
```
|
100
|
+
|
101
|
+
Then run the container you built with the shell, and create the bundle:
|
102
|
+
|
103
|
+
```bash
|
104
|
+
docker run --volume "$PWD:/app" --user $UID:`grep ^$USERNAME /etc/passwd | cut -d: -f4` -it bootstrap_form /bin/bash
|
105
|
+
bundle install
|
106
|
+
```
|
107
|
+
|
108
|
+
You can run tests in the container as normal, with `rake test`.
|
109
|
+
|
110
|
+
(Some of that command line is need for Linux hosts, to run the container as the current user.)
|
111
|
+
|
112
|
+
### The Demo App
|
113
|
+
|
114
|
+
There is a demo app in this repository. It shows some of the features of `bootstrap_form`, and provides a base on which to build ad-hoc testing, if you need it.
|
115
|
+
|
116
|
+
To run the demo app, set up the database and run the server:
|
117
|
+
|
118
|
+
```bash
|
119
|
+
cd demo
|
120
|
+
export BUNDLER_GEMFILE=../gemfiles/6.1.gemfile
|
121
|
+
rails db:setup
|
122
|
+
rails s -b 0.0.0.0
|
123
|
+
```
|
124
|
+
|
125
|
+
To run the demo app in the Docker container:
|
126
|
+
|
127
|
+
```bash
|
128
|
+
docker run --volume "$PWD:/app" --user $UID:`grep ^$USERNAME /etc/passwd | cut -d: -f4` -p 3000:3000 -it bootstrap_form /bin/bash
|
129
|
+
cd demo
|
130
|
+
export BUNDLER_GEMFILE=../gemfiles/6.1.gemfile
|
131
|
+
rails db:setup
|
132
|
+
rails s -b 0.0.0.0
|
133
|
+
```
|
134
|
+
|
135
|
+
To use other supported versions of Rails, change the `export BUNDLER_GEMFILE...` line to another gem file.
|
136
|
+
|
80
137
|
## Documentation Contributions
|
81
138
|
|
82
139
|
Contributions to documentation are always welcome. Even fixing one typo improves the quality of `bootstrap_form`. To make a documentation contribution, follow steps 1-3 of Code Contributions, then make the documentation changes, then make the pull request (step 6 of Code Contributions).
|
@@ -92,11 +149,14 @@ We are an entirely volunteer project. Sometimes it's hard for people to find the
|
|
92
149
|
Thanks to all the great contributors over the years: https://github.com/bootstrap-ruby/bootstrap_form/graphs/contributors
|
93
150
|
|
94
151
|
## Troubleshooting
|
152
|
+
|
95
153
|
### Models and Database Tables
|
154
|
+
|
96
155
|
`bootstrap_form` needs a few models and tables to support testing. It appears that the necessary tables were created via the `demo/db/schema.rb` file. To support `rich_text_area`, Rails 6 creates some migrations. These migrations had to be run in the existing database (not an empty one) to create a new `schema.rb` that creates the `bootstrap_form` test tables, and the tables needed by Rails 6. The `schema.rb` file was checked in to GitHub, but the migrations were not.
|
97
156
|
|
98
157
|
In the future, any new Rails functionality that creates tables would likely have to be prepared the same way:
|
99
|
-
|
158
|
+
|
159
|
+
```bash
|
100
160
|
cd demo
|
101
161
|
rails db:setup # create the databases from `schema.rb`
|
102
162
|
rails db:migrate # add the new tables and create a new `schema.rb`
|
data/Dangerfile
CHANGED
@@ -44,11 +44,9 @@ end
|
|
44
44
|
# ------------------------------------------------------------------------------
|
45
45
|
# Did you remove the CHANGELOG's "Your contribution here!" line?
|
46
46
|
# ------------------------------------------------------------------------------
|
47
|
-
if has_changelog_changes
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
)
|
53
|
-
end
|
47
|
+
if has_changelog_changes && IO.read("CHANGELOG.md").scan(/^\s*[-*] Your contribution here/i).count < 3
|
48
|
+
raise(
|
49
|
+
"Please put the `- Your contribution here!` line back into CHANGELOG.md.",
|
50
|
+
sticky: false
|
51
|
+
)
|
54
52
|
end
|
data/Dockerfile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
ARG DISTRO=buster
|
2
|
+
ARG RUBY_VERSION=2.6
|
3
|
+
|
4
|
+
FROM ruby:$RUBY_VERSION-$DISTRO
|
5
|
+
|
6
|
+
RUN mkdir -p /app
|
7
|
+
ENV HOME /app
|
8
|
+
WORKDIR /app
|
9
|
+
|
10
|
+
ENV GEM_HOME $HOME/vendor/bundle
|
11
|
+
ENV BUNDLE_APP_CONFIG="$GEM_HOME"
|
12
|
+
ENV PATH ./bin:$GEM_HOME/bin:$PATH
|
13
|
+
RUN (echo 'docker'; echo 'docker') | passwd root
|
14
|
+
|
15
|
+
# Yarn installs nodejs.
|
16
|
+
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
|
17
|
+
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
|
18
|
+
apt update -y -q && \
|
19
|
+
apt install -y -q yarn sqlite3
|
20
|
+
|
21
|
+
# Ruby now comes with bundler, but we're not using the default version yet, because we were using
|
22
|
+
# a newer version of bundler already. Ruby 3 comes with Bundler 2.2.3. Ruby 2.7 has Bundler 2.1.2,
|
23
|
+
# which is still behind what we were using.
|
24
|
+
RUN gem install bundler -v 2.1.4
|
25
|
+
|
26
|
+
EXPOSE 3000
|
data/Gemfile
CHANGED
@@ -1,22 +1,23 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
2
|
|
3
|
-
gemspec
|
3
|
+
gemspec path: __dir__
|
4
4
|
|
5
5
|
# Uncomment and change rails version for testing purposes
|
6
6
|
# gem "rails", "~> 5.2.0"
|
7
|
-
gem "rails", "~> 6.0.0"
|
7
|
+
# gem "rails", "~> 6.0.0"
|
8
|
+
# gem "rails", "~> 6.1.0"
|
8
9
|
# gem "rails", git: "https://github.com/rails/rails.git"
|
9
10
|
|
10
11
|
group :development do
|
11
12
|
gem "chandler", ">= 0.7.0"
|
12
13
|
gem "htmlbeautifier"
|
14
|
+
gem "rubocop-performance", require: false
|
13
15
|
gem "rubocop-rails", require: false
|
14
16
|
gem "sassc-rails"
|
15
17
|
gem "webpacker"
|
16
18
|
end
|
17
19
|
|
18
20
|
group :test do
|
19
|
-
# can relax version requirement for Rails 5.2.beta3+
|
20
21
|
gem "diffy"
|
21
22
|
gem "equivalent-xml"
|
22
23
|
gem "mocha"
|
data/README.md
CHANGED
@@ -1,17 +1,11 @@
|
|
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
|
-
|
7
1
|
# bootstrap_form
|
8
2
|
|
9
|
-
[![
|
3
|
+
[![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)
|
10
4
|
[![Gem Version](https://badge.fury.io/rb/bootstrap_form.svg)](https://rubygems.org/gems/bootstrap_form)
|
11
5
|
|
12
|
-
`bootstrap_form` is a Rails form builder that makes it super easy to integrate Bootstrap
|
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:
|
13
7
|
|
14
|
-
* [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.
|
8
|
+
* [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/)
|
15
9
|
* Automatic [mark-up for the `required` attribute](#required-fields) on required fields.
|
16
10
|
* An easy way to consistently show [help](#help-text) text on fields.
|
17
11
|
* Mark-up for [Bootstrap horizontal forms](#horizontal-forms) (labels to the left of their fields, like a traditional desktop application), if that's what you want.
|
@@ -33,14 +27,14 @@ Some other nice things that `bootstrap_form` does for you are:
|
|
33
27
|
|
34
28
|
* Ruby 2.5+
|
35
29
|
* Rails 5.2+
|
36
|
-
* Bootstrap
|
30
|
+
* Bootstrap 5.0+
|
37
31
|
|
38
32
|
## Installation
|
39
33
|
|
40
34
|
Add it to your Gemfile:
|
41
35
|
|
42
36
|
```ruby
|
43
|
-
gem "bootstrap_form", "~>
|
37
|
+
gem "bootstrap_form", "~> 5.0"
|
44
38
|
```
|
45
39
|
|
46
40
|
Then:
|
@@ -79,12 +73,12 @@ This generates the following HTML:
|
|
79
73
|
|
80
74
|
```html
|
81
75
|
<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post">
|
82
|
-
<div class="
|
83
|
-
<label for="user_email">Email</label>
|
76
|
+
<div class="mb-3">
|
77
|
+
<label class="form-label" for="user_email">Email</label>
|
84
78
|
<input class="form-control" id="user_email" name="user[email]" type="email">
|
85
79
|
</div>
|
86
|
-
<div class="
|
87
|
-
<label for="user_password">Password</label>
|
80
|
+
<div class="mb-3">
|
81
|
+
<label class="form-label" for="user_password">Password</label>
|
88
82
|
<input class="form-control" id="user_password" name="user[password]" type="password">
|
89
83
|
</div>
|
90
84
|
<div class="form-check">
|
@@ -125,14 +119,14 @@ To get started, just use the `bootstrap_form_with` helper in place of `form_with
|
|
125
119
|
This generates:
|
126
120
|
|
127
121
|
```html
|
128
|
-
<form
|
122
|
+
<form action="/users" accept-charset="UTF-8" method="post">
|
129
123
|
<input name="utf8" type="hidden" value="✓" />
|
130
|
-
<div class="
|
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>
|
132
126
|
<input class="form-control" type="email" value="steve@example.com" name="user[email]" />
|
133
127
|
</div>
|
134
|
-
<div class="
|
135
|
-
<label for="user_password">Password</label>
|
128
|
+
<div class="mb-3">
|
129
|
+
<label class="form-label" for="user_password">Password</label>
|
136
130
|
<input class="form-control" type="password" name="user[password]" />
|
137
131
|
<small class="form-text text-muted">A good password should be at least six characters long</small>
|
138
132
|
</div>
|
@@ -150,7 +144,6 @@ in `form_with`.
|
|
150
144
|
|
151
145
|
`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).
|
152
146
|
|
153
|
-
|
154
147
|
## Configuration
|
155
148
|
|
156
149
|
`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:
|
|
159
152
|
|
160
153
|
| Option | Default value | Description |
|
161
154
|
|---------------------------|------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
162
|
-
| `default_form_attributes` |
|
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. |
|
164
156
|
|
165
157
|
Example:
|
158
|
+
|
166
159
|
```ruby
|
167
160
|
# config/initializers/bootstrap_form.rb
|
168
161
|
BootstrapForm.configure do |c|
|
169
|
-
c.default_form_attributes = {} # to make forms W3C
|
162
|
+
c.default_form_attributes = { role: "form" } # to make forms non-compliant with W3C.
|
170
163
|
end
|
171
164
|
```
|
172
165
|
|
@@ -319,7 +312,7 @@ To add a class to the input group wrapper, use the `:input_group_class` option.
|
|
319
312
|
|
320
313
|
### Additional Form Group Attributes
|
321
314
|
|
322
|
-
Bootstrap mark-up dictates that most input field types have the label and input wrapped in a `div.
|
315
|
+
Bootstrap mark-up dictates that most input field types have the label and input wrapped in a `div.mb-3`.
|
323
316
|
|
324
317
|
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.
|
325
318
|
|
@@ -330,8 +323,8 @@ If you want to add an additional CSS class or any other attribute to the form gr
|
|
330
323
|
Which produces the following output:
|
331
324
|
|
332
325
|
```erb
|
333
|
-
<div class="
|
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>
|
335
328
|
<input class="form-control" id="user_name" name="user[name]" type="text">
|
336
329
|
</div>
|
337
330
|
```
|
@@ -404,10 +397,10 @@ Check boxes and radio buttons are wrapped in a `div.form-check`. You can add cla
|
|
404
397
|
|
405
398
|
### Switches
|
406
399
|
|
407
|
-
To render checkboxes as switches with Bootstrap 4.2+, use `
|
400
|
+
To render checkboxes as switches with Bootstrap 4.2+, use `switch: true`:
|
408
401
|
|
409
402
|
```erb
|
410
|
-
<%= f.check_box :remember_me,
|
403
|
+
<%= f.check_box :remember_me, switch: true %>
|
411
404
|
```
|
412
405
|
|
413
406
|
### Collections
|
@@ -440,8 +433,8 @@ You can create a static control like this:
|
|
440
433
|
Here's the output for a horizontal layout:
|
441
434
|
|
442
435
|
```html
|
443
|
-
<div class="
|
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>
|
445
438
|
<div class="col-sm-10">
|
446
439
|
<input class="form-control-plaintext" id="user_email" name="user[email]" readonly="readonly" type="text" value="test@email.com"/>
|
447
440
|
</div>
|
@@ -553,8 +546,8 @@ If you're using Rails 6, `bootstrap_form` supports the `rich_text_area` helper.
|
|
553
546
|
will be rendered as:
|
554
547
|
|
555
548
|
```html
|
556
|
-
<div class="
|
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>
|
558
551
|
<input type="hidden" name="user[life_story]" id="user_life_story_trix_input_user"/>
|
559
552
|
<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"/>
|
560
553
|
</trix-editor>
|
@@ -700,6 +693,21 @@ The `custom` option can be used to replace the browser default styles for check
|
|
700
693
|
<% end %>
|
701
694
|
```
|
702
695
|
|
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
|
+
|
703
711
|
## Validation and Errors
|
704
712
|
|
705
713
|
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
|
|
710
718
|
error will be displayed below the field. Here's an example:
|
711
719
|
|
712
720
|
```html
|
713
|
-
<div class="
|
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>
|
715
723
|
<input class="form-control is-invalid" id="user_email" name="user[email]" type="email" value="">
|
716
724
|
<small class="invalid-feedback">can't be blank</small>
|
717
725
|
</div>
|
@@ -788,8 +796,7 @@ Which outputs:
|
|
788
796
|
|
789
797
|
### Errors On
|
790
798
|
|
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.
|
793
800
|
|
794
801
|
```erb
|
795
802
|
<%= f.errors_on :tasks %>
|
@@ -798,7 +805,7 @@ represented by a form field, use the `errors_on` helper.
|
|
798
805
|
Which outputs:
|
799
806
|
|
800
807
|
```html
|
801
|
-
<div class="
|
808
|
+
<div class="invalid-feedback">Tasks can't be blank.</div>
|
802
809
|
```
|
803
810
|
|
804
811
|
You can hide the attribute name like this:
|
@@ -810,7 +817,19 @@ You can hide the attribute name like this:
|
|
810
817
|
Which outputs:
|
811
818
|
|
812
819
|
```html
|
813
|
-
<div class="
|
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>
|
814
833
|
```
|
815
834
|
|
816
835
|
## Required Fields
|
@@ -874,6 +893,10 @@ If you're considering contributing to bootstrap_form,
|
|
874
893
|
please review the [Contributing](/CONTRIBUTING.md)
|
875
894
|
document first.
|
876
895
|
|
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
|
+
|
877
900
|
## License
|
878
901
|
|
879
|
-
MIT License. Copyright 2012-
|
902
|
+
MIT License. Copyright 2012-2021 Stephen Potenza (https://github.com/potenza) and others
|
data/UPGRADE-4.0.md
CHANGED
@@ -33,7 +33,7 @@ One way to make the above behave the same in `bootstrap_form` v4.0 is to write i
|
|
33
33
|
<%= bootstrap_form_for(@user) do |f| %>
|
34
34
|
<%= f.form_group(:email) do %>
|
35
35
|
<p class="form-control-plaintext">Bar</p>
|
36
|
-
<%=
|
36
|
+
<%= tag.div(@user.errors[:email].join(", "), class: "invalid-feedback", style: "display: block;") unless @user.errors[:email].empty? %>
|
37
37
|
<%= end %>
|
38
38
|
<%= end %>
|
39
39
|
```
|
data/UPGRADE-5.0.md
ADDED
@@ -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
|
+
```
|