rails_bootstrap_form 0.9.0 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +25 -0
  3. data/Gemfile.lock +1 -1
  4. data/README.md +97 -44
  5. data/demo/app/views/users/_horizontal_form.html.erb +7 -2
  6. data/demo/app/views/users/_vertical_form.html.erb +7 -2
  7. data/lib/rails_bootstrap_form/bootstrap_form_builder.rb +5 -2
  8. data/lib/rails_bootstrap_form/field_wrapper_builder.rb +54 -49
  9. data/lib/rails_bootstrap_form/helpers/buttons.rb +3 -3
  10. data/lib/rails_bootstrap_form/helpers/check_box.rb +26 -26
  11. data/lib/rails_bootstrap_form/helpers/help_text.rb +3 -3
  12. data/lib/rails_bootstrap_form/helpers/labels.rb +16 -16
  13. data/lib/rails_bootstrap_form/helpers/radio_button.rb +22 -23
  14. data/lib/rails_bootstrap_form/helpers.rb +2 -2
  15. data/lib/rails_bootstrap_form/input_group_builder.rb +14 -14
  16. data/lib/rails_bootstrap_form/inputs/base.rb +33 -6
  17. data/lib/rails_bootstrap_form/inputs/check_box.rb +11 -19
  18. data/lib/rails_bootstrap_form/inputs/collection_check_boxes.rb +9 -15
  19. data/lib/rails_bootstrap_form/inputs/collection_radio_buttons.rb +8 -16
  20. data/lib/rails_bootstrap_form/inputs/collection_select.rb +3 -3
  21. data/lib/rails_bootstrap_form/inputs/color_field.rb +3 -3
  22. data/lib/rails_bootstrap_form/inputs/grouped_collection_select.rb +3 -3
  23. data/lib/rails_bootstrap_form/inputs/radio_button.rb +11 -19
  24. data/lib/rails_bootstrap_form/inputs/range_field.rb +3 -3
  25. data/lib/rails_bootstrap_form/inputs/rich_text_area.rb +3 -3
  26. data/lib/rails_bootstrap_form/inputs/select.rb +3 -3
  27. data/lib/rails_bootstrap_form/inputs/time_zone_select.rb +3 -3
  28. data/lib/rails_bootstrap_form/inputs/weekday_select.rb +3 -3
  29. data/lib/rails_bootstrap_form/version.rb +1 -1
  30. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 15ea5c9f97b548a1fbadb720b875c2a0a784ea6184e77b62af1191865bcef46c
4
- data.tar.gz: 70f4b371a945958580eb8883868a799deb9b189454a1c8bf97ef263905dd0a39
3
+ metadata.gz: 23429dc16ad64529ba65b78cf376ff4bb5b31134bb87b1f8808af1fd32fe0427
4
+ data.tar.gz: 83785c866c4705460b55cbad301971492f360407b4d91abf49e0f11d25f07070
5
5
  SHA512:
6
- metadata.gz: 82b6509a781a1acd0ac837b1bd51900a2fa023bc1a55870905c25509fc48d674d1ee164ca309c8cf8446dae4364f815bf639ecab14b4c205c60cca0edd2e0a4b
7
- data.tar.gz: f2e4dd5bcd9a4f0f4aa5763d22bc9003118b8f8ad3e56f56c16dc30defd86ea95d877d6b0fdeaca54ffc11eeb32358bf3dd5a388c7165e966c4d9f366d709fef
6
+ metadata.gz: 3be8e0f60800ddd2fabf8b6db7a5d2d996bb45c932f184578448e4525bddd85d87f798b69dbc13787e04e87d2d2ed53dcabd4f9e78f97914247379a83237bafb
7
+ data.tar.gz: 2ab6a13c6b251556033636c06baa061b4379b8acea6461e1b6a36ddda9fd85a8892b322c660aa7d68e2377f6271250fa28fe35691c7f35a5001e5b928597d21f
data/CHANGELOG.md CHANGED
@@ -4,6 +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.2](https://github.com/shivam091/rails_bootstrap_form/compare/v0.9.1...v0.9.2) - 2023-06-03
8
+
9
+ ### What's new
10
+
11
+ - Added support to disable wrapper by passing option `wrapper: false`.
12
+
13
+ ### What's fixed
14
+
15
+ - 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)).
16
+
17
+ ### What's changed
18
+
19
+ - Wrappers of `check_box`, `collection_check_boxes`, `radio_button`, and `collection_radio_buttons` helpers.
20
+
21
+ ## [0.9.1](https://github.com/shivam091/rails_bootstrap_form/compare/v0.9.0...v0.9.1) - 2023-06-02
22
+
23
+ ### What's new
24
+
25
+ - Allow user to configure `options[:multiple]` for `collection_check_boxes`.
26
+ - Added option `inline` to control inline rendering of `collection_check_boxes` and `collection_radio_buttons`.
27
+
28
+ ### What's changed
29
+
30
+ - `wrapper[:class]` will now be appended to existing field wrapper CSS classes ([#29](https://github.com/shivam091/rails_bootstrap_form/issues/29))
31
+
7
32
  ## [0.9.0](https://github.com/shivam091/rails_bootstrap_form/compare/v0.8.3...v0.9.0) - 2023-05-31
8
33
 
9
34
  ### What's new
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails_bootstrap_form (0.9.0)
4
+ rails_bootstrap_form (0.9.2)
5
5
  actionpack (~> 7.0)
6
6
  activemodel (~> 7.0)
7
7
 
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="form-check mb-3">
107
- <input name="user[remember_me]" type="hidden" value="0" autocomplete="off">
108
- <input class="form-check-input" type="checkbox" value="1" name="user[remember_me]" id="user_remember_me">
109
- <label class="form-check-label" for="user_remember_me">Remember me</label>
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="form-check mb-3">
143
- <input name="user[remember_me]" type="hidden" value="0" autocomplete="off">
144
- <input class="form-check-input" type="checkbox" value="1" name="user[remember_me]" id="user_remember_me">
145
- <label class="form-check-label" for="user_remember_me">Remember me</label>
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, required: true %>
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="form-check mb-3">
216
- <input name="user[terms]" type="hidden" value="0" autocomplete="off">
217
- <input required="required" class="form-check-input" type="checkbox" value="1" name="user[terms]" id="user_terms">
218
- <label class="form-check-label required" for="user_terms">I accept terms and conditions</label>
219
- <div class="form-text text-muted">You must first accept terms and conditions in order to continue</div>
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:
@@ -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="form-check mb-3">
681
- <input name="user[remember_me]" type="hidden" value="0" autocomplete="off">
682
- <input class="form-check-input" type="checkbox" value="1" name="user[remember_me]" id="user_remember_me">
683
- <label class="form-check-label" for="user_remember_me">Keep me signed in</label>
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="form-check form-switch mb-3">
699
- <input name="user[remember_me]" type="hidden" value="0" autocomplete="off">
700
- <input class="form-check-input" type="checkbox" value="1" name="user[remember_me]" id="user_remember_me">
701
- <label class="form-check-label" for="user_remember_me">Keep me signed in</label>
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="form-check mb-3">
717
- <input name="user[terms]" type="hidden" value="0" autocomplete="off">
718
- <input required="required" class="form-check-input" type="checkbox" value="1" name="user[terms]" id="user_terms">
719
- <label class="form-check-label required" for="user_terms">I accept terms and conditions</label>
720
- <div class="form-text text-muted">You must first accept terms and conditions in order to continue</div>
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
 
@@ -836,7 +861,6 @@ Our `fields_for` helper accepts the same arguments as the [default Rails helper]
836
861
  <%= form.check_box :terms, required: true %>
837
862
  <%= form.primary "Register" %>
838
863
  <% end %>
839
-
840
864
  ```
841
865
 
842
866
  This generates the following HTML:
@@ -873,11 +897,12 @@ This generates the following HTML:
873
897
  </select>
874
898
  </div>
875
899
  </div>
876
- <div class="form-check mb-3">
877
- <input name="user[terms]" type="hidden" value="0" autocomplete="off">
878
- <input required="required" class="form-check-input" type="checkbox" value="1" name="user[terms]" id="user_terms">
879
- <label class="form-check-label required" for="user_terms">I accept terms and conditions</label>
880
- <div class="form-text text-muted">You must first accept terms and conditions in order to continue</div>
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>
881
906
  </div>
882
907
  <input type="submit" name="commit" value="Register" class="btn btn-primary" data-disable-with="Register">
883
908
  </form>
@@ -1066,9 +1091,11 @@ This helper will render check box and label for you.
1066
1091
  This generates the following HTML:
1067
1092
 
1068
1093
  ```html
1069
- <div class="form-check mb-3">
1070
- <input class="form-check-input" type="radio" value="male" name="user[gender]" id="user_gender_male">
1071
- <label class="form-check-label" for="user_gender_male">Male</label>
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>
1072
1099
  </div>
1073
1100
  ```
1074
1101
 
@@ -1083,10 +1110,12 @@ This helper also renders help text if `help_text` option is set or information o
1083
1110
  This generates the following HTML:
1084
1111
 
1085
1112
  ```html
1086
- <div class="form-check mb-3">
1087
- <input class="form-check-input" type="radio" value="male" name="user[gender]" id="user_gender_male">
1088
- <label class="form-check-label" for="user_gender_male">Male</label>
1089
- <div class="form-text text-muted">Please select your gender</div>
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>
1090
1119
  </div>
1091
1120
  ```
1092
1121
 
@@ -1412,7 +1441,7 @@ an argument and takes care of rendering labels, check boxes, and wrapper for you
1412
1441
  ![collection_check_boxes](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/c92f5921-e572-4384-812e-31308e018f66)
1413
1442
 
1414
1443
  ```erb
1415
- <%= form.collection_check_boxes :skill_ids, ::Skill.all, :id, :name, {bootstrap: {layout: :horizontal}, onchange: "this.form.submit();"}, {} %>
1444
+ <%= form.collection_check_boxes :skill_ids, ::Skill.all, :id, :name, {bootstrap: {layout: :horizontal, inline: true}, onchange: "this.form.submit();"}, {} %>
1416
1445
  ```
1417
1446
 
1418
1447
  This generates the following HTML:
@@ -1477,7 +1506,7 @@ an argument and takes care of rendering labels, radio button, and wrapper for yo
1477
1506
  ![collection_radio_buttons](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/798a8b0c-915a-40b1-9874-dd74f50d3695)
1478
1507
 
1479
1508
  ```erb
1480
- <%= form.collection_radio_buttons :fruit_id, ::Fruit.all, :id, :name, {checked: form.object.fruit_id, bootstrap: {layout: :horizontal}}, {} %>
1509
+ <%= form.collection_radio_buttons :fruit_id, ::Fruit.all, :id, :name, {checked: form.object.fruit_id, bootstrap: {layout: :horizontal, inline: true}}, {} %>
1481
1510
  ```
1482
1511
 
1483
1512
  This generates the following HTML:
@@ -1858,6 +1887,30 @@ This generates the following HTML:
1858
1887
  </form>
1859
1888
  ```
1860
1889
 
1890
+ Inline errors are also supported if the field is wrapped inside of input group and has floating label:
1891
+
1892
+ ![floating_inline_errors](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/89deb618-3f06-463b-91fb-60c50794387c)
1893
+
1894
+ ```erb
1895
+ <%= form.text_field :expected_ctc, bootstrap: {floating: true, prepend: "$", append: "0.0"} %>
1896
+ ```
1897
+
1898
+ This generates the following HTML:
1899
+
1900
+ ```html
1901
+ <div class="mb-3">
1902
+ <div class="input-group has-validation">
1903
+ <span class="input-group-text">$</span>
1904
+ <div class="form-floating is-invalid">
1905
+ <input class="form-control is-invalid" aria-required="true" required="required" placeholder="Expected CTC" type="text" value="" name="user[expected_ctc]" id="user_expected_ctc">
1906
+ <label class="form-label required is-invalid" for="user_expected_ctc">Expected CTC</label>
1907
+ </div>
1908
+ <span class="input-group-text">0.0</span>
1909
+ <div class="invalid-feedback">can't be blank</div>
1910
+ </div>
1911
+ </div>
1912
+ ```
1913
+
1861
1914
  ## Required Fields
1862
1915
 
1863
1916
  A label that is associated with a mandatory field is automatically annotated with a `required` CSS class. `rails_bootstrap_form` provides styling for required fields.
@@ -1948,7 +2001,7 @@ bootstrap: {label_text: "<span></span>".html_safe}
1948
2001
 
1949
2002
  ## Contributing
1950
2003
 
1951
- I welcome contributions. If you wish to contribute in `rails_bootstrap_form`, please review the [Contributing]() document first.
2004
+ I welcome contributions. If you wish to contribute in `rails_bootstrap_form`, please review the [Contributing](/CONTRIBUTING.md) document first.
1952
2005
 
1953
2006
  ## License
1954
2007
 
@@ -12,9 +12,14 @@
12
12
  <%= form.date_field :birth_date %>
13
13
  <%= form.range_field :excellence %>
14
14
  <%= form.url_field :blog_url %>
15
- <%= form.collection_radio_buttons :fruit_id, ::Fruit.all, :id, :name, {checked: form.object.fruit_id} %>
15
+ <%= form.collection_radio_buttons :fruit_id, ::Fruit.all, :id, :name, {checked: form.object.fruit_id, bootstrap: {inline: true}} %>
16
16
  <%= form.color_field :favorite_color %>
17
- <%= form.collection_check_boxes :skill_ids, ::Skill.all, :id, :name %>
17
+ <%= form.collection_check_boxes :skill_ids, ::Skill.all, :id, :name, multiple: true, bootstrap: {inline: true} %>
18
+ <%= form.number_field :expected_ctc, bootstrap: {prepend: "$", append: "0.0"} %>
19
+ <%= form.date_select :interview_date %>
20
+ <%= form.time_select :interview_time %>
21
+ <%= form.datetime_select :interview_datetime %>
22
+ <%= form.weekday_select :weekly_off %>
18
23
  <%= form.fields_for :address, include_id: false do |address_form| %>
19
24
  <%= address_form.text_area :street %>
20
25
  <%= address_form.text_field :state %>
@@ -12,9 +12,14 @@
12
12
  <%= form.date_field :birth_date %>
13
13
  <%= form.range_field :excellence %>
14
14
  <%= form.url_field :blog_url %>
15
- <%= form.collection_radio_buttons :fruit_id, ::Fruit.all, :id, :name, {checked: form.object.fruit_id} %>
15
+ <%= form.collection_radio_buttons :fruit_id, ::Fruit.all, :id, :name, {checked: form.object.fruit_id, bootstrap: {inline: true}} %>
16
16
  <%= form.color_field :favorite_color %>
17
- <%= form.collection_check_boxes :skill_ids, ::Skill.all, :id, :name %>
17
+ <%= form.collection_check_boxes :skill_ids, ::Skill.all, :id, :name, multiple: true, bootstrap: {inline: true} %>
18
+ <%= form.number_field :expected_ctc, bootstrap: {prepend: "$", append: "0.0"} %>
19
+ <%= form.date_select :interview_date %>
20
+ <%= form.time_select :interview_time %>
21
+ <%= form.datetime_select :interview_datetime %>
22
+ <%= form.weekday_select :weekly_off %>
18
23
  <%= form.fields_for :address, include_id: false do |address_form| %>
19
24
  <%= address_form.text_area :street %>
20
25
  <%= address_form.text_field :state %>
@@ -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
- bootstrap_options = {bootstrap: options.fetch(:bootstrap, {})}
46
- fields_options = bootstrap_options.deep_merge!(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,84 +4,89 @@
4
4
 
5
5
  module RailsBootstrapForm
6
6
  module FieldWrapperBuilder
7
- def field_wrapper_builder(attribute, bootstrap_options, options, html_options = nil, &block)
8
- field_options = field_css_options(attribute, bootstrap_options, options, html_options.try(:symbolize_keys!))
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, bootstrap_options, field_options, &block)
10
+ field_wrapper(attribute, bootstrap, field_options, &block)
11
11
  end
12
12
 
13
- def field_wrapper(attribute, bootstrap_options, options, &block)
14
- label = draw_label(attribute, options, bootstrap_options)
15
- help_text = help_text(attribute, bootstrap_options)
16
-
17
- if bootstrap_options.layout_horizontal?
18
- tag.div(**field_wrapper_options(bootstrap_options)) do
19
- concat(label)
20
- concat(tag.div(class: bootstrap_options.field_col_wrapper_class) do
21
- concat(input_group_wrapper(attribute, bootstrap_options) do
22
- capture(&block)
23
- end)
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 bootstrap_options.floating?
29
- tag.div(**field_wrapper_options(bootstrap_options)) do
30
- concat(input_group_wrapper(attribute, bootstrap_options) do
31
- tag.div(class: floating_label_classes(attribute)) do
32
- concat(capture(&block))
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
- tag.div(**field_wrapper_options(bootstrap_options)) do
40
- concat(label)
41
- concat(input_group_wrapper(attribute, bootstrap_options) do
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(bootstrap_options)
51
+ def field_wrapper_options(bootstrap)
52
+ wrapper_options = bootstrap.wrapper
53
+
51
54
  {}.tap do |option|
52
- option[:class] = field_wrapper_classes(bootstrap_options)
53
- end.merge(bootstrap_options.wrapper)
55
+ option[:class] = field_wrapper_classes(bootstrap)
56
+ option.merge!(wrapper_options.except(:class)) if wrapper_options.is_a?(Hash)
57
+ end
54
58
  end
55
59
 
56
- def field_wrapper_classes(bootstrap_options)
60
+ def field_wrapper_classes(bootstrap)
57
61
  classes = []
58
- classes << "row" if bootstrap_options.layout_horizontal?
59
- classes << form_wrapper_default_class(bootstrap_options)
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)
60
65
  classes.flatten.compact
61
66
  end
62
67
 
63
- def form_wrapper_default_class(bootstrap_options)
64
- bootstrap_options.layout_inline? ? "col-12" : "mb-3"
68
+ def field_wrapper_default_class(bootstrap)
69
+ bootstrap.layout_inline? ? "col-12" : "mb-3"
65
70
  end
66
71
 
67
- def field_css_options(attribute, bootstrap_options, options, html_options)
72
+ def field_css_options(attribute, bootstrap, options, html_options)
68
73
  css_options = (html_options || options)
69
74
 
70
75
  field_classes = Array(options[:class])
71
76
  field_classes << [
72
- bootstrap_options.field_class,
73
- bootstrap_options.additional_field_class
77
+ bootstrap.field_class,
78
+ bootstrap.additional_field_class
74
79
  ]
75
80
  field_classes << "is-invalid" if is_invalid?(attribute)
76
- if is_size_valid?(bootstrap_options)
77
- field_classes << "#{bootstrap_options.field_class}-#{bootstrap_options.size}"
81
+ if is_size_valid?(bootstrap)
82
+ field_classes << "#{bootstrap.field_class}-#{bootstrap.size}"
78
83
  end
79
84
 
80
85
  css_options[:class] = field_classes.flatten.compact
81
86
  css_options.merge!(required_field_options(attribute, options))
82
87
 
83
- if placeholder_required?(bootstrap_options)
84
- css_options[:placeholder] ||= label_text(attribute, bootstrap_options)
88
+ if placeholder_required?(bootstrap)
89
+ css_options[:placeholder] ||= label_text(attribute, bootstrap)
85
90
  end
86
91
 
87
92
  css_options
@@ -95,11 +100,11 @@ module RailsBootstrapForm
95
100
  classes
96
101
  end
97
102
 
98
- def placeholder_required?(bootstrap_options)
99
- (bootstrap_options.floating? && !bootstrap_options.layout_horizontal?) || bootstrap_options.layout_inline?
103
+ def placeholder_required?(bootstrap)
104
+ (bootstrap.floating? && !bootstrap.layout_horizontal?) || bootstrap.layout_inline?
100
105
  end
101
106
 
102
- private :field_wrapper, :field_wrapper_classes, :form_wrapper_default_class,
107
+ private :field_wrapper, :field_wrapper_classes, :field_wrapper_default_class,
103
108
  :field_css_options, :floating_label_classes
104
109
  end
105
110
  end
@@ -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
- bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
13
+ bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
14
14
 
15
- button_html = if (bootstrap_options.render_as_button? || block)
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 bootstrap_options.layout_inline?
21
+ if bootstrap.layout_inline?
22
22
  tag.div(class: "col-12") { button_html }
23
23
  else
24
24
  button_html
@@ -8,10 +8,10 @@ module RailsBootstrapForm
8
8
  extend ActiveSupport::Concern
9
9
 
10
10
  def self.included(base_class)
11
- def check_box_label(attribute, checked_value, options, bootstrap_options, &block)
12
- unless bootstrap_options.skip_label?
11
+ def check_box_label(attribute, checked_value, options, bootstrap, &block)
12
+ unless bootstrap.skip_label?
13
13
  label_options = {
14
- class: check_box_label_class(attribute, bootstrap_options, options)
14
+ class: check_box_label_class(attribute, bootstrap, options)
15
15
  }
16
16
  label_options[:for] = options[:id] if options[:id].present?
17
17
 
@@ -21,20 +21,14 @@ module RailsBootstrapForm
21
21
  attribute
22
22
  end
23
23
 
24
- label_text = check_box_label_text(attribute, options, bootstrap_options, &block)
24
+ label_text = check_box_label_text(attribute, options, bootstrap, &block)
25
25
 
26
26
  label(label_name, label_text, label_options)
27
27
  end
28
28
  end
29
29
 
30
- def check_box_wrapper_options(bootstrap_options)
31
- {}.tap do |option|
32
- option[:class] = check_box_wrapper_class(bootstrap_options)
33
- end.merge(bootstrap_options.wrapper)
34
- end
35
-
36
- def check_box_label_text(attribute, options, bootstrap_options, &block)
37
- block ? capture(&block) : label_text(attribute, bootstrap_options)
30
+ def check_box_label_text(attribute, options, bootstrap, &block)
31
+ block ? capture(&block) : label_text(attribute, bootstrap)
38
32
  end
39
33
 
40
34
  def check_box_value(attribute, value)
@@ -50,32 +44,38 @@ module RailsBootstrapForm
50
44
  classes.flatten.compact
51
45
  end
52
46
 
53
- def check_box_label_class(attribute, bootstrap_options, options)
54
- classes = Array("form-check-label") << bootstrap_options.additional_label_class
55
- classes << "required" if is_field_required?(attribute, options) && !bootstrap_options.inline?
47
+ def check_box_label_class(attribute, bootstrap, options)
48
+ classes = Array("form-check-label") << bootstrap.additional_label_class
49
+ classes << "required" if is_field_required?(attribute, options)
56
50
  classes << "is-invalid" if is_invalid?(attribute)
57
- classes << bootstrap_options.hide_class if bootstrap_options.hide_label?
51
+ classes << bootstrap.hide_class if bootstrap.hide_label?
58
52
  classes.flatten.compact
59
53
  end
60
54
 
61
- def check_box_wrapper_class(bootstrap_options)
55
+ def check_box_wrapper_classes(bootstrap)
62
56
  classes = Array("form-check")
63
- classes << "form-switch" if bootstrap_options.switch?
64
- classes << "form-check-inline" if bootstrap_options.inline?
65
- if (bootstrap_options.layout_vertical? && !bootstrap_options.inline?)
66
- classes << "mb-3"
67
- end
57
+ classes << "form-switch" if bootstrap.switch?
58
+ classes << "form-check-inline" if bootstrap.inline?
68
59
  classes.flatten.compact
69
60
  end
70
61
 
71
- def check_box_container_classes(bootstrap_options)
72
- classes = Array(bootstrap_options.field_col_wrapper_class)
73
- classes << field_offset_class(bootstrap_options.label_col_wrapper_class)
62
+ def check_box_container_classes(bootstrap)
63
+ classes = Array(bootstrap.field_col_wrapper_class)
64
+ classes << field_offset_class(bootstrap.label_col_wrapper_class)
74
65
  classes.flatten.compact
75
66
  end
76
67
 
68
+ def bootstrap_check_box(attribute, value, options, bootstrap)
69
+ options[:class] = check_box_classes(attribute, options)
70
+ check_box_field = check_box_without_bootstrap(attribute, options, value, nil)
71
+ check_box_label = check_box_label(attribute, value, options, bootstrap)
72
+
73
+ check_box_field + check_box_label
74
+ end
75
+
77
76
  private :check_box_label, :check_box_classes, :check_box_label_class,
78
- :check_box_wrapper_class, :check_box_container_classes
77
+ :check_box_wrapper_classes, :check_box_container_classes,
78
+ :bootstrap_check_box
79
79
  end
80
80
  end
81
81
  end
@@ -8,10 +8,10 @@ module RailsBootstrapForm
8
8
  extend ActiveSupport::Concern
9
9
 
10
10
  def self.included(base_class)
11
- def help_text(attribute, bootstrap_options)
12
- return if bootstrap_options.help_text == false
11
+ def help_text(attribute, bootstrap)
12
+ return if bootstrap.help_text == false
13
13
 
14
- help_text = (bootstrap_options.help_text || scoped_help_text(attribute))
14
+ help_text = (bootstrap.help_text || scoped_help_text(attribute))
15
15
 
16
16
  tag.div(help_text, class: "form-text text-muted") if help_text.present?
17
17
  end
@@ -8,42 +8,42 @@ module RailsBootstrapForm
8
8
  extend ActiveSupport::Concern
9
9
 
10
10
  def self.included(base_class)
11
- def draw_label(attribute, options, bootstrap_options)
12
- unless bootstrap_options.skip_label? && !bootstrap_options.floating?
11
+ def draw_label(attribute, options, bootstrap)
12
+ unless bootstrap.skip_label? && !bootstrap.floating?
13
13
  label_options = {
14
- class: label_classes(attribute, options, bootstrap_options)
14
+ class: label_classes(attribute, options, bootstrap)
15
15
  }
16
16
  label_options[:for] = options[:id] if options[:id].present?
17
- label_text = label_text(attribute, bootstrap_options)
17
+ label_text = label_text(attribute, bootstrap)
18
18
 
19
19
  label(attribute, label_text, label_options)
20
20
  end
21
21
  end
22
22
 
23
- def label_classes(attribute, options, bootstrap_options)
23
+ def label_classes(attribute, options, bootstrap)
24
24
  classes = []
25
- classes << label_layout_classes(bootstrap_options)
26
- classes << bootstrap_options.additional_label_class
27
- classes << bootstrap_options.hide_class if hide_class_required?(bootstrap_options)
25
+ classes << label_layout_classes(bootstrap)
26
+ classes << bootstrap.additional_label_class
27
+ classes << bootstrap.hide_class if hide_class_required?(bootstrap)
28
28
  classes << "required" if is_field_required?(attribute, options)
29
29
  classes << "is-invalid" if is_invalid?(attribute)
30
30
  classes.flatten.compact
31
31
  end
32
32
 
33
- def label_layout_classes(bootstrap_options)
34
- if bootstrap_options.layout_horizontal?
35
- [bootstrap_options.label_col_class, bootstrap_options.label_col_wrapper_class]
33
+ def label_layout_classes(bootstrap)
34
+ if bootstrap.layout_horizontal?
35
+ [bootstrap.label_col_class, bootstrap.label_col_wrapper_class]
36
36
  else
37
- bootstrap_options.label_class
37
+ bootstrap.label_class
38
38
  end
39
39
  end
40
40
 
41
- def label_text(attribute, bootstrap_options)
42
- bootstrap_options.label_text || object&.class.try(:human_attribute_name, attribute)
41
+ def label_text(attribute, bootstrap)
42
+ bootstrap.label_text || object&.class.try(:human_attribute_name, attribute)
43
43
  end
44
44
 
45
- def hide_class_required?(bootstrap_options)
46
- bootstrap_options.hide_label? || (bootstrap_options.layout_inline? && !bootstrap_options.floating?)
45
+ def hide_class_required?(bootstrap)
46
+ bootstrap.hide_label? || (bootstrap.layout_inline? && !bootstrap.floating?)
47
47
  end
48
48
 
49
49
  private :draw_label, :label_classes, :label_text, :label_layout_classes,
@@ -8,11 +8,11 @@ module RailsBootstrapForm
8
8
  extend ActiveSupport::Concern
9
9
 
10
10
  def self.included(base_class)
11
- def radio_button_label(attribute, value, options, bootstrap_options)
12
- unless bootstrap_options.skip_label?
11
+ def radio_button_label(attribute, value, options, bootstrap)
12
+ unless bootstrap.skip_label?
13
13
  label_options = {
14
14
  value: value,
15
- class: radio_button_label_class(attribute, bootstrap_options, options)
15
+ class: radio_button_label_class(attribute, bootstrap, options)
16
16
  }
17
17
  label_options[:for] = options[:id] if options[:id].present?
18
18
 
@@ -22,18 +22,12 @@ module RailsBootstrapForm
22
22
  attribute
23
23
  end
24
24
 
25
- label_text = label_text(attribute, bootstrap_options)
25
+ label_text = label_text(attribute, bootstrap)
26
26
 
27
27
  label(label_name, label_text, label_options)
28
28
  end
29
29
  end
30
30
 
31
- def radio_button_wrapper_options(bootstrap_options)
32
- {}.tap do |option|
33
- option[:class] = radio_button_wrapper_class(bootstrap_options)
34
- end.merge(bootstrap_options.wrapper)
35
- end
36
-
37
31
  def radio_button_value(attribute, value)
38
32
  # label's `for` attribute needs to match checkbox tag's id,
39
33
  # IE sanitized value, IE
@@ -47,31 +41,36 @@ module RailsBootstrapForm
47
41
  classes.flatten.compact
48
42
  end
49
43
 
50
- def radio_button_label_class(attribute, bootstrap_options, options)
51
- classes = Array("form-check-label") << bootstrap_options.additional_label_class
52
- classes << "required" if is_field_required?(attribute, options) && !bootstrap_options.inline?
44
+ def radio_button_label_class(attribute, bootstrap, options)
45
+ classes = Array("form-check-label") << bootstrap.additional_label_class
46
+ classes << "required" if is_field_required?(attribute, options)
53
47
  classes << "is-invalid" if is_invalid?(attribute)
54
- classes << bootstrap_options.hide_class if bootstrap_options.hide_label?
48
+ classes << bootstrap.hide_class if bootstrap.hide_label?
55
49
  classes.flatten.compact
56
50
  end
57
51
 
58
- def radio_button_wrapper_class(bootstrap_options)
52
+ def radio_button_wrapper_classes(bootstrap)
59
53
  classes = Array("form-check")
60
- classes << "form-check-inline" if bootstrap_options.inline?
61
- if (bootstrap_options.layout_vertical? && !bootstrap_options.inline?)
62
- classes << "mb-3"
63
- end
54
+ classes << "form-check-inline" if bootstrap.inline?
64
55
  classes.flatten.compact
65
56
  end
66
57
 
67
- def radio_button_container_classes(bootstrap_options)
68
- classes = Array(bootstrap_options.field_col_wrapper_class)
69
- classes << field_offset_class(bootstrap_options.label_col_wrapper_class)
58
+ def radio_button_container_classes(bootstrap)
59
+ classes = Array(bootstrap.field_col_wrapper_class)
60
+ classes << field_offset_class(bootstrap.label_col_wrapper_class)
70
61
  classes.flatten.compact
71
62
  end
72
63
 
64
+ def bootstrap_radio_button(attribute, value, options, bootstrap)
65
+ options[:class] = radio_button_classes(attribute, options)
66
+ radio_button_field = radio_button_without_bootstrap(attribute, value, options)
67
+ radio_button_label = radio_button_label(attribute, value, options, bootstrap)
68
+
69
+ radio_button_field + radio_button_label
70
+ end
71
+
73
72
  private :radio_button_label, :radio_button_classes, :radio_button_label_class,
74
- :radio_button_wrapper_class, :radio_button_container_classes
73
+ :radio_button_wrapper_classes, :radio_button_container_classes
75
74
  end
76
75
  end
77
76
  end
@@ -33,8 +33,8 @@ module RailsBootstrapForm
33
33
  "rails-bootstrap-forms-#{field_tag_name.to_s.tr("_", "-")}"
34
34
  end
35
35
 
36
- def is_size_valid?(bootstrap_options)
37
- bootstrap_options.size && %i(sm lg).include?(bootstrap_options.size)
36
+ def is_size_valid?(bootstrap)
37
+ bootstrap.size && %i(sm lg).include?(bootstrap.size)
38
38
  end
39
39
 
40
40
  def field_offset_class(label_col_wrapper_class)
@@ -7,17 +7,17 @@ module RailsBootstrapForm
7
7
  extend ActiveSupport::Concern
8
8
 
9
9
  def self.included(base_class)
10
- def input_group_wrapper(attribute, bootstrap_options, &block)
10
+ def input_group_wrapper(attribute, bootstrap, &block)
11
11
  input = capture(&block) || ActiveSupport::SafeBuffer.new
12
12
 
13
- if input_group_required?(bootstrap_options)
14
- prepend = attach_input(bootstrap_options, :prepend)
15
- append = attach_input(bootstrap_options, :append)
13
+ if input_group_required?(bootstrap)
14
+ prepend = attach_input(bootstrap, :prepend)
15
+ append = attach_input(bootstrap, :append)
16
16
 
17
17
  input = prepend + input + append
18
18
  input += generate_error(attribute)
19
19
 
20
- input = tag.div(input, class: input_group_classes(attribute, bootstrap_options))
20
+ input = tag.div(input, class: input_group_classes(attribute, bootstrap))
21
21
  else
22
22
  input += generate_error(attribute)
23
23
  end
@@ -25,18 +25,18 @@ module RailsBootstrapForm
25
25
  input
26
26
  end
27
27
 
28
- def input_group_classes(attribute, bootstrap_options)
29
- classes = Array("input-group") << bootstrap_options.additional_input_group_class
30
- if is_size_valid?(bootstrap_options)
31
- classes << "input-group-#{bootstrap_options.size}"
28
+ def input_group_classes(attribute, bootstrap)
29
+ classes = Array("input-group") << bootstrap.additional_input_group_class
30
+ if is_size_valid?(bootstrap)
31
+ classes << "input-group-#{bootstrap.size}"
32
32
  end
33
33
  # Require `has-validation` class if field has errors.
34
34
  classes << "has-validation" if is_invalid?(attribute)
35
35
  classes.flatten.compact
36
36
  end
37
37
 
38
- def attach_input(bootstrap_options, key)
39
- tags = [*bootstrap_options.send(key)].map do |item|
38
+ def attach_input(bootstrap, key)
39
+ tags = [*bootstrap.send(key)].map do |item|
40
40
  input_group_content(item)
41
41
  end
42
42
 
@@ -49,10 +49,10 @@ module RailsBootstrapForm
49
49
  tag.span(content.html_safe, class: "input-group-text")
50
50
  end
51
51
 
52
- def input_group_required?(bootstrap_options)
52
+ def input_group_required?(bootstrap)
53
53
  [
54
- bootstrap_options.prepend,
55
- bootstrap_options.append
54
+ bootstrap.prepend,
55
+ bootstrap.append
56
56
  ].any?(&:present?)
57
57
  end
58
58
 
@@ -7,13 +7,40 @@ module RailsBootstrapForm
7
7
  module Base
8
8
  extend ActiveSupport::Concern
9
9
 
10
+ included do
11
+ def inputs_collection(attribute, collection, value_method, text_method, bootstrap, options = {})
12
+ inputs = ActiveSupport::SafeBuffer.new
13
+
14
+ collection.each do |object|
15
+ value = object.send(value_method)
16
+ input_options = {
17
+ bootstrap: {
18
+ label_text: text_method.respond_to?(:call) ? text_method.call(object) : object.send(text_method),
19
+ inline: bootstrap.inline?
20
+ },
21
+ required: false
22
+ }.deep_merge!(options)
23
+
24
+ if (checked = input_options[:checked])
25
+ input_options[:checked] = collection_input_checked?(checked, object, value)
26
+ end
27
+
28
+ input_value = value_method.respond_to?(:call) ? value_method.call(object) : value
29
+
30
+ inputs << yield(attribute, input_value, input_options)
31
+ end
32
+
33
+ inputs
34
+ end
35
+ end
36
+
10
37
  class_methods do
11
38
  def bootstrap_field(field_name)
12
39
  define_method(field_name) do |attribute, options = {}|
13
- bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
14
- return super(attribute, options) if bootstrap_options.disabled?
40
+ bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
41
+ return super(attribute, options) if bootstrap.disabled?
15
42
 
16
- field_wrapper_builder(attribute, bootstrap_options, options) do
43
+ field_wrapper_builder(attribute, bootstrap, options) do
17
44
  super(attribute, options)
18
45
  end
19
46
  end
@@ -23,10 +50,10 @@ module RailsBootstrapForm
23
50
  define_method(field_name) do |attribute, options = {}, html_options = {}|
24
51
  options = {bootstrap: {field_class: "form-select"}}.deep_merge!(options)
25
52
 
26
- bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
27
- return super(attribute, options, html_options) if bootstrap_options.disabled?
53
+ bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
54
+ return super(attribute, options, html_options) if bootstrap.disabled?
28
55
 
29
- field_wrapper_builder(attribute, bootstrap_options, options, html_options) do
56
+ field_wrapper_builder(attribute, bootstrap, options, html_options) do
30
57
  tag.fieldset(class: control_specific_class(field_name)) do
31
58
  super(attribute, options, html_options)
32
59
  end
@@ -9,31 +9,23 @@ module RailsBootstrapForm
9
9
 
10
10
  included do
11
11
  def check_box(attribute, options = {}, checked_value = "1", unchecked_value = "0", &block)
12
- bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
13
- return super if bootstrap_options.disabled?
12
+ bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
13
+ return super if bootstrap.disabled?
14
14
 
15
- options[:class] = check_box_classes(attribute, options)
16
-
17
- check_box_field = super(attribute, options, checked_value, unchecked_value)
18
- check_box_help_text = help_text(attribute, bootstrap_options)
19
-
20
- check_box_label = check_box_label(attribute, checked_value, options, bootstrap_options, &block)
21
-
22
- check_box_html = tag.div(**check_box_wrapper_options(bootstrap_options)) do
23
- concat(check_box_field)
24
- concat(check_box_label)
25
- concat(check_box_help_text) unless bootstrap_options.inline?
26
- concat(generate_error(attribute)) if (is_invalid?(attribute) && !bootstrap_options.inline?)
15
+ check_box_html = tag.div(class: check_box_wrapper_classes(bootstrap)) do
16
+ concat(bootstrap_check_box(attribute, checked_value, options, bootstrap))
17
+ concat(help_text(attribute, bootstrap))
18
+ concat(generate_error(attribute)) if is_invalid?(attribute)
27
19
  end
28
20
 
29
- if (bootstrap_options.layout_horizontal? && !bootstrap_options.inline?)
30
- tag.div(class: field_wrapper_classes(bootstrap_options)) do
31
- tag.div(class: check_box_container_classes(bootstrap_options)) do
21
+ if bootstrap.wrapper
22
+ tag.div(**field_wrapper_options(bootstrap)) do
23
+ if bootstrap.layout_horizontal?
24
+ tag.div(class: check_box_container_classes(bootstrap)) { check_box_html }
25
+ else
32
26
  check_box_html
33
27
  end
34
28
  end
35
- elsif bootstrap_options.layout_inline?
36
- tag.div(class: "col-12") { check_box_html }
37
29
  else
38
30
  check_box_html
39
31
  end
@@ -9,30 +9,24 @@ module RailsBootstrapForm
9
9
 
10
10
  included do
11
11
  def collection_check_boxes(attribute, collection, value_method, text_method, options = {}, html_options = {})
12
- bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
13
- return super if bootstrap_options.disabled?
12
+ bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
13
+ return super if bootstrap.disabled?
14
14
 
15
- options[:multiple] = true
15
+ inputs = inputs_collection(attribute, collection, value_method, text_method, bootstrap, options) do |attribute, value, options|
16
+ bootstrap_opts = bootstrap_form_options.scoped(options.delete(:bootstrap))
16
17
 
17
- inputs = ActiveSupport::SafeBuffer.new
18
+ check_box_html = tag.div(class: check_box_wrapper_classes(bootstrap_opts)) do
19
+ bootstrap_check_box(attribute, value, options, bootstrap_opts)
20
+ end
18
21
 
19
- collection.each do |object|
20
- input_value = value_method.respond_to?(:call) ? value_method.call(object) : object.send(value_method)
21
- input_options = {
22
- bootstrap: {
23
- label_text: text_method.respond_to?(:call) ? text_method.call(object) : object.send(text_method),
24
- inline: true
25
- }
26
- }.deep_merge!(options)
27
-
28
- inputs << check_box(attribute, input_options, input_value, nil)
22
+ check_box_html
29
23
  end
30
24
 
31
25
  if options.delete(:include_hidden) { true }
32
26
  inputs.prepend(hidden_field(attribute, value: "", multiple: options[:multiple]))
33
27
  end
34
28
 
35
- field_wrapper_builder(attribute, bootstrap_options, options, html_options) do
29
+ field_wrapper_builder(attribute, bootstrap, options, html_options) do
36
30
  concat(tag.div(class: control_specific_class(:collection_check_boxes)) do
37
31
  concat(inputs)
38
32
  end)
@@ -9,28 +9,20 @@ module RailsBootstrapForm
9
9
 
10
10
  included do
11
11
  def collection_radio_buttons(attribute, collection, value_method, text_method, options = {}, html_options = {})
12
- bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
13
- return super if bootstrap_options.disabled?
12
+ bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
13
+ return super if bootstrap.disabled?
14
14
 
15
- inputs = ActiveSupport::SafeBuffer.new
15
+ inputs = inputs_collection(attribute, collection, value_method, text_method, bootstrap, options) do |attribute, value, options|
16
+ bootstrap_opts = bootstrap_form_options.scoped(options.delete(:bootstrap))
16
17
 
17
- collection.each do |object|
18
- input_value = value_method.respond_to?(:call) ? value_method.call(object) : object.send(value_method)
19
- input_options = {
20
- bootstrap: {
21
- label_text: text_method.respond_to?(:call) ? text_method.call(object) : object.send(text_method),
22
- inline: true
23
- }
24
- }.deep_merge!(options)
25
-
26
- if (checked = input_options[:checked])
27
- input_options[:checked] = collection_input_checked?(checked, object, object.send(value_method))
18
+ bootstrap_radio_html = tag.div(class: radio_button_wrapper_classes(bootstrap_opts)) do
19
+ bootstrap_radio_button(attribute, value, options, bootstrap_opts)
28
20
  end
29
21
 
30
- inputs << radio_button(attribute, input_value, input_options)
22
+ bootstrap_radio_html
31
23
  end
32
24
 
33
- field_wrapper_builder(attribute, bootstrap_options, options, html_options) do
25
+ field_wrapper_builder(attribute, bootstrap, options, html_options) do
34
26
  concat(tag.div(class: control_specific_class(:collection_radio_buttons)) do
35
27
  concat(inputs)
36
28
  end)
@@ -11,10 +11,10 @@ module RailsBootstrapForm
11
11
  def collection_select(attribute, collection, value_method, text_method, options = {}, html_options = {})
12
12
  options = {bootstrap: {field_class: "form-select"}}.deep_merge!(options)
13
13
 
14
- bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
- return super if bootstrap_options.disabled?
14
+ bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
+ return super if bootstrap.disabled?
16
16
 
17
- field_wrapper_builder(attribute, bootstrap_options, options, html_options) do
17
+ field_wrapper_builder(attribute, bootstrap, options, html_options) do
18
18
  super(attribute, collection, value_method, text_method, options, html_options)
19
19
  end
20
20
  end
@@ -11,10 +11,10 @@ module RailsBootstrapForm
11
11
  def color_field(attribute, options = {})
12
12
  options = {bootstrap: {field_class: "form-control form-control-color"}}.deep_merge!(options)
13
13
 
14
- bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
- return super if bootstrap_options.disabled?
14
+ bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
+ return super if bootstrap.disabled?
16
16
 
17
- field_wrapper_builder(attribute, bootstrap_options, options) do
17
+ field_wrapper_builder(attribute, bootstrap, options) do
18
18
  super(attribute, options)
19
19
  end
20
20
  end
@@ -11,10 +11,10 @@ module RailsBootstrapForm
11
11
  def grouped_collection_select(attribute, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {})
12
12
  options = {bootstrap: {field_class: "form-select"}}.deep_merge!(options)
13
13
 
14
- bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
- return super if bootstrap_options.disabled?
14
+ bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
+ return super if bootstrap.disabled?
16
16
 
17
- field_wrapper_builder(attribute, bootstrap_options, options, html_options) do
17
+ field_wrapper_builder(attribute, bootstrap, options, html_options) do
18
18
  super(attribute, collection, group_method, group_label_method, option_key_method, option_value_method, options, html_options)
19
19
  end
20
20
  end
@@ -9,31 +9,23 @@ module RailsBootstrapForm
9
9
 
10
10
  included do
11
11
  def radio_button(attribute, value, options = {})
12
- bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
13
- return super if bootstrap_options.disabled?
12
+ bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
13
+ return super if bootstrap.disabled?
14
14
 
15
- options[:class] = radio_button_classes(attribute, options)
16
-
17
- radio_button_field = super(attribute, value, options)
18
- radio_button_help_text = help_text(attribute, bootstrap_options)
19
-
20
- radio_button_label = radio_button_label(attribute, value, options, bootstrap_options)
21
-
22
- radio_button_html = tag.div(**radio_button_wrapper_options(bootstrap_options)) do
23
- concat(radio_button_field)
24
- concat(radio_button_label)
25
- concat(radio_button_help_text) unless bootstrap_options.inline?
26
- concat(generate_error(attribute)) if (is_invalid?(attribute) && !bootstrap_options.inline?)
15
+ radio_button_html = tag.div(class: radio_button_wrapper_classes(bootstrap)) do
16
+ concat(bootstrap_radio_button(attribute, value, options, bootstrap))
17
+ concat(help_text(attribute, bootstrap))
18
+ concat(generate_error(attribute)) if is_invalid?(attribute)
27
19
  end
28
20
 
29
- if (bootstrap_options.layout_horizontal? && !bootstrap_options.inline?)
30
- tag.div(class: field_wrapper_classes(bootstrap_options)) do
31
- tag.div(class: radio_button_container_classes(bootstrap_options)) do
21
+ if bootstrap.wrapper
22
+ tag.div(**field_wrapper_options(bootstrap)) do
23
+ if bootstrap.layout_horizontal?
24
+ tag.div(class: radio_button_container_classes(bootstrap)) { radio_button_html }
25
+ else
32
26
  radio_button_html
33
27
  end
34
28
  end
35
- elsif bootstrap_options.layout_inline?
36
- tag.div(class: "col-12") { radio_button_html }
37
29
  else
38
30
  radio_button_html
39
31
  end
@@ -11,10 +11,10 @@ module RailsBootstrapForm
11
11
  def range_field(attribute, options = {})
12
12
  options = {bootstrap: {field_class: "form-range"}}.deep_merge!(options)
13
13
 
14
- bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
- return super if bootstrap_options.disabled?
14
+ bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
+ return super if bootstrap.disabled?
16
16
 
17
- field_wrapper_builder(attribute, bootstrap_options, options) do
17
+ field_wrapper_builder(attribute, bootstrap, options) do
18
18
  super(attribute, options)
19
19
  end
20
20
  end
@@ -11,10 +11,10 @@ module RailsBootstrapForm
11
11
  def rich_text_area(attribute, options = {})
12
12
  options[:class] = ["trix-content", options[:class]].compact.join(" ")
13
13
 
14
- bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
- return super if bootstrap_options.disabled?
14
+ bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
+ return super if bootstrap.disabled?
16
16
 
17
- field_wrapper_builder(attribute, bootstrap_options, options) do
17
+ field_wrapper_builder(attribute, bootstrap, options) do
18
18
  super(attribute, options)
19
19
  end
20
20
  end
@@ -11,10 +11,10 @@ module RailsBootstrapForm
11
11
  def select(attribute, choices = nil, options = {}, html_options = {}, &block)
12
12
  options = {bootstrap: {field_class: "form-select"}}.deep_merge!(options)
13
13
 
14
- bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
- return super if bootstrap_options.disabled?
14
+ bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
+ return super if bootstrap.disabled?
16
16
 
17
- field_wrapper_builder(attribute, bootstrap_options, options, html_options) do
17
+ field_wrapper_builder(attribute, bootstrap, options, html_options) do
18
18
  super(attribute, choices, options, html_options, &block)
19
19
  end
20
20
  end
@@ -11,10 +11,10 @@ module RailsBootstrapForm
11
11
  def time_zone_select(attribute, priority_zones = nil, options = {}, html_options = {})
12
12
  options = {bootstrap: {field_class: "form-select"}}.deep_merge!(options)
13
13
 
14
- bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
- return super if bootstrap_options.disabled?
14
+ bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
+ return super if bootstrap.disabled?
16
16
 
17
- field_wrapper_builder(attribute, bootstrap_options, options, html_options) do
17
+ field_wrapper_builder(attribute, bootstrap, options, html_options) do
18
18
  super(attribute, priority_zones, options, html_options)
19
19
  end
20
20
  end
@@ -11,10 +11,10 @@ module RailsBootstrapForm
11
11
  def weekday_select(attribute, options = {}, html_options = {}, &block)
12
12
  options = {bootstrap: {field_class: "form-select"}}.deep_merge!(options)
13
13
 
14
- bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
- return super if bootstrap_options.disabled?
14
+ bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
+ return super if bootstrap.disabled?
16
16
 
17
- field_wrapper_builder(attribute, bootstrap_options, options, html_options) do
17
+ field_wrapper_builder(attribute, bootstrap, options, html_options) do
18
18
  super(attribute, options, html_options, &block)
19
19
  end
20
20
  end
@@ -3,6 +3,6 @@
3
3
  # -*- warn_indent: true -*-
4
4
 
5
5
  module RailsBootstrapForm
6
- VERSION = "0.9.0".freeze
6
+ VERSION = "0.9.2".freeze
7
7
  REQUIRED_RAILS_VERSION = "~> 7.0".freeze
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_bootstrap_form
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harshal LADHE (shivam091)
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-05-31 00:00:00.000000000 Z
11
+ date: 2023-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: generator_spec