bootstrap_form_legacy 4.0.1.dev
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.travis.yml +29 -0
- data/CHANGELOG.md +207 -0
- data/CONTRIBUTING.md +57 -0
- data/Dangerfile +54 -0
- data/Gemfile +21 -0
- data/LICENSE.txt +20 -0
- data/README.md +647 -0
- data/Rakefile +27 -0
- data/app/assets/stylesheets/rails_bootstrap_forms.css +10 -0
- data/bootstrap_form.gemspec +26 -0
- data/demo/README.md +17 -0
- data/demo/Rakefile +6 -0
- data/demo/app/controllers/application_controller.rb +2 -0
- data/demo/app/controllers/bootstrap_controller.rb +16 -0
- data/demo/app/helpers/bootstrap_helper.rb +23 -0
- data/demo/app/models/address.rb +3 -0
- data/demo/app/models/application_record.rb +3 -0
- data/demo/app/models/faux_user.rb +9 -0
- data/demo/app/models/super_user.rb +2 -0
- data/demo/app/models/user.rb +9 -0
- data/demo/app/views/bootstrap/form.html.erb +53 -0
- data/demo/app/views/layouts/application.html.erb +65 -0
- data/demo/bin/bundle +3 -0
- data/demo/bin/rails +4 -0
- data/demo/bin/rake +4 -0
- data/demo/bin/setup +36 -0
- data/demo/bin/update +31 -0
- data/demo/bin/yarn +11 -0
- data/demo/config.ru +5 -0
- data/demo/config/application.rb +24 -0
- data/demo/config/boot.rb +5 -0
- data/demo/config/database.yml +21 -0
- data/demo/config/environment.rb +5 -0
- data/demo/config/environments/development.rb +60 -0
- data/demo/config/environments/test.rb +48 -0
- data/demo/config/initializers/application_controller_renderer.rb +8 -0
- data/demo/config/initializers/assets.rb +14 -0
- data/demo/config/initializers/backtrace_silencers.rb +7 -0
- data/demo/config/initializers/cookies_serializer.rb +5 -0
- data/demo/config/initializers/filter_parameter_logging.rb +4 -0
- data/demo/config/initializers/inflections.rb +16 -0
- data/demo/config/initializers/mime_types.rb +4 -0
- data/demo/config/initializers/wrap_parameters.rb +14 -0
- data/demo/config/locales/en.yml +33 -0
- data/demo/config/puma.rb +56 -0
- data/demo/config/routes.rb +5 -0
- data/demo/config/spring.rb +6 -0
- data/demo/config/storage.yml +35 -0
- data/demo/db/schema.rb +24 -0
- data/demo/log/.keep +0 -0
- data/demo/package.json +5 -0
- data/demo/public/favicon.ico +0 -0
- data/lib/bootstrap_form.rb +13 -0
- data/lib/bootstrap_form/aliasing.rb +35 -0
- data/lib/bootstrap_form/form_builder.rb +564 -0
- data/lib/bootstrap_form/helper.rb +59 -0
- data/lib/bootstrap_form/helpers/bootstrap.rb +99 -0
- data/lib/bootstrap_form/version.rb +3 -0
- metadata +120 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 17d418df87737df9566ebde69bc92c34066c8e46
|
4
|
+
data.tar.gz: e46f31797c39ab157fee4aca2a67b012da4548c9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '0786ef134cb6f9a67e565498ecefe42f56fc7b0b83659ace6daa2006e745ec140ee83de1713b87d1b806174130d7be1e3f85044e9b5d679ccaa0bdb88afdcf1e'
|
7
|
+
data.tar.gz: 770da09a7d3ebf397dcd85021fe20c8c04fa32ab4ffeefe70fead630aba093dcf70f1b30f0389f7f078b9945a0036092a48f8c7bfa43fec570893b66c66f30c7
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.2.9
|
4
|
+
- 2.3.6
|
5
|
+
- 2.4.3
|
6
|
+
- 2.5.0
|
7
|
+
gemfile:
|
8
|
+
- test/gemfiles/5.0.gemfile
|
9
|
+
- test/gemfiles/5.1.gemfile
|
10
|
+
- test/gemfiles/5.2.gemfile
|
11
|
+
before_install:
|
12
|
+
- gem update --system
|
13
|
+
- gem install bundler --no-document
|
14
|
+
|
15
|
+
matrix:
|
16
|
+
include:
|
17
|
+
# Bleeding edge
|
18
|
+
- rvm: ruby-head
|
19
|
+
gemfile: test/gemfiles/5.2.gemfile
|
20
|
+
|
21
|
+
# Running one job to execute DANGER bot
|
22
|
+
- rvm: 2.5.0
|
23
|
+
gemfile: test/gemfiles/5.2.gemfile
|
24
|
+
script:
|
25
|
+
- gem install danger
|
26
|
+
- danger
|
27
|
+
|
28
|
+
allow_failures:
|
29
|
+
- rvm: ruby-head
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,207 @@
|
|
1
|
+
## [Pending Release][]
|
2
|
+
|
3
|
+
🚨 **This release adds support for Bootstrap v4 and drops support for Bootstrap v3.** 🚨
|
4
|
+
|
5
|
+
If your app uses Bootstrap v3, you should continue using bootstrap_form 2.7.x instead.
|
6
|
+
|
7
|
+
Bootstrap v3 and v4 are very different, and thus bootstrap_form now produces different markup in order to target v4. The changes are too many to list here; you can refer to Bootstrap's [Migrating to v4](https://getbootstrap.com/docs/4.0/migration/) page for a detailed explanation.
|
8
|
+
|
9
|
+
In addition to these necessary markup changes, the bootstrap_form API itself has the following important changes in this release.
|
10
|
+
|
11
|
+
### Breaking changes
|
12
|
+
|
13
|
+
* Rails 4.x is no longer supported
|
14
|
+
* Ruby 2.2 or newer is required
|
15
|
+
* Built-in support for the `nested_form` gem has been completely removed
|
16
|
+
* The `icon` option is no longer supported (Bootstrap v4 does not include icons)
|
17
|
+
* The deprecated Rails methods `check_boxes_collection` and `radio_buttons_collection` have been removed
|
18
|
+
* `hide_label: true` and `skip_label: true` on individual check boxes and radio buttons apply Bootstrap 4 markup. This means the appearance of a page may change if you're upgrading from the Bootstrap 3 version of `bootstrap_form`, and you used `check_box` or `radio_button` with either of those options
|
19
|
+
* `static_control` will no longer properly show error messages. This is the result of bootstrap changes.
|
20
|
+
* `static_control` will also no longer accept a block, use the `value` option instead.
|
21
|
+
* Your contribution here!
|
22
|
+
* [#456](https://github.com/bootstrap-ruby/bootstrap_form/pull/456): Fix label `for` attribute when passing non-english characters using `collection_check_boxes` - [@ug0](https://github.com/ug0).
|
23
|
+
|
24
|
+
### New features
|
25
|
+
|
26
|
+
* Support for Rails 5.1 `form_with` - [@lcreid](https://github.com/lcreid).
|
27
|
+
* Support Bootstrap v4's [Custom Checkboxes and Radios](https://getbootstrap.com/docs/4.0/components/forms/#checkboxes-and-radios-1) with a new `custom: true` option
|
28
|
+
* Allow HTML in help translations by using the `_html` suffix on the key - [@unikitty37](https://github.com/unikitty37)
|
29
|
+
* [#408](https://github.com/bootstrap-ruby/bootstrap_form/pull/408): Add option[:id] on static control #245 - [@duleorlovic](https://github.com/duleorlovic).
|
30
|
+
* [#455](https://github.com/bootstrap-ruby/bootstrap_form/pull/455): Support for i18n `:html` subkeys in help text - [@jsaraiva](https://github.com/jsaraiva).
|
31
|
+
* Your contribution here!
|
32
|
+
|
33
|
+
### Bugfixes
|
34
|
+
|
35
|
+
* [#357](https://github.com/bootstrap-ruby/bootstrap_form/pull/357) if provided,
|
36
|
+
use html option `id` to specify `for` attribute on label
|
37
|
+
[@duleorlovic](https://github.com/duleorlovic)
|
38
|
+
* Your contribution here!
|
39
|
+
|
40
|
+
|
41
|
+
## [2.7.0][] (2017-04-21)
|
42
|
+
|
43
|
+
Features:
|
44
|
+
* [#325](https://github.com/bootstrap-ruby/bootstrap_form/pull/325): Support :prepend and :append for the `select` helper - [@donv](https://github.com/donv).
|
45
|
+
|
46
|
+
## [2.6.0][] (2017-02-03)
|
47
|
+
|
48
|
+
Bugfixes:
|
49
|
+
- Fix ambiguous first argument warning (#311, @mikenicklas)
|
50
|
+
|
51
|
+
Features:
|
52
|
+
- Add a FormBuilder#custom_control helper [#289](https://github.com/bootstrap-ruby/bootstrap_form/pull/289)
|
53
|
+
|
54
|
+
## [2.5.3][] (2016-12-23)
|
55
|
+
|
56
|
+
There are no user-facing changes with this release. Behind the scenes, the tests have been greatly improved. The project is now tested against and compatible with the following Rails versions 4.0, 4.1, 4.2 and 5.0 (#278).
|
57
|
+
|
58
|
+
## [2.5.2][] (2016-10-08)
|
59
|
+
|
60
|
+
Bugfixes:
|
61
|
+
- Allow objects without `model_name`s to act as form objects (#295, @laserlemon)
|
62
|
+
- Fix offset for submit for horizontal forms when using non-sm column breakers for label column (#293, @oteyatosys)
|
63
|
+
|
64
|
+
## [2.5.1][] (2016-09-23)
|
65
|
+
|
66
|
+
Bugfixes:
|
67
|
+
- Fix getting help text for elements when using anonymous models (see [issue 282](https://github.com/bootstrap-ruby/bootstrap_form/issues/282))
|
68
|
+
|
69
|
+
## [2.5.0][] (2016-08-12)
|
70
|
+
|
71
|
+
Bugfixes:
|
72
|
+
|
73
|
+
- Sanitize <label> name (IE `for` attribute) in same manner that Rails sanitizes
|
74
|
+
the <input> `id` attribute to fix a11y issue with `for` and `id` mismatch
|
75
|
+
- Fix loading of ActionView helpers in combination with RSpec and `rails-controller-testing`. (see [rails-controller-testing/issues#24](https://github.com/rails/rails-controller-testing/issues/24))
|
76
|
+
|
77
|
+
Features:
|
78
|
+
|
79
|
+
- Add support for input-group-sm and input-group-lg in prepend/append (#226, @rusanu)
|
80
|
+
- Added option to prevent the 'required' CSS class on labels (#205, @LucasAU)
|
81
|
+
|
82
|
+
## [2.4.0][] (2016-07-04)
|
83
|
+
|
84
|
+
This version is ready to use with Rails 5.0.0!
|
85
|
+
|
86
|
+
Bugfixes:
|
87
|
+
|
88
|
+
- Minor README corrections (#184, @msmithstubbs)
|
89
|
+
- Fix `alias_method_chain` deprecation warnings when using Rails 5
|
90
|
+
- Allow `form_group` to work with frozen string options
|
91
|
+
|
92
|
+
Features:
|
93
|
+
|
94
|
+
- Allow primary button classes to be overridden (#183, @tanimichi)
|
95
|
+
- Allow to pass a block to select helper in Rails >= 4.1.0 (#229, @doits)
|
96
|
+
|
97
|
+
## 2.3.0 (2015-02-17)
|
98
|
+
|
99
|
+
Bugfixes:
|
100
|
+
|
101
|
+
- Use #underscore, not #downcase for help text scope (#140, @atipugin)
|
102
|
+
- Radio button and checkbox labels will now include the disabled class as needed. (#156, @ScottSwezey)
|
103
|
+
- Fixed issue with setting offset in form_group without label in horizontal layout
|
104
|
+
when form uses non-default label_col
|
105
|
+
- Fixed wrapper options (#153, @veilleperso)
|
106
|
+
- Fix errors on non-ActiveRecord setups (#200, @sgnn7)
|
107
|
+
|
108
|
+
Features:
|
109
|
+
|
110
|
+
- Allow users to display validation errors in labels (#144, @timcheadle)
|
111
|
+
- Use humanized attribute name in label errors (#146, @atipugin)
|
112
|
+
- Allow to skip label rendering (#145, @atipugin)
|
113
|
+
- Added a `required` CSS class for labels with required attributes (#150, @krsyoung)
|
114
|
+
- Added option to customize labels' class.
|
115
|
+
- Allow callable value_method and text_method for collection_check_boxes and collection_radio_buttons (#199, @shadwell)
|
116
|
+
|
117
|
+
## 2.2.0 (2014-09-16)
|
118
|
+
|
119
|
+
Bugfixes:
|
120
|
+
|
121
|
+
- Fixed an exception raised when form_group block returns nil (#111)
|
122
|
+
- Fixed an exception on human_attribute_name when using bootstrap_form_tag (#115)
|
123
|
+
- Set offset in form_group without label in horizontal layout (#94, @datWav)
|
124
|
+
- Fixes an offset bug in form_group without a given label in horizontal layout (#130, @datWav)
|
125
|
+
- Fixed bug where collection_check_boxes doesn't work if all are unchecked (#116, @burnt43)
|
126
|
+
|
127
|
+
Features:
|
128
|
+
|
129
|
+
- Added the ability to append/prepend buttons (@retoo)
|
130
|
+
- Added support for time_zone_select
|
131
|
+
- Accept multiple values, and objects as well, on `collection_check_boxes`
|
132
|
+
checked option (#114)
|
133
|
+
- Added support for hidding attribute name in errors_on helper (@datWav)
|
134
|
+
- Added support for additional class to the wrapper form_group by a field (@datWav)
|
135
|
+
- Support showing error summaries when inline_errors is enabled (@rosswilson)
|
136
|
+
- Name is now optional when creating static controls
|
137
|
+
- Keep original form helper methods with _without_bootstrap suffix (#123, @a2ikm)
|
138
|
+
- Added glyphicon support
|
139
|
+
- Added i18n support for help messages (#122, @huynhquancam)
|
140
|
+
- Added the ability to pass any attributes to wrapper (#136, @atipugin)
|
141
|
+
- Split monolithic test file into several smaller files (#141, @spacewander)
|
142
|
+
- Added role="form" attribute to forms (#142, @spacewander)
|
143
|
+
|
144
|
+
## 2.1.1 (2014-04-20)
|
145
|
+
|
146
|
+
Bugfixes:
|
147
|
+
|
148
|
+
- Do not reset additional classes on the form-group (@rzane)
|
149
|
+
- Fixed an exception when specifying a label while using bootstrap_form_tag
|
150
|
+
|
151
|
+
Features:
|
152
|
+
|
153
|
+
- [nested_form](https://github.com/ryanb/nested_form) integration via
|
154
|
+
`bootstrap_nested_form_for` (#44 and #66)
|
155
|
+
- `form_group` no longer requires a name (#83)
|
156
|
+
|
157
|
+
## 2.1.0 (2014-04-01)
|
158
|
+
|
159
|
+
Moved GitHub repository from https://github.com/potenza/bootstrap_form
|
160
|
+
to https://github.com/bootstrap-ruby/bootstrap_form
|
161
|
+
|
162
|
+
Bugfixes:
|
163
|
+
|
164
|
+
- i18n fix for checkbox labels (@i10a)
|
165
|
+
- Wrapped date & time helpers inside control-specific css classes to prevent stacking
|
166
|
+
- control-label class was not being added unless the form was horizontal (@slave2zeros)
|
167
|
+
- selects & collection selects were dropping label options
|
168
|
+
- allow html content in check_box tag label (@desheikh)
|
169
|
+
- allow check_box label to be defined with a block
|
170
|
+
- omit form-control class from file_field (@mbrictson)
|
171
|
+
- Collection inputs honour `checked` attribute (@desheikh)
|
172
|
+
- Fixing label/input pairing for checkbox collections (@byped)
|
173
|
+
- Removing for attribute on radio button labels (@sigmike)
|
174
|
+
|
175
|
+
Features:
|
176
|
+
|
177
|
+
- The control_class can be overridden per field by passing in the
|
178
|
+
:control_class option. Default value is "form-control".
|
179
|
+
- Make name optional in FormBuilder#submit (@adrpac)
|
180
|
+
- Added the FormBuilder#primary helper back in
|
181
|
+
- Added a FormBuilder#static_control helper
|
182
|
+
- Added support for radio_buttons_collection and check_boxes_collection
|
183
|
+
- Added a FormBuilder#error_summary helper method
|
184
|
+
- inline_errors can be turned off: bootstrap_form_for(obj, inline_errors: false)
|
185
|
+
When inline errors are off, FormBuilder#alert_message contains the error summary.
|
186
|
+
This can also be turned off with the option 'error_summary: false'
|
187
|
+
- Added support for: color_field, date_field, datetime_field, datetime_local_field,
|
188
|
+
month_field, range_field, search_field (#42), time_field, week_field
|
189
|
+
- Added ability to override the left/right classes for a particular control
|
190
|
+
when using horizontal forms. (@baldwindavid)
|
191
|
+
- Added support for grouped_collection_select (@rzane)
|
192
|
+
- Added support of Rails 4 syntax for collection inputs (@desheikh)
|
193
|
+
- Renamed options :left to :label_col and :right to :control_col
|
194
|
+
- Renamed option :style to :layout (@baldwindavid)
|
195
|
+
- Added errors_on helper (@baldwindavid)
|
196
|
+
- Added per field layout option (@baldwindavid)
|
197
|
+
- Added support for bootstrap_form_tag (@baldwindavid)
|
198
|
+
|
199
|
+
|
200
|
+
[Pending Release]: https://github.com/bootstrap-ruby/bootstrap_form/compare/v2.7.0...HEAD
|
201
|
+
[2.7.0]: https://github.com/bootstrap-ruby/bootstrap_form/compare/v2.6.0...v2.7.0
|
202
|
+
[2.6.0]: https://github.com/bootstrap-ruby/bootstrap_form/compare/v2.5.3...v2.6.0
|
203
|
+
[2.5.3]: https://github.com/bootstrap-ruby/bootstrap_form/compare/v2.5.2...v2.5.3
|
204
|
+
[2.5.2]: https://github.com/bootstrap-ruby/bootstrap_form/compare/v2.5.1...v2.5.2
|
205
|
+
[2.5.1]: https://github.com/bootstrap-ruby/bootstrap_form/compare/v2.5.0...v2.5.1
|
206
|
+
[2.5.0]: https://github.com/bootstrap-ruby/bootstrap_form/compare/v2.4.0...v2.5.0
|
207
|
+
[2.4.0]: https://github.com/bootstrap-ruby/bootstrap_form/compare/v2.3.0...v2.4.0
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# Contributing
|
2
|
+
|
3
|
+
The release of Bootstrap 4 and Rails 5.1 have implications for the future
|
4
|
+
direction of `bootstrap_form`. Don't worry. We plan to move this gem forward to
|
5
|
+
Bootstrap 4 and to support Rails 5.1 and beyond. If you're thinking of
|
6
|
+
contributing to `bootstrap_form`, please read
|
7
|
+
[issue #361](https://github.com/bootstrap-ruby/bootstrap_form/issues/361).
|
8
|
+
|
9
|
+
Your comments are welcome.
|
10
|
+
|
11
|
+
Thanks so much for considering a contribution to bootstrap_form. We love pull requests!
|
12
|
+
|
13
|
+
Here's a quick guide for contributing:
|
14
|
+
|
15
|
+
### 1. Check if issue or feature is available to work on
|
16
|
+
|
17
|
+
Make sure no one else is working on the same issue or feature. Search the issues
|
18
|
+
and pull requests for anything that looks like the issue or feature you want to
|
19
|
+
address. If no one else is working on your issue or feature, carry on with the
|
20
|
+
following steps.
|
21
|
+
|
22
|
+
### 2. Fork the repo
|
23
|
+
|
24
|
+
For the project. Optionally, create a branch you want to work on
|
25
|
+
|
26
|
+
### 3. Get it running locally
|
27
|
+
|
28
|
+
- Install the required dependencies with `bundle install`
|
29
|
+
- Run tests via: `bundle exec rake`
|
30
|
+
|
31
|
+
### 4. Hack away
|
32
|
+
|
33
|
+
- Try to keep your changes small. Consider making several smaller pull requests.
|
34
|
+
- Don't forget to add necessary tests.
|
35
|
+
- Update the README if necessary.
|
36
|
+
- Add a line to the CHANGELOG for your bug fix or feature.
|
37
|
+
|
38
|
+
You may find using demo application useful for development and debugging.
|
39
|
+
|
40
|
+
- `cd demo`
|
41
|
+
- `rake db:schema:load`
|
42
|
+
- `rails s`
|
43
|
+
- Navigate to http://localhost:3000
|
44
|
+
|
45
|
+
### 5. Make a Pull Request
|
46
|
+
|
47
|
+
- If you never done it before read this: https://help.github.com/articles/about-pull-requests/
|
48
|
+
- When PR is submitted check if TravisCI ran all tests successfully didn't raise any issues
|
49
|
+
|
50
|
+
### 6. Done!
|
51
|
+
|
52
|
+
Somebody will shortly review your pull request and if everything is good will be
|
53
|
+
merged into master brach. Eventually gem will be published with your changes.
|
54
|
+
|
55
|
+
---
|
56
|
+
|
57
|
+
Thanks to all the great contributors over the years: https://github.com/bootstrap-ruby/bootstrap_form/graphs/contributors
|
data/Dangerfile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# Adapted from https://github.com/ruby-grape/danger/blob/master/Dangerfile
|
2
|
+
# Q: What is a Dangerfile, anyway? A: See http://danger.systems/
|
3
|
+
|
4
|
+
# ------------------------------------------------------------------------------
|
5
|
+
# Additional pull request data
|
6
|
+
# ------------------------------------------------------------------------------
|
7
|
+
project_name = github.pr_json["base"]["repo"]["name"]
|
8
|
+
pr_number = github.pr_json["number"]
|
9
|
+
pr_url = github.pr_json["_links"]["html"]["href"]
|
10
|
+
|
11
|
+
# ------------------------------------------------------------------------------
|
12
|
+
# What changed?
|
13
|
+
# ------------------------------------------------------------------------------
|
14
|
+
has_lib_changes = !git.modified_files.grep(/^lib/).empty?
|
15
|
+
has_test_changes = !git.modified_files.grep(/^test/).empty?
|
16
|
+
has_changelog_changes = git.modified_files.include?("CHANGELOG.md")
|
17
|
+
|
18
|
+
# ------------------------------------------------------------------------------
|
19
|
+
# You've made changes to lib, but didn't write any tests?
|
20
|
+
# ------------------------------------------------------------------------------
|
21
|
+
if has_lib_changes && !has_test_changes
|
22
|
+
warn("There are code changes, but no corresponding tests. "\
|
23
|
+
"Please include tests if this PR introduces any modifications in "\
|
24
|
+
"#{project_name}'s behavior.",
|
25
|
+
:sticky => false)
|
26
|
+
end
|
27
|
+
|
28
|
+
# ------------------------------------------------------------------------------
|
29
|
+
# Have you updated CHANGELOG.md?
|
30
|
+
# ------------------------------------------------------------------------------
|
31
|
+
if !has_changelog_changes && has_lib_changes
|
32
|
+
markdown <<-MARKDOWN
|
33
|
+
Here's an example of a CHANGELOG.md entry (place it immediately under the `* Your contribution here!` line):
|
34
|
+
|
35
|
+
```markdown
|
36
|
+
* [##{pr_number}](#{pr_url}): #{github.pr_title} - [@#{github.pr_author}](https://github.com/#{github.pr_author}).
|
37
|
+
```
|
38
|
+
MARKDOWN
|
39
|
+
warn("Please update CHANGELOG.md with a description of your changes. "\
|
40
|
+
"If this PR is not a user-facing change (e.g. just refactoring), "\
|
41
|
+
"you can disregard this.", :sticky => false)
|
42
|
+
end
|
43
|
+
|
44
|
+
# ------------------------------------------------------------------------------
|
45
|
+
# Did you remove the CHANGELOG's "Your contribution here!" line?
|
46
|
+
# ------------------------------------------------------------------------------
|
47
|
+
if has_changelog_changes
|
48
|
+
if IO.read("CHANGELOG.md").scan(/^\s*[-\*] Your contribution here/i).count < 3
|
49
|
+
fail(
|
50
|
+
"Please put the `- Your contribution here!` line back into CHANGELOG.md.",
|
51
|
+
:sticky => false
|
52
|
+
)
|
53
|
+
end
|
54
|
+
end
|
data/Gemfile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
# Uncomment and change rails version for testing purposes
|
6
|
+
# gem "rails", "~> 5.2.0.beta2"
|
7
|
+
|
8
|
+
group :development do
|
9
|
+
gem "htmlbeautifier"
|
10
|
+
end
|
11
|
+
|
12
|
+
group :test do
|
13
|
+
# can relax version requirement for Rails 5.2.beta3+
|
14
|
+
gem "minitest"
|
15
|
+
|
16
|
+
gem "diffy"
|
17
|
+
gem "equivalent-xml"
|
18
|
+
gem "mocha"
|
19
|
+
gem "sqlite3"
|
20
|
+
gem "timecop"
|
21
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2012-2018 Stephen Potenza <potenza@gmail.com>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,647 @@
|
|
1
|
+
⚠️ **This documentation is for the master branch, which is not yet stable and targets Bootstrap v4.** If you are using Bootstrap v3, refer to the stable [legacy-2.7](https://github.com/bootstrap-ruby/bootstrap_form/tree/legacy-2.7) branch.
|
2
|
+
|
3
|
+
---
|
4
|
+
|
5
|
+
# bootstrap_form
|
6
|
+
|
7
|
+
[![Build Status](https://travis-ci.org/bootstrap-ruby/bootstrap_form.svg?branch=master)](https://travis-ci.org/bootstrap-ruby/bootstrap_form)
|
8
|
+
[![Gem Version](https://badge.fury.io/rb/bootstrap_form.svg)](https://rubygems.org/gems/bootstrap_form)
|
9
|
+
|
10
|
+
**bootstrap_form** is a Rails form builder that makes it super easy to integrate
|
11
|
+
Bootstrap v4-style forms into your Rails application.
|
12
|
+
|
13
|
+
## Requirements
|
14
|
+
|
15
|
+
* Ruby 2.0+
|
16
|
+
* Rails 4.0+ (Rails 5.1+ for `bootstrap_form_with`)
|
17
|
+
* Bootstrap 4.0.0+
|
18
|
+
|
19
|
+
## Installation
|
20
|
+
|
21
|
+
Add it to your Gemfile:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
gem "bootstrap_form",
|
25
|
+
git: "https://github.com/xire28/bootstrap_form.git",
|
26
|
+
branch: "master"
|
27
|
+
```
|
28
|
+
|
29
|
+
Then:
|
30
|
+
|
31
|
+
`bundle`
|
32
|
+
|
33
|
+
Then require the CSS in your `application.css` file:
|
34
|
+
|
35
|
+
```css
|
36
|
+
/*
|
37
|
+
*= require rails_bootstrap_forms
|
38
|
+
*/
|
39
|
+
```
|
40
|
+
|
41
|
+
## Usage
|
42
|
+
|
43
|
+
To get started, just use the `bootstrap_form_for` helper. Here's an example:
|
44
|
+
|
45
|
+
```erb
|
46
|
+
<%= bootstrap_form_for(@user) do |f| %>
|
47
|
+
<%= f.email_field :email %>
|
48
|
+
<%= f.password_field :password %>
|
49
|
+
<%= f.check_box :remember_me %>
|
50
|
+
<%= f.submit "Log In" %>
|
51
|
+
<% end %>
|
52
|
+
```
|
53
|
+
|
54
|
+
This generates the following HTML:
|
55
|
+
|
56
|
+
```html
|
57
|
+
<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post">
|
58
|
+
<div class="form-group">
|
59
|
+
<label for="user_email">Email</label>
|
60
|
+
<input class="form-control" id="user_email" name="user[email]" type="email">
|
61
|
+
</div>
|
62
|
+
<div class="form-group">
|
63
|
+
<label for="user_password">Password</label>
|
64
|
+
<input class="form-control" id="user_password" name="user[password]" type="password">
|
65
|
+
</div>
|
66
|
+
<div class="form-check">
|
67
|
+
<input name="user[remember_me]" type="hidden" value="0">
|
68
|
+
<input class="form-check-input" id="user_remember_me" name="user[remember_me]" type="checkbox" value="1">
|
69
|
+
<label class="form-check-label" for="user_remember_me">Remember me</label>
|
70
|
+
</div>
|
71
|
+
<input class="btn btn-secondary" name="commit" type="submit" value="Log In">
|
72
|
+
</form>
|
73
|
+
```
|
74
|
+
|
75
|
+
### bootstrap_form_tag
|
76
|
+
|
77
|
+
If your form is not backed by a model, use the `bootstrap_form_tag`. Usage of this helper is the same as `bootstrap_form_for`, except no model object is passed in as the first argument. Here's an example:
|
78
|
+
|
79
|
+
```erb
|
80
|
+
<%= bootstrap_form_tag url: '/subscribe' do |f| %>
|
81
|
+
<%= f.email_field :email, value: 'name@example.com' %>
|
82
|
+
<%= f.submit %>
|
83
|
+
<% end %>
|
84
|
+
```
|
85
|
+
|
86
|
+
### `bootstrap_form_with` (Rails 5.1+)
|
87
|
+
|
88
|
+
Note that `form_with` in Rails 5.1 does not add IDs to form elements and labels by default, which are both important to Bootstrap markup. This behavior is corrected in Rails 5.2.
|
89
|
+
|
90
|
+
To get started, just use the `bootstrap_form_with` helper in place of `form_with`. Here's an example:
|
91
|
+
|
92
|
+
```erb
|
93
|
+
<%= bootstrap_form_with(model: @user, local: true) do |f| %>
|
94
|
+
<%= f.email_field :email %>
|
95
|
+
<%= f.password_field :password %>
|
96
|
+
<%= f.check_box :remember_me %>
|
97
|
+
<%= f.submit "Log In" %>
|
98
|
+
<% end %>
|
99
|
+
```
|
100
|
+
|
101
|
+
This generates:
|
102
|
+
|
103
|
+
```html
|
104
|
+
<form role="form" action="/users" accept-charset="UTF-8" method="post">
|
105
|
+
<input name="utf8" type="hidden" value="✓" />
|
106
|
+
<div class="form-group">
|
107
|
+
<label class="required" for="user_email">Email</label>
|
108
|
+
<input class="form-control" type="email" value="steve@example.com" name="user[email]" />
|
109
|
+
</div>
|
110
|
+
<div class="form-group">
|
111
|
+
<label for="user_password">Password</label>
|
112
|
+
<input class="form-control" type="password" name="user[password]" />
|
113
|
+
<small class="form-text text-muted">A good password should be at least six characters long</small>
|
114
|
+
</div>
|
115
|
+
<div class="form-check">
|
116
|
+
<input name="user[remember_me]" type="hidden" value="0">
|
117
|
+
<input class="form-check-input" id="user_remember_me" name="user[remember_me]" type="checkbox" value="1">
|
118
|
+
<label class="form-check-label" for="user_remember_me">Remember me</label>
|
119
|
+
</div>
|
120
|
+
<input type="submit" name="commit" value="Log In" class="btn btn-secondary" data-disable-with="Log In" />
|
121
|
+
</form>
|
122
|
+
```
|
123
|
+
|
124
|
+
`bootstrap_form_with` supports both the `model:` and `url:` use cases
|
125
|
+
in `form_with`.
|
126
|
+
|
127
|
+
`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).
|
128
|
+
|
129
|
+
### Future Compatibility
|
130
|
+
|
131
|
+
The Rails team has [suggested](https://github.com/rails/rails/issues/25197) that `form_for` and `form_tag` may be deprecated and then removed in future versions of Rails. `bootstrap_form` will continue to support `bootstrap_form_for` and `bootstrap_form_tag` as long as Rails supports `form_for` and `form_tag`.
|
132
|
+
|
133
|
+
## Form Helpers
|
134
|
+
|
135
|
+
This gem wraps the following Rails form helpers:
|
136
|
+
|
137
|
+
* check_box
|
138
|
+
* collection_check_boxes
|
139
|
+
* collection_select
|
140
|
+
* color_field
|
141
|
+
* date_field
|
142
|
+
* date_select
|
143
|
+
* datetime_field
|
144
|
+
* datetime_local_field
|
145
|
+
* datetime_select
|
146
|
+
* email_field
|
147
|
+
* file_field
|
148
|
+
* grouped_collection_select
|
149
|
+
* hidden_field (not wrapped, but supported)
|
150
|
+
* month_field
|
151
|
+
* number_field
|
152
|
+
* password_field
|
153
|
+
* phone_field
|
154
|
+
* radio_button
|
155
|
+
* collection_radio_buttons
|
156
|
+
* range_field
|
157
|
+
* search_field
|
158
|
+
* select
|
159
|
+
* telephone_field
|
160
|
+
* text_area
|
161
|
+
* text_field
|
162
|
+
* time_field
|
163
|
+
* time_select
|
164
|
+
* time_zone_select
|
165
|
+
* url_field
|
166
|
+
* week_field
|
167
|
+
|
168
|
+
These helpers accept the same options as the standard Rails form helpers, with
|
169
|
+
a few extra options:
|
170
|
+
|
171
|
+
### Labels
|
172
|
+
|
173
|
+
Use the `label` option if you want to specify the field's label text:
|
174
|
+
|
175
|
+
```erb
|
176
|
+
<%= f.password_field :password_confirmation, label: "Confirm Password" %>
|
177
|
+
```
|
178
|
+
|
179
|
+
To hide a label, use the `hide_label: true` option. This adds the `sr-only`
|
180
|
+
class, which keeps your labels accessible to those using screen readers.
|
181
|
+
|
182
|
+
```erb
|
183
|
+
<%= f.text_area :comment, hide_label: true, placeholder: "Leave a comment..." %>
|
184
|
+
```
|
185
|
+
|
186
|
+
To add custom classes to the field's label:
|
187
|
+
|
188
|
+
```erb
|
189
|
+
<%= f.text_field :email, label_class: "custom-class" %>
|
190
|
+
```
|
191
|
+
|
192
|
+
#### Required Fields
|
193
|
+
|
194
|
+
A label that is associated with a required field is automatically annotated with
|
195
|
+
a `required` CSS class. You are free to add any appropriate CSS to style
|
196
|
+
required fields as desired. One example would be to automatically add an
|
197
|
+
asterisk to the end of the label:
|
198
|
+
|
199
|
+
```css
|
200
|
+
label.required:after {
|
201
|
+
content:" *";
|
202
|
+
}
|
203
|
+
```
|
204
|
+
|
205
|
+
The label `required` class is determined based on the definition of a presence
|
206
|
+
validator with the associated model attribute. Presently this is one of:
|
207
|
+
ActiveRecord::Validations::PresenceValidator or
|
208
|
+
ActiveModel::Validations::PresenceValidator.
|
209
|
+
|
210
|
+
In cases where this behavior is undesirable, use the `skip_required` option:
|
211
|
+
|
212
|
+
```erb
|
213
|
+
<%= f.password_field :password, label: "New Password", skip_required: true %>
|
214
|
+
```
|
215
|
+
|
216
|
+
### Input Elements / Controls
|
217
|
+
|
218
|
+
To specify the class of the generated input tag, use the `control_class` option:
|
219
|
+
|
220
|
+
```erb
|
221
|
+
<%= f.text_field :email, control_class: "custom-class" %>
|
222
|
+
```
|
223
|
+
|
224
|
+
### Help Text
|
225
|
+
|
226
|
+
To add help text, use the `help` option:
|
227
|
+
|
228
|
+
```erb
|
229
|
+
<%= f.password_field :password, help: "Must be at least 6 characters long" %>
|
230
|
+
```
|
231
|
+
|
232
|
+
This gem is also aware of help messages in locale translation files (i18n):
|
233
|
+
|
234
|
+
```yml
|
235
|
+
en:
|
236
|
+
activerecord:
|
237
|
+
help:
|
238
|
+
user:
|
239
|
+
password: "A good password should be at least six characters long"
|
240
|
+
```
|
241
|
+
|
242
|
+
Help translations containing HTML should follow the convention of appending `_html` to the name:
|
243
|
+
|
244
|
+
```yml
|
245
|
+
en:
|
246
|
+
activerecord:
|
247
|
+
help:
|
248
|
+
user:
|
249
|
+
password_html: "A <strong>good</strong> password should be at least six characters long"
|
250
|
+
```
|
251
|
+
|
252
|
+
If your model name has multiple words (like `SuperUser`), the key on the
|
253
|
+
translation file should be underscored (`super_user`).
|
254
|
+
|
255
|
+
You can override help translations for a particular field by passing the `help`
|
256
|
+
option or turn them off completely by passing `help: false`.
|
257
|
+
|
258
|
+
### Prepending and Appending Inputs
|
259
|
+
|
260
|
+
You can pass `prepend` and/or `append` options to input fields:
|
261
|
+
|
262
|
+
```erb
|
263
|
+
<%= f.text_field :price, prepend: "$", append: ".00" %>
|
264
|
+
```
|
265
|
+
|
266
|
+
You can also prepend and append buttons. Note: The buttons must contain the
|
267
|
+
`btn` class to generate the correct markup.
|
268
|
+
|
269
|
+
```erb
|
270
|
+
<%= f.text_field :search, append: link_to("Go", "#", class: "btn btn-secondary") %>
|
271
|
+
```
|
272
|
+
|
273
|
+
To add a class to the input group wrapper, use the `:input_group_class` option.
|
274
|
+
|
275
|
+
```erb
|
276
|
+
<%= f.email_field :email, append: f.primary('Subscribe'), input_group_class: 'input-group-lg' %>
|
277
|
+
```
|
278
|
+
|
279
|
+
### Additional Form Group Attributes
|
280
|
+
|
281
|
+
If you want to add an additional css class or any other attribute to the form group div, you can use
|
282
|
+
the `wrapper: { class: 'additional-class', data: { foo: 'bar' } }` option.
|
283
|
+
|
284
|
+
```erb
|
285
|
+
<%= f.text_field :name, wrapper: { class: 'has-warning', data: { foo: 'bar' } } %>
|
286
|
+
```
|
287
|
+
|
288
|
+
Which produces the following output:
|
289
|
+
|
290
|
+
```erb
|
291
|
+
<div class="form-group has-warning" data-foo="bar">
|
292
|
+
<label class="form-control-label" for="user_name">Id</label>
|
293
|
+
<input class="form-control" id="user_name" name="user[name]" type="text">
|
294
|
+
</div>
|
295
|
+
```
|
296
|
+
|
297
|
+
You still can use `wrapper_class` option to set only a css class. This is just a short form of `wrapper: { class: 'additional-class' }`.
|
298
|
+
|
299
|
+
### Selects
|
300
|
+
|
301
|
+
Our select helper accepts the same arguments as the [default Rails helper](http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-select). Here's an example of how you pass both options and html_options hashes:
|
302
|
+
|
303
|
+
```erb
|
304
|
+
<%= f.select :product, [["Apple", 1], ["Grape", 2]], { label: "Choose your favorite fruit:" }, { class: "selectpicker", wrapper: { class: 'has-warning', data: { foo: 'bar' } } } %>
|
305
|
+
```
|
306
|
+
|
307
|
+
### Checkboxes and Radios
|
308
|
+
|
309
|
+
Checkboxes and radios should be placed inside of a `form_group` to render
|
310
|
+
properly. The following example ensures that the entire form group will display
|
311
|
+
an error if an associated validations fails:
|
312
|
+
|
313
|
+
```erb
|
314
|
+
<%= f.form_group :skill_level, label: { text: "Skill" }, help: "Optional Help Text" do %>
|
315
|
+
<%= f.radio_button :skill_level, 0, label: "Novice", checked: true %>
|
316
|
+
<%= f.radio_button :skill_level, 1, label: "Intermediate" %>
|
317
|
+
<%= f.radio_button :skill_level, 2, label: "Advanced" %>
|
318
|
+
<% end %>
|
319
|
+
|
320
|
+
<%= f.form_group :terms do %>
|
321
|
+
<%= f.check_box :terms, label: "I agree to the Terms of Service" %>
|
322
|
+
<% end %>
|
323
|
+
```
|
324
|
+
|
325
|
+
You can also create a checkbox using a block:
|
326
|
+
|
327
|
+
```erb
|
328
|
+
<%= f.form_group :terms, label: { text: "Optional Label" } do %>
|
329
|
+
<%= f.check_box :terms do %>
|
330
|
+
You need to check this box to accept our terms of service and privacy policy
|
331
|
+
<% end %>
|
332
|
+
<% end %>
|
333
|
+
```
|
334
|
+
|
335
|
+
To display checkboxes and radios inline, pass the `inline: true` option:
|
336
|
+
|
337
|
+
```erb
|
338
|
+
<%= f.form_group :skill_level, label: { text: "Skill" } do %>
|
339
|
+
<%= f.radio_button :skill_level, 0, label: "Novice", inline: true %>
|
340
|
+
<%= f.radio_button :skill_level, 1, label: "Intermediate", inline: true %>
|
341
|
+
<%= f.radio_button :skill_level, 2, label: "Advanced", inline: true %>
|
342
|
+
<% end %>
|
343
|
+
```
|
344
|
+
|
345
|
+
#### Collections
|
346
|
+
|
347
|
+
`bootstrap_form` also provides helpers that automatically creates the
|
348
|
+
`form_group` and the `radio_button`s or `check_box`es for you:
|
349
|
+
|
350
|
+
```erb
|
351
|
+
<%= f.collection_radio_buttons :skill_level, Skill.all, :id, :name %>
|
352
|
+
<%= f.collection_check_boxes :skills, Skill.all, :id, :name %>
|
353
|
+
```
|
354
|
+
|
355
|
+
Collection methods accept these options:
|
356
|
+
* `:label`: Customize the `form_group`'s label
|
357
|
+
* `:hide_label`: Pass true to hide the `form_group`'s label
|
358
|
+
* `:help`: Add a help span to the `form_group`
|
359
|
+
* Other options will be forwarded to the `radio_button`/`check_box` method
|
360
|
+
|
361
|
+
### Static Controls
|
362
|
+
|
363
|
+
You can create a static control like this:
|
364
|
+
|
365
|
+
```erb
|
366
|
+
<%= f.static_control :email %>
|
367
|
+
```
|
368
|
+
|
369
|
+
Here's the output for a horizontal layout:
|
370
|
+
|
371
|
+
```html
|
372
|
+
<div class="form-group">
|
373
|
+
<label class="col-sm-2 form-control-label" for="user_email">Email</label>
|
374
|
+
<div class="col-sm-10">
|
375
|
+
<input class="form-control-plaintext" id="user_email" name="user[email]" readonly="readonly" type="text" value="test@email.com"/>
|
376
|
+
</div>
|
377
|
+
</div>
|
378
|
+
```
|
379
|
+
|
380
|
+
You can also create a static control that isn't based on a model attribute:
|
381
|
+
|
382
|
+
```erb
|
383
|
+
<%= f.static_control label: "Custom Static Control" do %>
|
384
|
+
Content Here
|
385
|
+
<% end %>
|
386
|
+
```
|
387
|
+
|
388
|
+
### Date Helpers
|
389
|
+
|
390
|
+
The multiple selects that the date and time helpers (`date_select`,
|
391
|
+
`time_select`, `datetime_select`) generate are wrapped inside a
|
392
|
+
`div.rails-bootstrap-forms-[date|time|datetime]-select` tag. This is because
|
393
|
+
Bootstrap automatically styles our controls as `block`s. This wrapper fixes
|
394
|
+
this defining these selects as `inline-block` and a width of `auto`.
|
395
|
+
|
396
|
+
### Submit Buttons
|
397
|
+
|
398
|
+
The `btn btn-secondary` css classes are automatically added to your submit
|
399
|
+
buttons.
|
400
|
+
|
401
|
+
```erb
|
402
|
+
<%= f.submit %>
|
403
|
+
```
|
404
|
+
|
405
|
+
You can also use the `primary` helper, which adds `btn btn-primary` to your
|
406
|
+
submit button:
|
407
|
+
|
408
|
+
```erb
|
409
|
+
<%= f.primary "Optional Label" %>
|
410
|
+
```
|
411
|
+
|
412
|
+
You can specify your own classes like this:
|
413
|
+
|
414
|
+
```erb
|
415
|
+
<%= f.submit "Log In", class: "btn btn-success" %>
|
416
|
+
```
|
417
|
+
|
418
|
+
### Accessing Rails Form Helpers
|
419
|
+
|
420
|
+
If you want to use the original Rails form helpers for a particular field,
|
421
|
+
append `_without_bootstrap` to the helper:
|
422
|
+
|
423
|
+
```erb
|
424
|
+
<%= f.text_field_without_bootstrap :email %>
|
425
|
+
```
|
426
|
+
|
427
|
+
## Form Styles
|
428
|
+
|
429
|
+
By default, your forms will stack labels on top of controls and your controls
|
430
|
+
will grow to 100% of the available width.
|
431
|
+
|
432
|
+
### Inline Forms
|
433
|
+
|
434
|
+
To use an inline-layout form, use the `layout: :inline` option. To hide labels,
|
435
|
+
use the `hide_label: true` option, which keeps your labels accessible to those
|
436
|
+
using screen readers.
|
437
|
+
|
438
|
+
```erb
|
439
|
+
<%= bootstrap_form_for(@user, layout: :inline) do |f| %>
|
440
|
+
<%= f.email_field :email, hide_label: true %>
|
441
|
+
<%= f.password_field :password, hide_label: true %>
|
442
|
+
<%= f.check_box :remember_me %>
|
443
|
+
<%= f.submit %>
|
444
|
+
<% end %>
|
445
|
+
```
|
446
|
+
|
447
|
+
To skip label rendering at all, use `skip_label: true` option.
|
448
|
+
|
449
|
+
```erb
|
450
|
+
<%= f.password_field :password, skip_label: true %>
|
451
|
+
```
|
452
|
+
|
453
|
+
### Horizontal Forms
|
454
|
+
|
455
|
+
To use a horizontal-layout form with labels to the left of the control, use the
|
456
|
+
`layout: :horizontal` option. You should specify both `label_col` and
|
457
|
+
`control_col` css classes as well (they default to `col-sm-2` and `col-sm-10`).
|
458
|
+
|
459
|
+
In the example below, the checkbox and submit button have been wrapped in a
|
460
|
+
`form_group` to keep them properly aligned.
|
461
|
+
|
462
|
+
```erb
|
463
|
+
<%= bootstrap_form_for(@user, layout: :horizontal, label_col: "col-sm-2", control_col: "col-sm-10") do |f| %>
|
464
|
+
<%= f.email_field :email %>
|
465
|
+
<%= f.password_field :password %>
|
466
|
+
<%= f.form_group do %>
|
467
|
+
<%= f.check_box :remember_me %>
|
468
|
+
<% end %>
|
469
|
+
<%= f.form_group do %>
|
470
|
+
<%= f.submit %>
|
471
|
+
<% end %>
|
472
|
+
<% end %>
|
473
|
+
```
|
474
|
+
|
475
|
+
The `label_col` and `control_col` css classes can also be changed per control:
|
476
|
+
|
477
|
+
```erb
|
478
|
+
<%= bootstrap_form_for(@user, layout: :horizontal) do |f| %>
|
479
|
+
<%= f.email_field :email %>
|
480
|
+
<%= f.text_field :age, control_col: "col-sm-3" %>
|
481
|
+
<%= f.form_group do %>
|
482
|
+
<%= f.submit %>
|
483
|
+
<% end %>
|
484
|
+
<% end %>
|
485
|
+
```
|
486
|
+
|
487
|
+
### Custom Field Layout
|
488
|
+
|
489
|
+
The form-level `layout` can be overridden per field, unless the form-level layout was `inline`:
|
490
|
+
|
491
|
+
```erb
|
492
|
+
<%= bootstrap_form_for(@user, layout: :horizontal) do |f| %>
|
493
|
+
<%= f.email_field :email %>
|
494
|
+
<%= f.text_field :feet, layout: :default %>
|
495
|
+
<%= f.text_field :inches, layout: :default %>
|
496
|
+
<%= f.form_group do %>
|
497
|
+
<%= f.submit %>
|
498
|
+
<% end %>
|
499
|
+
<% end %>
|
500
|
+
```
|
501
|
+
|
502
|
+
A form-level `layout: :inline` can't be overridden because of the way Bootstrap 4 implements in-line layouts. One possible work-around is to leave the form-level layout as default, and specify the individual fields as `layout: :inline`, except for the fields(s) that should be other than in-line.
|
503
|
+
|
504
|
+
### Custom Form Element Styles
|
505
|
+
|
506
|
+
The `custom` option can be used to replace the browser default styles for check boxes and radio buttons with dedicated Bootstrap styled form elements. Here's an example:
|
507
|
+
|
508
|
+
```erb
|
509
|
+
<%= bootstrap_form_for(@user) do |f| %>
|
510
|
+
<%= f.email_field :email %>
|
511
|
+
<%= f.password_field :password %>
|
512
|
+
<%= f.check_box :remember_me, custom: true %>
|
513
|
+
<%= f.submit "Log In" %>
|
514
|
+
<% end %>
|
515
|
+
```
|
516
|
+
|
517
|
+
## Validation and Errors
|
518
|
+
|
519
|
+
### Inline Errors
|
520
|
+
|
521
|
+
By default, fields that have validation errors will be outlined in red and the
|
522
|
+
error will be displayed below the field. Rails normally wraps the fields in a
|
523
|
+
div (field_with_errors), but this behavior is suppressed. Here's an example:
|
524
|
+
|
525
|
+
```html
|
526
|
+
<div class="form-group">
|
527
|
+
<label class="form-control-label" for="user_email">Email</label>
|
528
|
+
<input class="form-control is-invalid" id="user_email" name="user[email]" type="email" value="">
|
529
|
+
<small class="invalid-feedback">can't be blank</small>
|
530
|
+
</div>
|
531
|
+
```
|
532
|
+
|
533
|
+
You can turn off inline errors for the entire form like this:
|
534
|
+
|
535
|
+
```erb
|
536
|
+
<%= bootstrap_form_for(@user, inline_errors: false) do |f| %>
|
537
|
+
...
|
538
|
+
<% end %>
|
539
|
+
```
|
540
|
+
|
541
|
+
### Label Errors
|
542
|
+
|
543
|
+
You can also display validation errors in the field's label; just turn
|
544
|
+
on the `:label_errors` option. Here's an example:
|
545
|
+
|
546
|
+
```
|
547
|
+
<%= bootstrap_form_for(@user, label_errors: true) do |f| %>
|
548
|
+
...
|
549
|
+
<% end %>
|
550
|
+
```
|
551
|
+
|
552
|
+
By default, turning on `:label_errors` will also turn off
|
553
|
+
`:inline_errors`. If you want both turned on, you can do that too:
|
554
|
+
|
555
|
+
```
|
556
|
+
<%= bootstrap_form_for(@user, label_errors: true, inline_errors: true) do |f| %>
|
557
|
+
...
|
558
|
+
<% end %>
|
559
|
+
```
|
560
|
+
|
561
|
+
### Alert Messages
|
562
|
+
|
563
|
+
To display an error message with an error summary, you can use the
|
564
|
+
`alert_message` helper. This won't output anything unless a model validation
|
565
|
+
has failed.
|
566
|
+
|
567
|
+
```erb
|
568
|
+
<%= f.alert_message "Please fix the errors below." %>
|
569
|
+
```
|
570
|
+
|
571
|
+
Which outputs:
|
572
|
+
|
573
|
+
```html
|
574
|
+
<div class="alert alert-danger">
|
575
|
+
<p>Please fix the errors below.</p>
|
576
|
+
<ul class="rails-bootstrap-forms-error-summary">
|
577
|
+
<li>Email can't be blank</li>
|
578
|
+
</ul>
|
579
|
+
</div>
|
580
|
+
```
|
581
|
+
|
582
|
+
You can turn off the error summary like this:
|
583
|
+
|
584
|
+
```erb
|
585
|
+
<%= f.alert_message "Please fix the errors below.", error_summary: false %>
|
586
|
+
```
|
587
|
+
|
588
|
+
To output a simple unordered list of errors, use the `error_summary` helper.
|
589
|
+
|
590
|
+
```erb
|
591
|
+
<%= f.error_summary %>
|
592
|
+
```
|
593
|
+
|
594
|
+
Which outputs:
|
595
|
+
|
596
|
+
```html
|
597
|
+
<ul class="rails-bootstrap-forms-error-summary">
|
598
|
+
<li>Email can't be blank</li>
|
599
|
+
</ul>
|
600
|
+
```
|
601
|
+
|
602
|
+
### Errors On
|
603
|
+
|
604
|
+
If you want to display a custom inline error for a specific attribute not
|
605
|
+
represented by a form field, use the `errors_on` helper.
|
606
|
+
|
607
|
+
```erb
|
608
|
+
<%= f.errors_on :tasks %>
|
609
|
+
```
|
610
|
+
|
611
|
+
Which outputs:
|
612
|
+
|
613
|
+
```html
|
614
|
+
<div class="alert alert-danger">Tasks can't be blank.</div>
|
615
|
+
```
|
616
|
+
|
617
|
+
You can hide the attribute name like this:
|
618
|
+
|
619
|
+
```erb
|
620
|
+
<%= f.errors_on :tasks, hide_attribute_name: true %>
|
621
|
+
```
|
622
|
+
|
623
|
+
Which outputs:
|
624
|
+
|
625
|
+
```html
|
626
|
+
<div class="alert alert-danger">can't be blank.</div>
|
627
|
+
```
|
628
|
+
|
629
|
+
## Internationalization
|
630
|
+
|
631
|
+
bootstrap_form follows standard rails conventions so it's i18n-ready. See more
|
632
|
+
here: http://guides.rubyonrails.org/i18n.html#translations-for-active-record-models
|
633
|
+
|
634
|
+
## Code Triage page
|
635
|
+
|
636
|
+
http://www.codetriage.com/potenza/bootstrap_form
|
637
|
+
|
638
|
+
## Contributing
|
639
|
+
|
640
|
+
We welcome contributions.
|
641
|
+
If you're considering contributing to bootstrap_form,
|
642
|
+
please review the [Contributing](/CONTRIBUTING.md)
|
643
|
+
document first.
|
644
|
+
|
645
|
+
## License
|
646
|
+
|
647
|
+
MIT License. Copyright 2012-2018 Stephen Potenza (https://github.com/potenza)
|