rails_bootstrap_form 0.9.1 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +25 -1
- data/CONTRIBUTING.md +146 -0
- data/Gemfile.lock +1 -1
- data/README.md +76 -44
- data/lib/rails_bootstrap_form/bootstrap_form_builder.rb +5 -2
- data/lib/rails_bootstrap_form/field_wrapper_builder.rb +50 -49
- data/lib/rails_bootstrap_form/helpers/buttons.rb +3 -3
- data/lib/rails_bootstrap_form/helpers/choice.rb +81 -0
- data/lib/rails_bootstrap_form/helpers/help_text.rb +3 -3
- data/lib/rails_bootstrap_form/helpers/labels.rb +16 -16
- data/lib/rails_bootstrap_form/helpers.rb +10 -11
- data/lib/rails_bootstrap_form/input_group_builder.rb +14 -14
- data/lib/rails_bootstrap_form/inputs/base.rb +21 -18
- data/lib/rails_bootstrap_form/inputs/check_box.rb +12 -20
- data/lib/rails_bootstrap_form/inputs/collection_check_boxes.rb +10 -5
- data/lib/rails_bootstrap_form/inputs/collection_radio_buttons.rb +10 -5
- data/lib/rails_bootstrap_form/inputs/collection_select.rb +3 -3
- data/lib/rails_bootstrap_form/inputs/color_field.rb +9 -4
- data/lib/rails_bootstrap_form/inputs/grouped_collection_select.rb +3 -3
- data/lib/rails_bootstrap_form/inputs/radio_button.rb +11 -19
- data/lib/rails_bootstrap_form/inputs/range_field.rb +4 -4
- data/lib/rails_bootstrap_form/inputs/rich_text_area.rb +3 -3
- data/lib/rails_bootstrap_form/inputs/select.rb +3 -3
- data/lib/rails_bootstrap_form/inputs/time_zone_select.rb +3 -3
- data/lib/rails_bootstrap_form/inputs/weekday_select.rb +3 -3
- data/lib/rails_bootstrap_form/version.rb +1 -1
- metadata +4 -4
- data/lib/rails_bootstrap_form/helpers/check_box.rb +0 -86
- data/lib/rails_bootstrap_form/helpers/radio_button.rb +0 -82
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8bb2a8a391176d2d0e578b3ce1591c6f1f996cc8f5ebbb1ad6fcaddf9087be7e
|
4
|
+
data.tar.gz: a995a9c68d6509edc9f3327674783fb85c831f0107e269fc1ffbd75b98438b04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62c3811ebcb7356b7e5333c48146f2f2958aa16ecefc71cd7c9a05dcb1bafac659d019484e26a1bb5b0e901d1cbc041b9d88509816cb270a6ceb11a870252a12
|
7
|
+
data.tar.gz: d395785a7267dd780584e0ca968faf265e9ca5d637e206d66fa46a7c77da69b71314ae397b02a5a8b6e4bb6cb1cbc79dfcecf62ddbc11b2951af733668ee2a8e
|
data/CHANGELOG.md
CHANGED
@@ -4,7 +4,31 @@ You can find recent releases with docs in GitHub:
|
|
4
4
|
|
5
5
|
https://github.com/shivam091/rails_bootstrap_form/releases
|
6
6
|
|
7
|
-
## [0.9.
|
7
|
+
## [0.9.3](https://github.com/shivam091/rails_bootstrap_form/compare/v0.9.2...v0.9.3) - 2023-06-04
|
8
|
+
|
9
|
+
### What's changed
|
10
|
+
|
11
|
+
- Disabled floating labels for unsupported helpers
|
12
|
+
|
13
|
+
### What's fixed
|
14
|
+
|
15
|
+
- `id` of check box field when used in collection and don't has multiple select. (`collection_check_boxes` with `multiple: false`)
|
16
|
+
|
17
|
+
## [0.9.2](https://github.com/shivam091/rails_bootstrap_form/compare/v0.9.1...v0.9.2) - 2023-06-03
|
18
|
+
|
19
|
+
### What's new
|
20
|
+
|
21
|
+
- Added support to disable wrapper by passing option `wrapper: false`.
|
22
|
+
|
23
|
+
### What's fixed
|
24
|
+
|
25
|
+
- Changes to not showing required `asterisk` in `collection_check_boxes` and `collection_radio_buttons` helper ([#34](https://github.com/shivam091/rails_bootstrap_form/issues/34)).
|
26
|
+
|
27
|
+
### What's changed
|
28
|
+
|
29
|
+
- Wrappers of `check_box`, `collection_check_boxes`, `radio_button`, and `collection_radio_buttons` helpers.
|
30
|
+
|
31
|
+
## [0.9.1](https://github.com/shivam091/rails_bootstrap_form/compare/v0.9.0...v0.9.1) - 2023-06-02
|
8
32
|
|
9
33
|
### What's new
|
10
34
|
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
# Contributing
|
2
|
+
|
3
|
+
Thank you so much for considering a contribution to `rails_bootstrap_form`. We love pull requests!
|
4
|
+
|
5
|
+
We want everyone to feel welcome to contribute. We encourage respectful exchanges of ideas. We govern ourselves with the Contributor Covenant [Code of Conduct](/CODE_OF_CONDUCT.md).
|
6
|
+
|
7
|
+
There are a number of ways you can contribute to `rails_bootstrap_form`:
|
8
|
+
|
9
|
+
- Fix a bug or add a new feature
|
10
|
+
- Add to the documentation
|
11
|
+
- Review pull requests
|
12
|
+
|
13
|
+
## Code Contributions
|
14
|
+
|
15
|
+
Here's a quick guide for code contributions:
|
16
|
+
|
17
|
+
### 1. Check if issue or feature is available to work on
|
18
|
+
|
19
|
+
Make sure no one else is working on the same issue or feature. Search the issues
|
20
|
+
and pull requests for anything that looks like the issue or feature you want to
|
21
|
+
address. If no one else is working on your issue or feature, carry on with the
|
22
|
+
following steps.
|
23
|
+
|
24
|
+
### 2. Create an issue, and wait a few days for someone to respond (Optional)
|
25
|
+
|
26
|
+
If you create an issue for your feature request or bug, it gives the maintainers a chance to comment on your ideas before you invest a lot of work on a contribution. It may save you some re-work compared to simply submitting a pull request. It's up to you whether you submit an issue.
|
27
|
+
|
28
|
+
### 3. Fork the repo
|
29
|
+
|
30
|
+
Fork the project. Optionally, create a branch you want to work on.
|
31
|
+
|
32
|
+
### 4. Get it running locally
|
33
|
+
|
34
|
+
- Install the required dependencies with `bundle install`
|
35
|
+
- Run tests via: `bundle exec rake`
|
36
|
+
|
37
|
+
### 5. Hack away
|
38
|
+
|
39
|
+
- Try to keep your changes small. Consider making several smaller pull requests if your changes are extensive.
|
40
|
+
- Don't forget to add necessary tests and make sure that all tests run successfully.
|
41
|
+
- Update the README if necessary.
|
42
|
+
- Add a line to the CHANGELOG for your bug fix or feature.
|
43
|
+
- Read the [Coding Guidelines](#coding-guidelines) section and make sure that `bundle exec rubocop --autocorrect` doesn't find any offences.
|
44
|
+
|
45
|
+
You may find the [demo application](#the-demo-application) useful for development and debugging.
|
46
|
+
|
47
|
+
### 6. Make a pull request
|
48
|
+
|
49
|
+
- If you've never made a pull request (PR) before, read [this](https://help.github.com/articles/about-pull-requests/).
|
50
|
+
- If your PR fixes an issues, be sure to put "Fixes #nnn" in the description of the PR (where `nnn` is the issue number). Github will automatically close the issue when the PR is merged.
|
51
|
+
- When the PR is submitted, check if Travis CI ran all the tests successfully, and didn't raise any issues.
|
52
|
+
|
53
|
+
### 7. Done
|
54
|
+
|
55
|
+
Somebody will shortly review your pull request and if everything is good, it will be
|
56
|
+
merged into the main branch. Eventually the gem will be published with your changes.
|
57
|
+
|
58
|
+
### Coding guidelines
|
59
|
+
|
60
|
+
This project uses [RuboCop](https://github.com/bbatsov/rubocop) to enforce standard Ruby coding guidelines.
|
61
|
+
|
62
|
+
- Test that your contribution passes with `bundle exec rubocop`.
|
63
|
+
- RuboCop is also run as part of the full test suite with `bundle exec rake`.
|
64
|
+
- Note the Travis build will fail and your PR cannot be merged if RuboCop finds offences.
|
65
|
+
|
66
|
+
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/).
|
67
|
+
|
68
|
+
### Supported Versions of Ruby and Rails
|
69
|
+
|
70
|
+
The goal of `rails_bootstrap_form` is to support all versions of Rails (higher than 7.0) for bug fixes and security issues. We do not test against versions supported for severe security issues. We test against the minimum [version of Ruby required](https://guides.rubyonrails.org/upgrading_ruby_on_rails.html#ruby-versions) for those versions of Rails.
|
71
|
+
|
72
|
+
The Ruby on Rails support policy is [here](https://guides.rubyonrails.org/maintenance_policy.html).
|
73
|
+
|
74
|
+
### The Demo Application
|
75
|
+
|
76
|
+
There is a demo app in this repository. It shows some of the features of `rails_bootstrap_form`, and provides a base on which to build ad-hoc testing, if you need it.
|
77
|
+
|
78
|
+
Currently, the demo app is only set up to run for Rails 7, due to the variety of ways to include CSS and JavaScript in a modern Rails application.
|
79
|
+
To run the demo app, set up the database and run the server:
|
80
|
+
|
81
|
+
```bash
|
82
|
+
cd demo
|
83
|
+
bundle
|
84
|
+
rails db:create
|
85
|
+
rails db:migrate
|
86
|
+
```
|
87
|
+
|
88
|
+
You'll see errors in the browser console about duplicate ids. This is expected, since the demo app has many forms with the same fields in them. Something we can fix in the future, perhaps.
|
89
|
+
|
90
|
+
To use other supported versions of Rails, you will need to create a `Gemfile` for the Rails version. Then, change the `export BUNDLE_GEMFILE...` line to your gem file. Finally, figure out how to include the assets.
|
91
|
+
|
92
|
+
If you need to run the Rails server separately, for example, to debug the server, you _must_ run it like this:
|
93
|
+
|
94
|
+
```sh
|
95
|
+
bundle exec rails s -b 0.0.0.0
|
96
|
+
```
|
97
|
+
|
98
|
+
If you run just `rails` or even `bin/rails`, the `sprockets-rails` gem won't load and you'll either get error messages, or the assets won't be available to the demo app. At the moment it's a mystery why. PRs to fix this are welcome.
|
99
|
+
|
100
|
+
Please try to keep the checked-in `.ruby-version` set to the oldest supported version of Ruby. You're welcome and encouraged to try the demo app with other Ruby versions. Just don't check in the `.ruby-version` to GitHub.
|
101
|
+
|
102
|
+
## Documentation Contributions
|
103
|
+
|
104
|
+
Contributions to documentation are always welcome. Even fixing one typo improves the quality of `rails_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).
|
105
|
+
|
106
|
+
If you put `[ci skip]` in the commit message of the most recent commit of the PR, you'll be a good citizen by not causing our CI pipeline to run all the tests when it's not necessary.
|
107
|
+
|
108
|
+
## Reviewing Pull Requests
|
109
|
+
|
110
|
+
We are an entirely volunteer project. Sometimes it's hard for people to find the time to review pull requests. You can help! If you see a pull request that's waiting to be merged, it could be because no one has reviewed it yet. Your review could help move the pull request forward to be merged.
|
111
|
+
|
112
|
+
---
|
113
|
+
|
114
|
+
Thanks to all the [great contributors](https://github.com/shivam091/rails_bootstrap_form/graphs/contributors).
|
115
|
+
|
116
|
+
## Troubleshooting
|
117
|
+
|
118
|
+
### Models and Database Tables
|
119
|
+
|
120
|
+
`rails_bootstrap_form` needs 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 7 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 `rails_bootstrap_form` test tables, and the tables needed by Rails 7. The `schema.rb` file was checked in to GitHub.
|
121
|
+
|
122
|
+
In the future, any new Rails functionality that creates tables would likely have to be prepared the same way:
|
123
|
+
|
124
|
+
```bash
|
125
|
+
cd demo
|
126
|
+
rails db:create
|
127
|
+
rails db:migrate
|
128
|
+
```
|
129
|
+
|
130
|
+
### RuboCop
|
131
|
+
|
132
|
+
When you push a branch, RuboCop checks may fail, but locally you can't reproduce the failure. This may be because you're using a different version of RuboCop locally. When you push, the RuboCop tests use the currently available version of RuboCop. If you've been working on the branch for a while, it's likely you have a `Gemfile.lock` that specifies an older version of RuboCop.
|
133
|
+
|
134
|
+
The first thing to try is to update your `Gemfile.lock` locally:
|
135
|
+
|
136
|
+
```bash
|
137
|
+
bundle update
|
138
|
+
```
|
139
|
+
|
140
|
+
Or, if you really want to minimize your work:
|
141
|
+
|
142
|
+
```bash
|
143
|
+
bundle update --conservative rubocop
|
144
|
+
```
|
145
|
+
|
146
|
+
This should enable you to reproduce the RuboCop failures locally, and then you can fix them.
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -103,10 +103,12 @@ This generates the following HTML:
|
|
103
103
|
<label class="form-label required" for="user_password">Password</label>
|
104
104
|
<input class="form-control" aria-required="true" required="required" type="password" name="user[password]" id="user_password">
|
105
105
|
</div>
|
106
|
-
<div class="
|
107
|
-
<
|
108
|
-
|
109
|
-
|
106
|
+
<div class="mb-3">
|
107
|
+
<div class="form-check">
|
108
|
+
<input class="form-check-input" type="checkbox" value="1" name="user[terms]" id="user_terms">
|
109
|
+
<label class="form-check-label" for="user_terms">I accept terms and conditions</label>
|
110
|
+
<div class="form-text text-muted">You must first accept terms and conditions in order to continue</div>
|
111
|
+
</div>
|
110
112
|
</div>
|
111
113
|
<input type="submit" name="commit" value="Log In" class="btn btn-primary" data-disable-with="Log In">
|
112
114
|
</form>
|
@@ -139,10 +141,12 @@ This generates the following HTML:
|
|
139
141
|
<label class="form-label required" for="user_password">Password</label>
|
140
142
|
<input class="form-control" aria-required="true" required="required" type="password" name="user[password]" id="user_password">
|
141
143
|
</div>
|
142
|
-
<div class="
|
143
|
-
<
|
144
|
-
|
145
|
-
|
144
|
+
<div class="mb-3">
|
145
|
+
<div class="form-check">
|
146
|
+
<input class="form-check-input" type="checkbox" value="1" name="user[terms]" id="user_terms">
|
147
|
+
<label class="form-check-label" for="user_terms">I accept terms and conditions</label>
|
148
|
+
<div class="form-text text-muted">You must first accept terms and conditions in order to continue</div>
|
149
|
+
</div>
|
146
150
|
</div>
|
147
151
|
<input type="submit" name="commit" value="Log In" class="btn btn-primary" data-disable-with="Log In">
|
148
152
|
</form>
|
@@ -171,7 +175,7 @@ Here's a list of all possible options you can pass via `bootstrap` option that c
|
|
171
175
|
| `floating` | An option to control whether the field should have a floating label. | `false` |
|
172
176
|
| `static_field_class` | A CSS class that will be applied to all static fields. | `form-control-plaintext` |
|
173
177
|
| `switch` | An option to control whether the check box should look like Bootstrap switches. | `false` |
|
174
|
-
| `wrapper` | An option to control the HTML attributes and options that will be added to a field wrapper. | `{}` |
|
178
|
+
| `wrapper` | An option to control the HTML attributes and options that will be added to a field wrapper. You can set it false if you don't the field to be rendered in a wrapper. | `{}` |
|
175
179
|
| `size` | An option to control the size of input groups, buttons, labels, and fields. It can be `sm` or `lg`. | `nil` |
|
176
180
|
| `inline` | An option to group checkboxes and radio buttons on the same horizontal row. | `false` |
|
177
181
|
| `label_col_class` | A CSS class that will be applied to all labels when layout is `horizontal`. | `col-form-label` |
|
@@ -189,7 +193,7 @@ Here's an example of a form where one field uses different layout:
|
|
189
193
|
<%= form.text_field :name %>
|
190
194
|
<%= form.email_field :email %>
|
191
195
|
<%= form.password_field :password, bootstrap: {layout: :horizontal} %>
|
192
|
-
<%= form.check_box :terms
|
196
|
+
<%= form.check_box :terms %>
|
193
197
|
<%= form.primary "Register" %>
|
194
198
|
<% end %>
|
195
199
|
```
|
@@ -212,11 +216,12 @@ This generates the following HTML:
|
|
212
216
|
<input class="form-control" aria-required="true" required="required" type="password" name="user[password]" id="user_password">
|
213
217
|
</div>
|
214
218
|
</div>
|
215
|
-
<div class="
|
216
|
-
<
|
217
|
-
|
218
|
-
|
219
|
-
|
219
|
+
<div class="mb-3">
|
220
|
+
<div class="form-check">
|
221
|
+
<input class="form-check-input" type="checkbox" value="1" name="user[terms]" id="user_terms">
|
222
|
+
<label class="form-check-label" for="user_terms">I accept terms and conditions</label>
|
223
|
+
<div class="form-text text-muted">You must first accept terms and conditions in order to continue</div>
|
224
|
+
</div>
|
220
225
|
</div>
|
221
226
|
<input type="submit" name="commit" value="Register" class="btn btn-primary" data-disable-with="Register">
|
222
227
|
</form>
|
@@ -230,6 +235,23 @@ You can completely disable bootstrap and use default form builder by passing `di
|
|
230
235
|
<%= form.text_field :username, bootstrap: {disabled: true} %>
|
231
236
|
```
|
232
237
|
|
238
|
+
### Disabling wrapper
|
239
|
+
|
240
|
+
In some cases, you may need to disable the default wrapper. You can do this by passing 'wrapper: false':
|
241
|
+
|
242
|
+
![wrapper_false](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/1693cf0f-7a30-494d-9fb5-394f4fb2c676)
|
243
|
+
|
244
|
+
```erb
|
245
|
+
<%= form.text_field :name, bootstrap: {wrapper: false} %>
|
246
|
+
```
|
247
|
+
|
248
|
+
This generates the following HTML:
|
249
|
+
|
250
|
+
```html
|
251
|
+
<label class="form-label required" for="user_name">Name</label>
|
252
|
+
<input class="form-control" aria-required="true" required="required" type="text" name="user[name]" id="user_name">
|
253
|
+
```
|
254
|
+
|
233
255
|
## Supported Form Helpers
|
234
256
|
|
235
257
|
This gem wraps most of the form field helpers. Here's the current list:
|
@@ -666,7 +688,7 @@ Here's an example of how you pass the arguments for each form helper:
|
|
666
688
|
### check_box
|
667
689
|
|
668
690
|
Our `check_box` helper accepts the same arguments as the [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-check_box).
|
669
|
-
|
691
|
+
except it don't accept a `block` as an argument and renders check box and label for you.
|
670
692
|
|
671
693
|
![check_box](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/5836650c-d536-4f4e-b768-75bca9dd7901)
|
672
694
|
|
@@ -677,10 +699,11 @@ This helper will render check box and label for you.
|
|
677
699
|
This generates the following HTML:
|
678
700
|
|
679
701
|
```html
|
680
|
-
<div class="
|
681
|
-
<
|
682
|
-
|
683
|
-
|
702
|
+
<div class="mb-3">
|
703
|
+
<div class="form-check">
|
704
|
+
<input class="form-check-input" type="checkbox" value="1" name="user[remember_me]" id="user_remember_me">
|
705
|
+
<label class="form-check-label" for="user_remember_me">Keep me signed in</label>
|
706
|
+
</div>
|
684
707
|
</div>
|
685
708
|
```
|
686
709
|
|
@@ -695,10 +718,11 @@ You can set `switch` option to `true` if you want check box to look like switche
|
|
695
718
|
This generates the following HTML:
|
696
719
|
|
697
720
|
```html
|
698
|
-
<div class="
|
699
|
-
<
|
700
|
-
|
701
|
-
|
721
|
+
<div class="mb-3">
|
722
|
+
<div class="form-check form-switch">
|
723
|
+
<input class="form-check-input" type="checkbox" value="1" name="user[remember_me]" id="user_remember_me">
|
724
|
+
<label class="form-check-label" for="user_remember_me">Keep me signed in</label>
|
725
|
+
</div>
|
702
726
|
</div>
|
703
727
|
```
|
704
728
|
|
@@ -713,11 +737,12 @@ This helper also renders help text if `help_text` option is set or information o
|
|
713
737
|
This generates the following HTML:
|
714
738
|
|
715
739
|
```html
|
716
|
-
<div class="
|
717
|
-
<
|
718
|
-
|
719
|
-
|
720
|
-
|
740
|
+
<div class="mb-3">
|
741
|
+
<div class="form-check">
|
742
|
+
<input required="required" class="form-check-input" type="checkbox" value="1" name="user[terms]" id="user_terms">
|
743
|
+
<label class="form-check-label required" for="user_terms">I accept terms and conditions</label>
|
744
|
+
<div class="form-text text-muted">You must first accept terms and conditions in order to continue</div>
|
745
|
+
</div>
|
721
746
|
</div>
|
722
747
|
```
|
723
748
|
|
@@ -872,11 +897,12 @@ This generates the following HTML:
|
|
872
897
|
</select>
|
873
898
|
</div>
|
874
899
|
</div>
|
875
|
-
<div class="
|
876
|
-
<
|
877
|
-
|
878
|
-
|
879
|
-
|
900
|
+
<div class="mb-3">
|
901
|
+
<div class="form-check">
|
902
|
+
<input required="required" class="form-check-input" type="checkbox" value="1" name="user[terms]" id="user_terms">
|
903
|
+
<label class="form-check-label required" for="user_terms">I accept terms and conditions</label>
|
904
|
+
<div class="form-text text-muted">You must first accept terms and conditions in order to continue</div>
|
905
|
+
</div>
|
880
906
|
</div>
|
881
907
|
<input type="submit" name="commit" value="Register" class="btn btn-primary" data-disable-with="Register">
|
882
908
|
</form>
|
@@ -1065,9 +1091,11 @@ This helper will render check box and label for you.
|
|
1065
1091
|
This generates the following HTML:
|
1066
1092
|
|
1067
1093
|
```html
|
1068
|
-
<div class="
|
1069
|
-
<
|
1070
|
-
|
1094
|
+
<div class="mb-3">
|
1095
|
+
<div class="form-check">
|
1096
|
+
<input class="form-check-input" type="radio" value="male" name="user[gender]" id="user_gender_male">
|
1097
|
+
<label class="form-check-label" for="user_gender_male">Male</label>
|
1098
|
+
</div>
|
1071
1099
|
</div>
|
1072
1100
|
```
|
1073
1101
|
|
@@ -1082,10 +1110,12 @@ This helper also renders help text if `help_text` option is set or information o
|
|
1082
1110
|
This generates the following HTML:
|
1083
1111
|
|
1084
1112
|
```html
|
1085
|
-
<div class="
|
1086
|
-
<
|
1087
|
-
|
1088
|
-
|
1113
|
+
<div class="mb-3">
|
1114
|
+
<div class="form-check">
|
1115
|
+
<input class="form-check-input" type="radio" value="male" name="user[gender]" id="user_gender_male">
|
1116
|
+
<label class="form-check-label" for="user_gender_male">Male</label>
|
1117
|
+
<div class="form-text text-muted">Please select your gender</div>
|
1118
|
+
</div>
|
1089
1119
|
</div>
|
1090
1120
|
```
|
1091
1121
|
|
@@ -1405,7 +1435,7 @@ This generates the following HTML:
|
|
1405
1435
|
|
1406
1436
|
### collection_check_boxes
|
1407
1437
|
|
1408
|
-
This helper provides a way to create collection of check boxes. This helper accepts same arguments as [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_check_boxes) except it don't accept a block as
|
1438
|
+
This helper provides a way to create collection of check boxes. This helper accepts same arguments as [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_check_boxes) except it don't accept a `block` as
|
1409
1439
|
an argument and takes care of rendering labels, check boxes, and wrapper for you.
|
1410
1440
|
|
1411
1441
|
![collection_check_boxes](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/c92f5921-e572-4384-812e-31308e018f66)
|
@@ -1470,7 +1500,7 @@ This generates the following HTML:
|
|
1470
1500
|
|
1471
1501
|
### collection_radio_buttons
|
1472
1502
|
|
1473
|
-
This helper provides a way to create collection of radio buttons. This helper accepts same arguments as [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_radio_buttons) except it don't accept a block as
|
1503
|
+
This helper provides a way to create collection of radio buttons. This helper accepts same arguments as [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_radio_buttons) except it don't accept a `block` as
|
1474
1504
|
an argument and takes care of rendering labels, radio button, and wrapper for you.
|
1475
1505
|
|
1476
1506
|
![collection_radio_buttons](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/798a8b0c-915a-40b1-9874-dd74f50d3695)
|
@@ -1820,6 +1850,8 @@ This generates the following HTML:
|
|
1820
1850
|
</form>
|
1821
1851
|
```
|
1822
1852
|
|
1853
|
+
_Floating labels gets disabled by `rails_bootstrap_form` automatically for unsupported helpers._
|
1854
|
+
|
1823
1855
|
## Validation and Errors
|
1824
1856
|
|
1825
1857
|
By default, `rails_bootstrap_form` generations in-line errors which appear below the field.
|
@@ -1971,7 +2003,7 @@ bootstrap: {label_text: "<span></span>".html_safe}
|
|
1971
2003
|
|
1972
2004
|
## Contributing
|
1973
2005
|
|
1974
|
-
I welcome contributions. If you wish to contribute in `rails_bootstrap_form`, please review the [Contributing]() document first.
|
2006
|
+
I welcome contributions. If you wish to contribute in `rails_bootstrap_form`, please review the [Contributing](/CONTRIBUTING.md) document first.
|
1975
2007
|
|
1976
2008
|
## License
|
1977
2009
|
|
@@ -5,6 +5,9 @@
|
|
5
5
|
module RailsBootstrapForm
|
6
6
|
class BootstrapFormBuilder < ActionView::Helpers::FormBuilder
|
7
7
|
|
8
|
+
alias_method :check_box_without_bootstrap, :check_box
|
9
|
+
alias_method :radio_button_without_bootstrap, :radio_button
|
10
|
+
|
8
11
|
include RailsBootstrapForm::FieldWrapperBuilder
|
9
12
|
include RailsBootstrapForm::Helpers
|
10
13
|
include RailsBootstrapForm::InputGroupBuilder
|
@@ -42,8 +45,8 @@ module RailsBootstrapForm
|
|
42
45
|
|
43
46
|
def fields_for_options(record_object, fields_options)
|
44
47
|
fields_options = record_object if record_object.is_a?(Hash) && record_object.extractable_options?
|
45
|
-
|
46
|
-
fields_options =
|
48
|
+
bootstrap = {bootstrap: options.fetch(:bootstrap, {})}
|
49
|
+
fields_options = bootstrap.deep_merge!(fields_options)
|
47
50
|
fields_options
|
48
51
|
end
|
49
52
|
|
@@ -4,88 +4,89 @@
|
|
4
4
|
|
5
5
|
module RailsBootstrapForm
|
6
6
|
module FieldWrapperBuilder
|
7
|
-
def field_wrapper_builder(attribute,
|
8
|
-
field_options = field_css_options(attribute,
|
7
|
+
def field_wrapper_builder(attribute, bootstrap, options, html_options = nil, &block)
|
8
|
+
field_options = field_css_options(attribute, bootstrap, options, html_options.try(:symbolize_keys!))
|
9
9
|
|
10
|
-
field_wrapper(attribute,
|
10
|
+
field_wrapper(attribute, bootstrap, field_options, &block)
|
11
11
|
end
|
12
12
|
|
13
|
-
def field_wrapper(attribute,
|
14
|
-
label = draw_label(attribute, options,
|
15
|
-
help_text = help_text(attribute,
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
concat(help_text)
|
25
|
-
end)
|
13
|
+
def field_wrapper(attribute, bootstrap, options, &block)
|
14
|
+
label = draw_label(attribute, options, bootstrap)
|
15
|
+
help_text = help_text(attribute, bootstrap)
|
16
|
+
wrapper_content = ActiveSupport::SafeBuffer.new
|
17
|
+
|
18
|
+
if bootstrap.layout_horizontal?
|
19
|
+
wrapper_content << label
|
20
|
+
wrapper_content << tag.div(class: bootstrap.field_col_wrapper_class) do
|
21
|
+
input_group_wrapper(attribute, bootstrap) do
|
22
|
+
capture(&block)
|
23
|
+
end + help_text
|
26
24
|
end
|
27
25
|
else
|
28
|
-
if
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
concat(label)
|
34
|
-
end
|
35
|
-
end)
|
36
|
-
concat(help_text)
|
26
|
+
if bootstrap.floating?
|
27
|
+
wrapper_content << input_group_wrapper(attribute, bootstrap) do
|
28
|
+
tag.div(class: floating_label_classes(attribute)) do
|
29
|
+
capture(&block) + label
|
30
|
+
end
|
37
31
|
end
|
32
|
+
wrapper_content << help_text
|
38
33
|
else
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
capture(&block)
|
43
|
-
end)
|
44
|
-
concat(help_text)
|
34
|
+
wrapper_content << label
|
35
|
+
wrapper_content << input_group_wrapper(attribute, bootstrap) do
|
36
|
+
capture(&block)
|
45
37
|
end
|
38
|
+
wrapper_content << help_text
|
46
39
|
end
|
47
40
|
end
|
41
|
+
|
42
|
+
if bootstrap.wrapper
|
43
|
+
tag.div(**field_wrapper_options(bootstrap)) do
|
44
|
+
wrapper_content
|
45
|
+
end
|
46
|
+
else
|
47
|
+
wrapper_content
|
48
|
+
end
|
48
49
|
end
|
49
50
|
|
50
|
-
def field_wrapper_options(
|
51
|
-
wrapper_options =
|
51
|
+
def field_wrapper_options(bootstrap)
|
52
|
+
wrapper_options = bootstrap.wrapper
|
52
53
|
|
53
54
|
{}.tap do |option|
|
54
|
-
option[:class] = field_wrapper_classes(
|
55
|
+
option[:class] = field_wrapper_classes(bootstrap)
|
55
56
|
option.merge!(wrapper_options.except(:class)) if wrapper_options.is_a?(Hash)
|
56
57
|
end
|
57
58
|
end
|
58
59
|
|
59
|
-
def field_wrapper_classes(
|
60
|
+
def field_wrapper_classes(bootstrap)
|
60
61
|
classes = []
|
61
|
-
classes << "row" if
|
62
|
-
classes << field_wrapper_default_class(
|
63
|
-
classes <<
|
62
|
+
classes << "row" if bootstrap.layout_horizontal?
|
63
|
+
classes << field_wrapper_default_class(bootstrap)
|
64
|
+
classes << bootstrap.wrapper[:class] if bootstrap.wrapper.is_a?(Hash)
|
64
65
|
classes.flatten.compact
|
65
66
|
end
|
66
67
|
|
67
|
-
def field_wrapper_default_class(
|
68
|
-
|
68
|
+
def field_wrapper_default_class(bootstrap)
|
69
|
+
bootstrap.layout_inline? ? "col-12" : "mb-3"
|
69
70
|
end
|
70
71
|
|
71
|
-
def field_css_options(attribute,
|
72
|
+
def field_css_options(attribute, bootstrap, options, html_options)
|
72
73
|
css_options = (html_options || options)
|
73
74
|
|
74
75
|
field_classes = Array(options[:class])
|
75
76
|
field_classes << [
|
76
|
-
|
77
|
-
|
77
|
+
bootstrap.field_class,
|
78
|
+
bootstrap.additional_field_class
|
78
79
|
]
|
79
80
|
field_classes << "is-invalid" if is_invalid?(attribute)
|
80
|
-
if is_size_valid?(
|
81
|
-
field_classes << "#{
|
81
|
+
if is_size_valid?(bootstrap)
|
82
|
+
field_classes << "#{bootstrap.field_class}-#{bootstrap.size}"
|
82
83
|
end
|
83
84
|
|
84
85
|
css_options[:class] = field_classes.flatten.compact
|
85
86
|
css_options.merge!(required_field_options(attribute, options))
|
86
87
|
|
87
|
-
if placeholder_required?(
|
88
|
-
css_options[:placeholder] ||= label_text(attribute,
|
88
|
+
if placeholder_required?(bootstrap)
|
89
|
+
css_options[:placeholder] ||= label_text(attribute, bootstrap)
|
89
90
|
end
|
90
91
|
|
91
92
|
css_options
|
@@ -99,8 +100,8 @@ module RailsBootstrapForm
|
|
99
100
|
classes
|
100
101
|
end
|
101
102
|
|
102
|
-
def placeholder_required?(
|
103
|
-
(
|
103
|
+
def placeholder_required?(bootstrap)
|
104
|
+
(bootstrap.floating? && !bootstrap.layout_horizontal?) || bootstrap.layout_inline?
|
104
105
|
end
|
105
106
|
|
106
107
|
private :field_wrapper, :field_wrapper_classes, :field_wrapper_default_class,
|
@@ -10,15 +10,15 @@ module RailsBootstrapForm
|
|
10
10
|
def self.included(base_class)
|
11
11
|
def render_button(value = nil, options = {}, &block)
|
12
12
|
value, options = nil, value if value.is_a?(Hash)
|
13
|
-
|
13
|
+
bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
|
14
14
|
|
15
|
-
button_html = if (
|
15
|
+
button_html = if (bootstrap.render_as_button? || block)
|
16
16
|
button(value, options, &block)
|
17
17
|
else
|
18
18
|
submit(value, options)
|
19
19
|
end
|
20
20
|
|
21
|
-
if
|
21
|
+
if bootstrap.layout_inline?
|
22
22
|
tag.div(class: "col-12") { button_html }
|
23
23
|
else
|
24
24
|
button_html
|