rails_bootstrap_form 0.8.3 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +23 -1
  3. data/Gemfile.lock +1 -1
  4. data/README.md +75 -43
  5. data/demo/app/views/users/_horizontal_form.html.erb +8 -3
  6. data/demo/app/views/users/_inline_form.html.erb +1 -1
  7. data/demo/app/views/users/_vertical_form.html.erb +7 -2
  8. data/lib/rails_bootstrap_form/bootstrap_form_builder.rb +2 -2
  9. data/lib/rails_bootstrap_form/bootstrap_form_options.rb +16 -10
  10. data/lib/rails_bootstrap_form/field_wrapper_builder.rb +9 -7
  11. data/lib/rails_bootstrap_form/helpers/buttons.rb +1 -1
  12. data/lib/rails_bootstrap_form/helpers/check_box.rb +8 -4
  13. data/lib/rails_bootstrap_form/helpers/radio_button.rb +8 -4
  14. data/lib/rails_bootstrap_form/inputs/base.rb +35 -3
  15. data/lib/rails_bootstrap_form/inputs/check_box.rb +11 -14
  16. data/lib/rails_bootstrap_form/inputs/collection_check_boxes.rb +5 -14
  17. data/lib/rails_bootstrap_form/inputs/collection_radio_buttons.rb +5 -16
  18. data/lib/rails_bootstrap_form/inputs/collection_select.rb +5 -2
  19. data/lib/rails_bootstrap_form/inputs/color_field.rb +5 -2
  20. data/lib/rails_bootstrap_form/inputs/grouped_collection_select.rb +5 -2
  21. data/lib/rails_bootstrap_form/inputs/radio_button.rb +11 -14
  22. data/lib/rails_bootstrap_form/inputs/range_field.rb +5 -2
  23. data/lib/rails_bootstrap_form/inputs/rich_text_area.rb +4 -1
  24. data/lib/rails_bootstrap_form/inputs/select.rb +5 -2
  25. data/lib/rails_bootstrap_form/inputs/static_field.rb +1 -1
  26. data/lib/rails_bootstrap_form/inputs/time_zone_select.rb +5 -2
  27. data/lib/rails_bootstrap_form/inputs/weekday_select.rb +5 -2
  28. data/lib/rails_bootstrap_form/version.rb +1 -1
  29. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44eed939f6f6924e6ff02b2330cf0372a6efdbeb2a379b19fc8b3eb740c6dd3b
4
- data.tar.gz: b1600e611eaa19725e924b01136bddf59c385b046a744c4d7d97fb1a44d7123b
3
+ metadata.gz: 4cc018cfa787b152387078681629abadc1794699ef4151423db7fad244560be7
4
+ data.tar.gz: 4e932a41a3c992a79f766b868d04b655b4fb3aafabb08559caa8714189ac25d0
5
5
  SHA512:
6
- metadata.gz: 6641be855874886a07007ac392040b8cf82b3715315d2e072f20682f372df948fdfa66fe106075a928cb550fdfe7aba678f5d7135ad3993da8785c67642f99e9
7
- data.tar.gz: 303a8dc7b296790fab32aa5079a57f0e782898e1c4c2e53da450bb21020bf424c949a6432a77374fc7cfabf8d2ad43679ce50ad24ecfb2a3091239e4f02659c1
6
+ metadata.gz: 6738ad4f1381fe2ef85aa87e87b825ac0b0d96a3131f5727a5550361945cf99a9223fbed1b4018f139e89d39c9ab679df3a57b43e8e66dccfd1adb11af4610b6
7
+ data.tar.gz: c6e9250a1ea90b92398a2e3834450fbf6bdcc27f3ab8a5189c394795d53548caca48371f55e91b786bd9c2d05acb2702021d31b8a1fe5f6debaf9b1574611ced
data/CHANGELOG.md CHANGED
@@ -4,11 +4,33 @@ 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.1](https://github.com/shivam091/rails_bootstrap_form/compare/v0.9.0...v0.9.1) - 2023-06-
8
+
9
+ ### What's new
10
+
11
+ - Allow user to configure `options[:multiple]` for `collection_check_boxes`.
12
+ - Added option `inline` to control inline rendering of `collection_check_boxes` and `collection_radio_buttons`.
13
+
14
+ ### What's changed
15
+
16
+ - `wrapper[:class]` will now be appended to existing field wrapper CSS classes ([#29](https://github.com/shivam091/rails_bootstrap_form/issues/29))
17
+
18
+ ## [0.9.0](https://github.com/shivam091/rails_bootstrap_form/compare/v0.8.3...v0.9.0) - 2023-05-31
19
+
20
+ ### What's new
21
+
22
+ - Added `disabled` option to allow user to render default Rails form builder element.
23
+
24
+ ### BREAKING CHANGES
25
+
26
+ - Renamed `wrapper_options` option to `wrapper`
27
+ - Renamed `bootstrap_form` option to `bootstrap`
28
+
7
29
  ## [0.8.3](https://github.com/shivam091/rails_bootstrap_form/compare/v0.8.2...v0.8.3) - 2023-05-29
8
30
 
9
31
  ### What's new
10
32
 
11
- - Added support to specify `bootstrap_form` option on `fields_for` helper
33
+ - Added support to specify `bootstrap` option on `fields_for` helper ([#30](https://github.com/shivam091/rails_bootstrap_form/issues/30))
12
34
 
13
35
  ## [0.8.2](https://github.com/shivam091/rails_bootstrap_form/compare/v0.8.1...v0.8.2) - 2023-05-28
14
36
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails_bootstrap_form (0.8.3)
4
+ rails_bootstrap_form (0.9.1)
5
5
  actionpack (~> 7.0)
6
6
  activemodel (~> 7.0)
7
7
 
data/README.md CHANGED
@@ -150,10 +150,11 @@ This generates the following HTML:
150
150
 
151
151
  ## Bootstrap Configuration Options
152
152
 
153
- Here's a list of all possible options you can pass via `bootstrap_form` option that can be attached to the `bootstrap_form_for` or `bootstrap_form_with` or any field helpers inside of it:
153
+ Here's a list of all possible options you can pass via `bootstrap` option that can be attached to the `bootstrap_form_for` or `bootstrap_form_with` or any field helpers inside of it:
154
154
 
155
155
  | Option | Description | Default value |
156
156
  | ------ | ------------- | ----------- |
157
+ | `disabled` | An option to disable **rails_bootstrap_form** helpers. Default rails form builder element is rendered when set to `true` | `false` |
157
158
  | `layout` | Controls layout of form and field helpers. It can be `vertical` `horizontal`, or `inline`. | `vertical` |
158
159
  | `field_class` | A CSS class that will be applied to all form fields. | `form-control` |
159
160
  | `additional_field_class` | An additional CSS class that will be added along with the existing css classes of field helpers. | `nil` |
@@ -170,7 +171,7 @@ Here's a list of all possible options you can pass via `bootstrap_form` option t
170
171
  | `floating` | An option to control whether the field should have a floating label. | `false` |
171
172
  | `static_field_class` | A CSS class that will be applied to all static fields. | `form-control-plaintext` |
172
173
  | `switch` | An option to control whether the check box should look like Bootstrap switches. | `false` |
173
- | `wrapper_options` | An option to control the HTML attributes and options that will be added to a field wrapper. | `{}` |
174
+ | `wrapper` | An option to control the HTML attributes and options that will be added to a field wrapper. | `{}` |
174
175
  | `size` | An option to control the size of input groups, buttons, labels, and fields. It can be `sm` or `lg`. | `nil` |
175
176
  | `inline` | An option to group checkboxes and radio buttons on the same horizontal row. | `false` |
176
177
  | `label_col_class` | A CSS class that will be applied to all labels when layout is `horizontal`. | `col-form-label` |
@@ -187,7 +188,7 @@ Here's an example of a form where one field uses different layout:
187
188
  <%= bootstrap_form_for @user do |form| %>
188
189
  <%= form.text_field :name %>
189
190
  <%= form.email_field :email %>
190
- <%= form.password_field :password, bootstrap_form: {layout: :horizontal} %>
191
+ <%= form.password_field :password, bootstrap: {layout: :horizontal} %>
191
192
  <%= form.check_box :terms, required: true %>
192
193
  <%= form.primary "Register" %>
193
194
  <% end %>
@@ -221,6 +222,14 @@ This generates the following HTML:
221
222
  </form>
222
223
  ```
223
224
 
225
+ ### Disabling Bootstrap
226
+
227
+ You can completely disable bootstrap and use default form builder by passing `disabled: true` option. For example:
228
+
229
+ ```erb
230
+ <%= form.text_field :username, bootstrap: {disabled: true} %>
231
+ ```
232
+
224
233
  ## Supported Form Helpers
225
234
 
226
235
  This gem wraps most of the form field helpers. Here's the current list:
@@ -284,7 +293,7 @@ Here's an example of how it looks like by default:
284
293
  ![horizontal_layout](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/71493945-31d5-4917-83c2-8cb7b0825371)
285
294
 
286
295
  ```erb
287
- <%= bootstrap_form_for @user, bootstrap_form: {layout: :horizontal} do |form| %>
296
+ <%= bootstrap_form_for @user, bootstrap: {layout: :horizontal} do |form| %>
288
297
  <%= form.email_field :email %>
289
298
  <%= form.password_field :password %>
290
299
  <%= form.primary "Sign in" %>
@@ -315,9 +324,9 @@ The `label_col_wrapper_class` and `field_col_wrapper_class` css classes can also
315
324
  ![horizontal_form_custom_classes](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/ae5492f0-4a10-4f63-ae4d-9675bfb93226)
316
325
 
317
326
  ```erb
318
- <%= bootstrap_form_for @user, bootstrap_form: {layout: :horizontal} do |form| %>
327
+ <%= bootstrap_form_for @user, bootstrap: {layout: :horizontal} do |form| %>
319
328
  <%= form.text_field :name %>
320
- <%= form.email_field :username, bootstrap_form: {label_col_wrapper_class: "col-sm-2", field_col_wrapper_class: "col-sm-6"} %>
329
+ <%= form.email_field :username, bootstrap: {label_col_wrapper_class: "col-sm-2", field_col_wrapper_class: "col-sm-6"} %>
321
330
  <%= form.password_field :password %>
322
331
  <%= form.fields_for :address, include_id: false do |address_form| %>
323
332
  <%= address_form.select :country_id, options_for_select(::Country.pluck(:name, :id), address_form.object.country_id),
@@ -374,7 +383,7 @@ Here's an example of how it looks like:
374
383
  ![inline_layout](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/644a08ec-b249-4e1c-8d61-5350e6649f11)
375
384
 
376
385
  ```erb
377
- <%= bootstrap_form_for @user, bootstrap_form: {layout: :inline} do |form| %>
386
+ <%= bootstrap_form_for @user, bootstrap: {layout: :inline} do |form| %>
378
387
  <%= form.email_field :email %>
379
388
  <%= form.password_field :password %>
380
389
  <%= form.primary "Sign in" %>
@@ -411,7 +420,7 @@ generated by the Rails.
411
420
  ![label_text](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/b6378a06-c8e0-4944-8e0c-940a25964062)
412
421
 
413
422
  ```erb
414
- <%= form.password_field :password, bootstrap_form: {label_text: "New password"} %>
423
+ <%= form.password_field :password, bootstrap: {label_text: "New password"} %>
415
424
  ```
416
425
 
417
426
  This generates the following HTML:
@@ -429,7 +438,7 @@ to those using screen readers.
429
438
  ![hide_label](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/512a16b9-6829-40a2-bf07-f087970c9dac)
430
439
 
431
440
  ```erb
432
- <%= form.password_field :password, bootstrap_form: {hide_label: true} %>
441
+ <%= form.password_field :password, bootstrap: {hide_label: true} %>
433
442
  ```
434
443
 
435
444
  This generates the following HTML:
@@ -446,7 +455,7 @@ To skip a label, you can set `skip_label` option to `true`. This will not render
446
455
  ![skip_label](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/251e28ac-b98b-4e6a-8d55-8c0cb061e65a)
447
456
 
448
457
  ```erb
449
- <%= form.password_field :password, bootstrap_form: {skip_label: true} %>
458
+ <%= form.password_field :password, bootstrap: {skip_label: true} %>
450
459
  ```
451
460
 
452
461
  This generates the following HTML:
@@ -462,7 +471,7 @@ To add additional CSS class to the label, you can use `additional_label_class` o
462
471
  ![additional_label_class](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/b5ab4efe-2512-4ee4-9d35-99d3b7f78171)
463
472
 
464
473
  ```erb
465
- <%= form.password_field :password, bootstrap_form: {additional_label_class: "text-danger"} %>
474
+ <%= form.password_field :password, bootstrap: {additional_label_class: "text-danger"} %>
466
475
  ```
467
476
 
468
477
  This generates the following HTML:
@@ -508,7 +517,7 @@ You can customize the help text using `help_text` option:
508
517
  ![help_text](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/cdfe0e3c-6fcd-45a4-9621-9f0341925a1c)
509
518
 
510
519
  ```erb
511
- <%= form.password_field :password, bootstrap_form: {help_text: "Password should not be disclosed to anyone."} %>
520
+ <%= form.password_field :password, bootstrap: {help_text: "Password should not be disclosed to anyone."} %>
512
521
  ```
513
522
 
514
523
  This generates the following HTML:
@@ -547,7 +556,7 @@ You can use `prepend` and/or `append` options to attach addons to input fields:
547
556
  ![input_group_addon](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/e7fb8f52-558d-458d-a112-2ee3bab366db)
548
557
 
549
558
  ```erb
550
- <%= form.number_field :expected_ctc, bootstrap_form: {prepend: "₹", append: ".00"} %>
559
+ <%= form.number_field :expected_ctc, bootstrap: {prepend: "₹", append: ".00"} %>
551
560
  ```
552
561
 
553
562
  This generates the following HTML:
@@ -568,7 +577,7 @@ If you want to attach multiple addons to the input, pass them as an array:
568
577
  ![input_group_multiple_addons](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/8a6179c2-0def-428a-8429-c97db2c4a567)
569
578
 
570
579
  ```erb
571
- <%= form.number_field :expected_ctc, bootstrap_form: {prepend: ["Gross", "₹"], append: [".00", "per annum"]} %>
580
+ <%= form.number_field :expected_ctc, bootstrap: {prepend: ["Gross", "₹"], append: [".00", "per annum"]} %>
572
581
  ```
573
582
 
574
583
  This generates the following HTML:
@@ -591,7 +600,7 @@ You can also prepend and append buttons. Note that these buttons must contain th
591
600
  ![input_group_button](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/f0d1e22a-ca2b-42da-b99c-f3e7003d8c27)
592
601
 
593
602
  ```erb
594
- <%= form.text_field :search, bootstrap_form: {append: form.secondary("Search")} %>
603
+ <%= form.text_field :search, bootstrap: {append: form.secondary("Search")} %>
595
604
  ```
596
605
 
597
606
  This generates the following HTML:
@@ -611,7 +620,7 @@ To add additional CSS class to the input group wrapper, you can use `additional_
611
620
  ![additional_input_group_class](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/1814ec85-1efe-4ffc-ba87-c171d1b73e2c)
612
621
 
613
622
  ```erb
614
- <%= form.number_field :expected_ctc, bootstrap_form: {prepend: "₹", append: ".00", additional_input_group_class: "custom-class"} %>
623
+ <%= form.number_field :expected_ctc, bootstrap: {prepend: "₹", append: ".00", additional_input_group_class: "custom-class"} %>
615
624
  ```
616
625
 
617
626
  This generates the following HTML:
@@ -632,7 +641,7 @@ You can customize size of the input group using `size` option. Input group suppo
632
641
  ![input_group_size](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/b7236bd6-4dad-4142-b14e-f6325a612958)
633
642
 
634
643
  ```erb
635
- <%= form.number_field :expected_ctc, bootstrap_form: {prepend: "₹", append: ".00", size: :sm} %>
644
+ <%= form.number_field :expected_ctc, bootstrap: {prepend: "₹", append: ".00", size: :sm} %>
636
645
  ```
637
646
 
638
647
  This generates the following HTML:
@@ -651,7 +660,7 @@ This generates the following HTML:
651
660
  ## Form Helpers
652
661
 
653
662
  Our form helpers accept the same arguments as the default Rails form helpers.
654
- In order to apply addition options of `rails_bootstrap_form`, `bootstrap_form` object is passed in `options` argument of the helper.
663
+ In order to apply addition options of `rails_bootstrap_form`, `bootstrap` object is passed in `options` argument of the helper.
655
664
  Here's an example of how you pass the arguments for each form helper:
656
665
 
657
666
  ### check_box
@@ -680,7 +689,7 @@ You can set `switch` option to `true` if you want check box to look like switche
680
689
  ![check_box_switch](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/20c493ce-7f2c-4ac9-a854-e1520cae6a54)
681
690
 
682
691
  ```erb
683
- <%= form.check_box :remember_me, bootstrap_form: {switch: true} %>
692
+ <%= form.check_box :remember_me, bootstrap: {switch: true} %>
684
693
  ```
685
694
 
686
695
  This generates the following HTML:
@@ -811,23 +820,22 @@ This generates the following HTML:
811
820
 
812
821
  Our `fields_for` helper accepts the same arguments as the [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-fields_for).
813
822
 
814
- `rails_bootstrap_form` allows us to set `bootstrap_form` option just like `bootstrap_form_for` and `bootstrap_form_with`. By setting this option on fields_for, it applies to all the fields defined for that form:
823
+ `rails_bootstrap_form` allows us to set `bootstrap` option just like `bootstrap_form_for` and `bootstrap_form_with`. By setting this option on fields_for, it applies to all the fields defined for that form:
815
824
 
816
825
  ![fields_for](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/f515302f-a92a-4b5c-a444-af91cbb00dff)
817
826
 
818
827
  ```erb
819
828
  <%= bootstrap_form_for @user do |form| %>
820
829
  <%= form.email_field :email, autocomplete: "new-email" %>
821
- <%= form.password_field :password, autocomplete: "new-password", bootstrap_form: {layout: :horizontal} %>
830
+ <%= form.password_field :password, autocomplete: "new-password", bootstrap: {layout: :horizontal} %>
822
831
  <%= form.phone_field :mobile_number %>
823
- <%= form.fields_for :address, include_id: false, bootstrap_form: {layout: :horizontal} do |address_form| %>
832
+ <%= form.fields_for :address, include_id: false, bootstrap: {layout: :horizontal} do |address_form| %>
824
833
  <%= address_form.select :country_id, options_for_select(::Country.pluck(:name, :id), address_form.object.country_id),
825
834
  {include_blank: "Select Country"} %>
826
835
  <% end %>
827
836
  <%= form.check_box :terms, required: true %>
828
837
  <%= form.primary "Register" %>
829
838
  <% end %>
830
-
831
839
  ```
832
840
 
833
841
  This generates the following HTML:
@@ -874,12 +882,12 @@ This generates the following HTML:
874
882
  </form>
875
883
  ```
876
884
 
877
- By setting `bootstrap_form` option on `bootstrap_form_for` or `bootstrap_form_with`, this option also applies to all the fields defined in fields_for block:
885
+ By setting `bootstrap` option on `bootstrap_form_for` or `bootstrap_form_with`, this option also applies to all the fields defined in fields_for block:
878
886
 
879
887
  ![fields_for_horizontal](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/cb75e76b-e8a3-48f1-83a1-9eb150aa2466)
880
888
 
881
889
  ```erb
882
- <%= bootstrap_form_for @user, bootstrap_form: {layout: :horizontal} do |form| %>
890
+ <%= bootstrap_form_for @user, bootstrap: {layout: :horizontal} do |form| %>
883
891
  <%= form.email_field :email, autocomplete: "new-email" %>
884
892
  <%= form.password_field :password, autocomplete: "new-password" %>
885
893
  <%= form.phone_field :mobile_number %>
@@ -1051,7 +1059,7 @@ This helper will render check box and label for you.
1051
1059
  ![radio_button](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/9afa4065-6eea-44a6-a5be-d2936d1d2f9c)
1052
1060
 
1053
1061
  ```erb
1054
- <%= form.radio_button :gender, :male, bootstrap_form: {label_text: "Male"} %>
1062
+ <%= form.radio_button :gender, :male, bootstrap: {label_text: "Male"} %>
1055
1063
  ```
1056
1064
 
1057
1065
  This generates the following HTML:
@@ -1068,7 +1076,7 @@ This helper also renders help text if `help_text` option is set or information o
1068
1076
  ![radio_button_help_text](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/2409e822-c1bd-499b-b80f-e2948acf3403)
1069
1077
 
1070
1078
  ```erb
1071
- <%= form.radio_button :gender, :male, bootstrap_form: {label_text: "Male", help_text: "Please select your gender"} %>
1079
+ <%= form.radio_button :gender, :male, bootstrap: {label_text: "Male", help_text: "Please select your gender"} %>
1072
1080
  ```
1073
1081
 
1074
1082
  This generates the following HTML:
@@ -1236,7 +1244,7 @@ This generates the following HTML:
1236
1244
  ## Form Options Helpers
1237
1245
 
1238
1246
  Our form options helpers accept the same arguments as the default Rails form options helpers.
1239
- In order to apply addition options of `rails_bootstrap_form`, `bootstrap_form` object is passed in `options` argument of the helper.
1247
+ In order to apply addition options of `rails_bootstrap_form`, `bootstrap` object is passed in `options` argument of the helper.
1240
1248
  Here's an example of how you pass the arguments for each form option helper:
1241
1249
 
1242
1250
  ### select
@@ -1247,7 +1255,7 @@ Here's an example of how you pass both options and html_options hashes:
1247
1255
  ![select](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/e21f092c-d439-4817-bba1-8ec0c21330c1)
1248
1256
 
1249
1257
  ```erb
1250
- <%= form.select :fruit_id, options_for_select(::Fruit.pluck(:name, :id), form.object.fruit_id), {include_blank: "Select fruit", bootstrap_form: {size: :sm, help_text: false}}, {onchange: "this.form.submit();"} %>
1258
+ <%= form.select :fruit_id, options_for_select(::Fruit.pluck(:name, :id), form.object.fruit_id), {include_blank: "Select fruit", bootstrap: {size: :sm, help_text: false}}, {onchange: "this.form.submit();"} %>
1251
1259
  ```
1252
1260
 
1253
1261
  This generates the following HTML:
@@ -1273,7 +1281,7 @@ Here's an example of how you pass both options and html_options hashes:
1273
1281
  ![collection_select](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/c3a24265-81a9-4d1b-aa01-2b066d2f8bc7)
1274
1282
 
1275
1283
  ```erb
1276
- <%= form.collection_select :fruit_id, ::Fruit.all, :id, :name, {include_blank: "Select fruit", bootstrap_form: {help_text: false}}, {selected: form.object.fruit_id, onchange: "this.form.submit();"} %>
1284
+ <%= form.collection_select :fruit_id, ::Fruit.all, :id, :name, {include_blank: "Select fruit", bootstrap: {help_text: false}}, {selected: form.object.fruit_id, onchange: "this.form.submit();"} %>
1277
1285
  ```
1278
1286
 
1279
1287
  This generates the following HTML:
@@ -1299,7 +1307,7 @@ Here's an example of how you pass both options and html_options hashes:
1299
1307
  ![grouped_collection_select](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/d8f90065-3aa8-4d52-9c3e-0486324b3624)
1300
1308
 
1301
1309
  ```erb
1302
- <%= form.grouped_collection_select :city, ::Country.includes(:cities), :cities, :name, :id, :name, {include_blank: "Select city", bootstrap_form: {floating: true}}, {onchange: "this.form.submit();"} %>
1310
+ <%= form.grouped_collection_select :city, ::Country.includes(:cities), :cities, :name, :id, :name, {include_blank: "Select city", bootstrap: {floating: true}}, {onchange: "this.form.submit();"} %>
1303
1311
  ```
1304
1312
 
1305
1313
  This generates the following HTML:
@@ -1343,7 +1351,7 @@ Here's an example of how you pass both options and html_options hashes:
1343
1351
  ![time_zone_select](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/e161585c-1bbf-485c-9baf-c57b15258fe8)
1344
1352
 
1345
1353
  ```erb
1346
- <%= form.time_zone_select :timezone, ::ActiveSupport::TimeZone.all, {include_blank: "Select time zone", bootstrap_form: {label_text: "Preferred time zone"}}, {onchange: "this.form.submit();"} %>
1354
+ <%= form.time_zone_select :timezone, ::ActiveSupport::TimeZone.all, {include_blank: "Select time zone", bootstrap: {label_text: "Preferred time zone"}}, {onchange: "this.form.submit();"} %>
1347
1355
  ```
1348
1356
 
1349
1357
  This generates the following HTML:
@@ -1375,7 +1383,7 @@ Here's an example of how you pass both options and html_options hashes:
1375
1383
  ![weekday_select](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/e469a57d-3d22-4c9e-829b-4ba825593ae1)
1376
1384
 
1377
1385
  ```erb
1378
- <%= form.weekday_select :weekly_off, {selected: "Monday", bootstrap_form: {label_text: "Week off"}}, {onchange: "this.form.submit();} %>
1386
+ <%= form.weekday_select :weekly_off, {selected: "Monday", bootstrap: {label_text: "Week off"}}, {onchange: "this.form.submit();"} %>
1379
1387
  ```
1380
1388
 
1381
1389
  This generates the following HTML:
@@ -1403,7 +1411,7 @@ an argument and takes care of rendering labels, check boxes, and wrapper for you
1403
1411
  ![collection_check_boxes](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/c92f5921-e572-4384-812e-31308e018f66)
1404
1412
 
1405
1413
  ```erb
1406
- <%= form.collection_check_boxes :skill_ids, ::Skill.all, :id, :name, {bootstrap_form: {layout: :horizontal}, onchange: "this.form.submit();"}, {} %>
1414
+ <%= form.collection_check_boxes :skill_ids, ::Skill.all, :id, :name, {bootstrap: {layout: :horizontal, inline: true}, onchange: "this.form.submit();"}, {} %>
1407
1415
  ```
1408
1416
 
1409
1417
  This generates the following HTML:
@@ -1468,7 +1476,7 @@ an argument and takes care of rendering labels, radio button, and wrapper for yo
1468
1476
  ![collection_radio_buttons](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/798a8b0c-915a-40b1-9874-dd74f50d3695)
1469
1477
 
1470
1478
  ```erb
1471
- <%= form.collection_radio_buttons :fruit_id, ::Fruit.all, :id, :name, {checked: form.object.fruit_id, bootstrap_form: {layout: :horizontal}}, {} %>
1479
+ <%= form.collection_radio_buttons :fruit_id, ::Fruit.all, :id, :name, {checked: form.object.fruit_id, bootstrap: {layout: :horizontal, inline: true}}, {} %>
1472
1480
  ```
1473
1481
 
1474
1482
  This generates the following HTML:
@@ -1504,7 +1512,7 @@ This generates the following HTML:
1504
1512
 
1505
1513
  The multiple selects that the date and time helpers (`date_select`, `time_select`, `datetime_select`) generate are wrapped inside a `fieldset.rails-bootstrap-forms-[date|time|datetime]-select` tag.
1506
1514
  This is because Bootstrap automatically styles our controls as blocks. This wrapper fixes this defining these selects as `inline-block` and a width of `auto`.
1507
- In order to apply addition options of `rails_bootstrap_form`, `bootstrap_form` object is passed in `options` argument of the helper.
1515
+ In order to apply addition options of `rails_bootstrap_form`, `bootstrap` object is passed in `options` argument of the helper.
1508
1516
 
1509
1517
  ### date_select
1510
1518
 
@@ -1514,7 +1522,7 @@ Here's an example of how you pass both options and html_options hashes:
1514
1522
  ![date_select](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/45fe5d72-43da-498e-a1c2-ac6729446bba)
1515
1523
 
1516
1524
  ```erb
1517
- <%= form.date_select :interview_date, {selected: form.object.interview_date, bootstrap_form: {label_text: "Choose interview date"}}, {onchange: "this.form.submit();"} %>
1525
+ <%= form.date_select :interview_date, {selected: form.object.interview_date, bootstrap: {label_text: "Choose interview date"}}, {onchange: "this.form.submit();"} %>
1518
1526
  ```
1519
1527
 
1520
1528
  This generates the following HTML:
@@ -1566,7 +1574,7 @@ Here's an example of how you pass both options and html_options hashes:
1566
1574
  ![time_select](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/2195922c-c7cc-48dc-9912-3ef3cbb8e017)
1567
1575
 
1568
1576
  ```erb
1569
- <%= form.time_select :interview_time, {selected: form.object.interview_time, bootstrap_form: {label_text: "Choose interview time"}}, {onchange: "this.form.submit();"} %>
1577
+ <%= form.time_select :interview_time, {selected: form.object.interview_time, bootstrap: {label_text: "Choose interview time"}}, {onchange: "this.form.submit();"} %>
1570
1578
  ```
1571
1579
 
1572
1580
  This generates the following HTML:
@@ -1610,7 +1618,7 @@ Here's an example of how you pass both options and html_options hashes:
1610
1618
  ![datetime_select](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/c0e0cd83-d44a-4308-bfa9-e25a2a488d66)
1611
1619
 
1612
1620
  ```erb
1613
- <%= form.datetime_select :interview_datetime, {selected: form.object.interview_datetime, bootstrap_form: {label_text: "Choose interview date & time"}}, {onchange: "this.form.submit();"} %>
1621
+ <%= form.datetime_select :interview_datetime, {selected: form.object.interview_datetime, bootstrap: {label_text: "Choose interview date & time"}}, {onchange: "this.form.submit();"} %>
1614
1622
  ```
1615
1623
 
1616
1624
  This generates the following HTML:
@@ -1710,7 +1718,7 @@ To render submit helper as a button helper, you can set `render_as_button` optio
1710
1718
  ![render_as_button](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/dffd72d8-3acf-4029-be04-3bf7776e8d9c)
1711
1719
 
1712
1720
  ```erb
1713
- <%= form.primary "Register", bootstrap_form: {render_as_button: true} %>
1721
+ <%= form.primary "Register", bootstrap: {render_as_button: true} %>
1714
1722
  <%= form.secondary do %>
1715
1723
  Sign in
1716
1724
  <% end %>
@@ -1755,7 +1763,7 @@ The `floating` option can be used to enable Bootstrap floating labels. This opti
1755
1763
  ![floating_labels](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/3976629d-4717-47b0-ab91-9a16e6c9ed5f)
1756
1764
 
1757
1765
  ```erb
1758
- <%= bootstrap_form_for @user, bootstrap_form: {floating: true} do |form| %>
1766
+ <%= bootstrap_form_for @user, bootstrap: {floating: true} do |form| %>
1759
1767
  <%= form.text_field :name %>
1760
1768
  <%= form.email_field :username %>
1761
1769
  <%= form.password_field :password %>
@@ -1849,6 +1857,30 @@ This generates the following HTML:
1849
1857
  </form>
1850
1858
  ```
1851
1859
 
1860
+ Inline errors are also supported if the field is wrapped inside of input group and has floating label:
1861
+
1862
+ ![floating_inline_errors](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/89deb618-3f06-463b-91fb-60c50794387c)
1863
+
1864
+ ```erb
1865
+ <%= form.text_field :expected_ctc, bootstrap: {floating: true, prepend: "$", append: "0.0"} %>
1866
+ ```
1867
+
1868
+ This generates the following HTML:
1869
+
1870
+ ```html
1871
+ <div class="mb-3">
1872
+ <div class="input-group has-validation">
1873
+ <span class="input-group-text">$</span>
1874
+ <div class="form-floating is-invalid">
1875
+ <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">
1876
+ <label class="form-label required is-invalid" for="user_expected_ctc">Expected CTC</label>
1877
+ </div>
1878
+ <span class="input-group-text">0.0</span>
1879
+ <div class="invalid-feedback">can't be blank</div>
1880
+ </div>
1881
+ </div>
1882
+ ```
1883
+
1852
1884
  ## Required Fields
1853
1885
 
1854
1886
  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.
@@ -1928,13 +1960,13 @@ Some third party plug-ins require an empty but visible label on an input control
1928
1960
  The solution is to use a zero-width character for the label, or some other "empty" HTML. For example:
1929
1961
 
1930
1962
  ```erb
1931
- bootstrap_form: {label_text: "&#8203;".html_safe}
1963
+ bootstrap: {label_text: "&#8203;".html_safe}
1932
1964
  ```
1933
1965
 
1934
1966
  or
1935
1967
 
1936
1968
  ```erb
1937
- bootstrap_form: {label_text: "<span></span>".html_safe}
1969
+ bootstrap: {label_text: "<span></span>".html_safe}
1938
1970
  ```
1939
1971
 
1940
1972
  ## Contributing
@@ -3,7 +3,7 @@
3
3
  Horizontal layout
4
4
  </div>
5
5
  <div class="card-body">
6
- <%= bootstrap_form_for @user, bootstrap_form: {layout: :horizontal} do |form| %>
6
+ <%= bootstrap_form_for @user, bootstrap: {layout: :horizontal} do |form| %>
7
7
  <%= form.text_field :name, autocomplete: "new-name" %>
8
8
  <%= form.text_field :username, autocomplete: "new-username" %>
9
9
  <%= form.email_field :email, autocomplete: "new-email" %>
@@ -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 %>
@@ -3,7 +3,7 @@
3
3
  Inline layout
4
4
  </div>
5
5
  <div class="card-body">
6
- <%= bootstrap_form_for @user, bootstrap_form: {layout: :inline} do |form| %>
6
+ <%= bootstrap_form_for @user, bootstrap: {layout: :inline} do |form| %>
7
7
  <%= form.text_field :username, autocomplete: "new-username" %>
8
8
  <%= form.password_field :password, autocomplete: "new-password" %>
9
9
  <%= form.check_box :remember_me %>
@@ -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 %>
@@ -15,7 +15,7 @@ module RailsBootstrapForm
15
15
  attr_accessor :bootstrap_form_options
16
16
 
17
17
  def initialize(object_name, object, template, options)
18
- @bootstrap_form_options = RailsBootstrapForm::BootstrapFormOptions.new(options[:bootstrap_form])
18
+ @bootstrap_form_options = RailsBootstrapForm::BootstrapFormOptions.new(options[:bootstrap])
19
19
  apply_default_form_options(options)
20
20
  apply_default_form_classes(options)
21
21
  super(object_name, object, template, options)
@@ -42,7 +42,7 @@ module RailsBootstrapForm
42
42
 
43
43
  def fields_for_options(record_object, fields_options)
44
44
  fields_options = record_object if record_object.is_a?(Hash) && record_object.extractable_options?
45
- bootstrap_options = {bootstrap_form: options.fetch(:bootstrap_form, {})}
45
+ bootstrap_options = {bootstrap: options.fetch(:bootstrap, {})}
46
46
  fields_options = bootstrap_options.deep_merge!(fields_options)
47
47
  fields_options
48
48
  end
@@ -6,16 +6,20 @@ module RailsBootstrapForm
6
6
  # Container for bootstrap specific form builder options. It controls options
7
7
  # that define form layout, grid sizing, and few other configurable options.
8
8
  # They are passed-in into form builder helper and field helpers via
9
- # `:bootstrap_form` option.
9
+ # `:bootstrap` option.
10
10
  #
11
11
  # For example:
12
12
  #
13
- # bootstrap_form_with model: @user, bootstrap_form: {layout: :inline} do |f|
14
- # f.text_field :email, bootstrap_form: {label: {text: "Your email"}}
13
+ # bootstrap_form_with model: @user, bootstrap: {layout: :inline} do |f|
14
+ # f.text_field :email, bootstrap: {label: {text: "Your email"}}
15
15
  # end
16
16
  #
17
17
  class BootstrapFormOptions
18
18
 
19
+ # Controls whether to render default Rails form builder element.
20
+ # The default value is `false`.
21
+ attr_accessor :disabled
22
+
19
23
  # Controls layout of form and field helpers. It can be "vertical,
20
24
  # "horizontal", or "inline". The default value is `vertical`.
21
25
  attr_accessor :layout
@@ -64,8 +68,8 @@ module RailsBootstrapForm
64
68
  #
65
69
  # Example:
66
70
  #
67
- # form.text_field :dollars, bootstrap_form: {input_group: {prepend: "$", append: ".00"}}
68
- # form.text_field :search, bootstrap_form: {input_group: {append: button_tag("Go", type: :submit, class: "btn btn-secondary")}}
71
+ # form.text_field :dollars, bootstrap: {input_group: {prepend: "$", append: ".00"}}
72
+ # form.text_field :search, bootstrap: {input_group: {append: button_tag("Go", type: :submit, class: "btn btn-secondary")}}
69
73
  #
70
74
  # Raw or HTML content to be prepended to the field.
71
75
  # The default value is `nil`.
@@ -93,7 +97,7 @@ module RailsBootstrapForm
93
97
 
94
98
  # An option to control the HTML attributes and options that will be added to
95
99
  # the field wrapper. The default value is `{}`.
96
- attr_accessor :wrapper_options
100
+ attr_accessor :wrapper
97
101
 
98
102
  # An option to control the size of input groups, buttons, labels, and fields.
99
103
  # The valid values are `sm` and `lg`. The default value is `nil`.
@@ -103,7 +107,7 @@ module RailsBootstrapForm
103
107
  # The default value is `false`.
104
108
  #
105
109
  # Example:
106
- # form.collection_radio_buttons :choices, ["yes", "no"], :to_s, :to_s, bootstrap_form: {inline: true}
110
+ # form.collection_radio_buttons :choices, ["yes", "no"], :to_s, :to_s, bootstrap: {inline: true}
107
111
  attr_accessor :inline
108
112
 
109
113
  # A CSS class that will be applied to all labels when layout is horizontal.
@@ -145,7 +149,7 @@ module RailsBootstrapForm
145
149
  # to a given form field. For example, we can change grid just for one field:
146
150
  #
147
151
  # bootstrap_form_with model: @user do |f|
148
- # f.text_field :email, bootstrap_form: {label_col_wrapper_class: "col-md-6", field_col_wrapper_class: "col-md-6"}
152
+ # f.text_field :email, bootstrap: {label_col_wrapper_class: "col-md-6", field_col_wrapper_class: "col-md-6"}
149
153
  # f.password_field :password
150
154
  # end
151
155
  #
@@ -161,11 +165,13 @@ module RailsBootstrapForm
161
165
  end
162
166
  end
163
167
 
164
- %i(inline floating switch skip_label hide_label render_as_button).each do |method|
168
+ %i(disabled inline floating switch skip_label hide_label render_as_button).each do |method|
165
169
  define_method("#{method}?") { self.send(method) }
166
170
  end
167
171
 
168
172
  def set_defaults
173
+ @disabled = false
174
+
169
175
  @layout = "vertical"
170
176
 
171
177
  @field_class = "form-control"
@@ -190,7 +196,7 @@ module RailsBootstrapForm
190
196
 
191
197
  @switch = false
192
198
 
193
- @wrapper_options = {}
199
+ @wrapper = {}
194
200
 
195
201
  @size = nil
196
202
 
@@ -4,9 +4,7 @@
4
4
 
5
5
  module RailsBootstrapForm
6
6
  module FieldWrapperBuilder
7
- def field_wrapper_builder(attribute, options, html_options = nil, &block)
8
- bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap_form))
9
-
7
+ def field_wrapper_builder(attribute, bootstrap_options, options, html_options = nil, &block)
10
8
  field_options = field_css_options(attribute, bootstrap_options, options, html_options.try(:symbolize_keys!))
11
9
 
12
10
  field_wrapper(attribute, bootstrap_options, field_options, &block)
@@ -50,19 +48,23 @@ module RailsBootstrapForm
50
48
  end
51
49
 
52
50
  def field_wrapper_options(bootstrap_options)
51
+ wrapper_options = bootstrap_options.wrapper
52
+
53
53
  {}.tap do |option|
54
54
  option[:class] = field_wrapper_classes(bootstrap_options)
55
- end.merge(bootstrap_options.wrapper_options)
55
+ option.merge!(wrapper_options.except(:class)) if wrapper_options.is_a?(Hash)
56
+ end
56
57
  end
57
58
 
58
59
  def field_wrapper_classes(bootstrap_options)
59
60
  classes = []
60
61
  classes << "row" if bootstrap_options.layout_horizontal?
61
- classes << form_wrapper_default_class(bootstrap_options)
62
+ classes << field_wrapper_default_class(bootstrap_options)
63
+ classes << bootstrap_options.wrapper[:class]
62
64
  classes.flatten.compact
63
65
  end
64
66
 
65
- def form_wrapper_default_class(bootstrap_options)
67
+ def field_wrapper_default_class(bootstrap_options)
66
68
  bootstrap_options.layout_inline? ? "col-12" : "mb-3"
67
69
  end
68
70
 
@@ -101,7 +103,7 @@ module RailsBootstrapForm
101
103
  (bootstrap_options.floating? && !bootstrap_options.layout_horizontal?) || bootstrap_options.layout_inline?
102
104
  end
103
105
 
104
- private :field_wrapper, :field_wrapper_classes, :form_wrapper_default_class,
106
+ private :field_wrapper, :field_wrapper_classes, :field_wrapper_default_class,
105
107
  :field_css_options, :floating_label_classes
106
108
  end
107
109
  end
@@ -10,7 +10,7 @@ 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_form))
13
+ bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
14
14
 
15
15
  button_html = if (bootstrap_options.render_as_button? || block)
16
16
  button(value, options, &block)
@@ -28,9 +28,12 @@ module RailsBootstrapForm
28
28
  end
29
29
 
30
30
  def check_box_wrapper_options(bootstrap_options)
31
+ wrapper_options = bootstrap_options.wrapper
32
+
31
33
  {}.tap do |option|
32
- option[:class] = check_box_wrapper_class(bootstrap_options)
33
- end.merge(bootstrap_options.wrapper_options)
34
+ option[:class] = check_box_wrapper_classes(bootstrap_options)
35
+ option.merge!(wrapper_options.except(:class)) if wrapper_options.is_a?(Hash)
36
+ end
34
37
  end
35
38
 
36
39
  def check_box_label_text(attribute, options, bootstrap_options, &block)
@@ -58,13 +61,14 @@ module RailsBootstrapForm
58
61
  classes.flatten.compact
59
62
  end
60
63
 
61
- def check_box_wrapper_class(bootstrap_options)
64
+ def check_box_wrapper_classes(bootstrap_options)
62
65
  classes = Array("form-check")
63
66
  classes << "form-switch" if bootstrap_options.switch?
64
67
  classes << "form-check-inline" if bootstrap_options.inline?
65
68
  if (bootstrap_options.layout_vertical? && !bootstrap_options.inline?)
66
69
  classes << "mb-3"
67
70
  end
71
+ classes << bootstrap_options.wrapper[:class]
68
72
  classes.flatten.compact
69
73
  end
70
74
 
@@ -75,7 +79,7 @@ module RailsBootstrapForm
75
79
  end
76
80
 
77
81
  private :check_box_label, :check_box_classes, :check_box_label_class,
78
- :check_box_wrapper_class, :check_box_container_classes
82
+ :check_box_wrapper_classes, :check_box_container_classes
79
83
  end
80
84
  end
81
85
  end
@@ -29,9 +29,12 @@ module RailsBootstrapForm
29
29
  end
30
30
 
31
31
  def radio_button_wrapper_options(bootstrap_options)
32
+ wrapper_options = bootstrap_options.wrapper
33
+
32
34
  {}.tap do |option|
33
- option[:class] = radio_button_wrapper_class(bootstrap_options)
34
- end.merge(bootstrap_options.wrapper_options)
35
+ option[:class] = radio_button_wrapper_classes(bootstrap_options)
36
+ option.merge!(wrapper_options.except(:class)) if wrapper_options.is_a?(Hash)
37
+ end
35
38
  end
36
39
 
37
40
  def radio_button_value(attribute, value)
@@ -55,12 +58,13 @@ module RailsBootstrapForm
55
58
  classes.flatten.compact
56
59
  end
57
60
 
58
- def radio_button_wrapper_class(bootstrap_options)
61
+ def radio_button_wrapper_classes(bootstrap_options)
59
62
  classes = Array("form-check")
60
63
  classes << "form-check-inline" if bootstrap_options.inline?
61
64
  if (bootstrap_options.layout_vertical? && !bootstrap_options.inline?)
62
65
  classes << "mb-3"
63
66
  end
67
+ classes << bootstrap_options.wrapper[:class]
64
68
  classes.flatten.compact
65
69
  end
66
70
 
@@ -71,7 +75,7 @@ module RailsBootstrapForm
71
75
  end
72
76
 
73
77
  private :radio_button_label, :radio_button_classes, :radio_button_label_class,
74
- :radio_button_wrapper_class, :radio_button_container_classes
78
+ :radio_button_wrapper_classes, :radio_button_container_classes
75
79
  end
76
80
  end
77
81
  end
@@ -7,10 +7,39 @@ 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, options = {})
12
+ inputs = ActiveSupport::SafeBuffer.new
13
+
14
+ collection.each do |object|
15
+ input_options = {
16
+ bootstrap: {
17
+ label_text: text_method.respond_to?(:call) ? text_method.call(object) : object.send(text_method),
18
+ help_text: false,
19
+ inline: bootstrap_options.inline?
20
+ }
21
+ }.deep_merge!(options)
22
+
23
+ if (checked = input_options[:checked])
24
+ input_options[:checked] = collection_input_checked?(checked, object, object.send(value_method))
25
+ end
26
+
27
+ input_value = value_method.respond_to?(:call) ? value_method.call(object) : object.send(value_method)
28
+
29
+ inputs << yield(attribute, input_value, input_options)
30
+ end
31
+
32
+ inputs
33
+ end
34
+ end
35
+
10
36
  class_methods do
11
37
  def bootstrap_field(field_name)
12
38
  define_method(field_name) do |attribute, options = {}|
13
- field_wrapper_builder(attribute, options) do
39
+ bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
40
+ return super(attribute, options) if bootstrap_options.disabled?
41
+
42
+ field_wrapper_builder(attribute, bootstrap_options, options) do
14
43
  super(attribute, options)
15
44
  end
16
45
  end
@@ -18,9 +47,12 @@ module RailsBootstrapForm
18
47
 
19
48
  def bootstrap_select_group(field_name)
20
49
  define_method(field_name) do |attribute, options = {}, html_options = {}|
21
- options = {bootstrap_form: {field_class: "form-select"}}.deep_merge!(options)
50
+ options = {bootstrap: {field_class: "form-select"}}.deep_merge!(options)
51
+
52
+ bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
53
+ return super(attribute, options, html_options) if bootstrap_options.disabled?
22
54
 
23
- field_wrapper_builder(attribute, options, html_options) do
55
+ field_wrapper_builder(attribute, bootstrap_options, options, html_options) do
24
56
  tag.fieldset(class: control_specific_class(field_name)) do
25
57
  super(attribute, options, html_options)
26
58
  end
@@ -9,7 +9,8 @@ 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_form))
12
+ bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
13
+ return super if bootstrap_options.disabled?
13
14
 
14
15
  options[:class] = check_box_classes(attribute, options)
15
16
 
@@ -21,24 +22,20 @@ module RailsBootstrapForm
21
22
  check_box_html = tag.div(**check_box_wrapper_options(bootstrap_options)) do
22
23
  concat(check_box_field)
23
24
  concat(check_box_label)
24
- concat(check_box_help_text) unless bootstrap_options.inline?
25
+ concat(check_box_help_text)
25
26
  concat(generate_error(attribute)) if (is_invalid?(attribute) && !bootstrap_options.inline?)
26
27
  end
27
28
 
28
- if bootstrap_options.inline?
29
- check_box_html
30
- else
31
- if bootstrap_options.layout_horizontal?
32
- tag.div(class: field_wrapper_classes(bootstrap_options)) do
33
- tag.div(class: check_box_container_classes(bootstrap_options)) do
34
- check_box_html
35
- end
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
32
+ check_box_html
36
33
  end
37
- elsif bootstrap_options.layout_inline?
38
- tag.div(class: "col-12") { check_box_html }
39
- else
40
- check_box_html
41
34
  end
35
+ elsif bootstrap_options.layout_inline?
36
+ tag.div(class: "col-12") { check_box_html }
37
+ else
38
+ check_box_html
42
39
  end
43
40
  end
44
41
  end
@@ -9,27 +9,18 @@ module RailsBootstrapForm
9
9
 
10
10
  included do
11
11
  def collection_check_boxes(attribute, collection, value_method, text_method, options = {}, html_options = {})
12
- options[:multiple] = true
12
+ bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
13
+ return super if bootstrap_options.disabled?
13
14
 
14
- inputs = ActiveSupport::SafeBuffer.new
15
-
16
- collection.each do |object|
17
- input_value = value_method.respond_to?(:call) ? value_method.call(object) : object.send(value_method)
18
- input_options = {
19
- bootstrap_form: {
20
- label_text: text_method.respond_to?(:call) ? text_method.call(object) : object.send(text_method),
21
- inline: true
22
- }
23
- }.deep_merge!(options)
24
-
25
- inputs << check_box(attribute, input_options, input_value, nil)
15
+ inputs = inputs_collection(attribute, collection, value_method, text_method, bootstrap_options, options) do |attribute, value, options|
16
+ check_box(attribute, options, value, nil)
26
17
  end
27
18
 
28
19
  if options.delete(:include_hidden) { true }
29
20
  inputs.prepend(hidden_field(attribute, value: "", multiple: options[:multiple]))
30
21
  end
31
22
 
32
- field_wrapper_builder(attribute, options, html_options) do
23
+ field_wrapper_builder(attribute, bootstrap_options, options, html_options) do
33
24
  concat(tag.div(class: control_specific_class(:collection_check_boxes)) do
34
25
  concat(inputs)
35
26
  end)
@@ -9,25 +9,14 @@ module RailsBootstrapForm
9
9
 
10
10
  included do
11
11
  def collection_radio_buttons(attribute, collection, value_method, text_method, options = {}, html_options = {})
12
- inputs = ActiveSupport::SafeBuffer.new
12
+ bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
13
+ return super if bootstrap_options.disabled?
13
14
 
14
- collection.each do |object|
15
- input_value = value_method.respond_to?(:call) ? value_method.call(object) : object.send(value_method)
16
- input_options = {
17
- bootstrap_form: {
18
- label_text: text_method.respond_to?(:call) ? text_method.call(object) : object.send(text_method),
19
- inline: true
20
- }
21
- }.deep_merge!(options)
22
-
23
- if (checked = input_options[:checked])
24
- input_options[:checked] = collection_input_checked?(checked, object, object.send(value_method))
25
- end
26
-
27
- inputs << radio_button(attribute, input_value, input_options)
15
+ inputs = inputs_collection(attribute, collection, value_method, text_method, bootstrap_options, options) do |attribute, value, options|
16
+ radio_button(attribute, value, options)
28
17
  end
29
18
 
30
- field_wrapper_builder(attribute, options, html_options) do
19
+ field_wrapper_builder(attribute, bootstrap_options, options, html_options) do
31
20
  concat(tag.div(class: control_specific_class(:collection_radio_buttons)) do
32
21
  concat(inputs)
33
22
  end)
@@ -9,9 +9,12 @@ module RailsBootstrapForm
9
9
 
10
10
  included do
11
11
  def collection_select(attribute, collection, value_method, text_method, options = {}, html_options = {})
12
- options = {bootstrap_form: {field_class: "form-select"}}.deep_merge!(options)
12
+ options = {bootstrap: {field_class: "form-select"}}.deep_merge!(options)
13
13
 
14
- field_wrapper_builder(attribute, options, html_options) do
14
+ bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
+ return super if bootstrap_options.disabled?
16
+
17
+ field_wrapper_builder(attribute, bootstrap_options, options, html_options) do
15
18
  super(attribute, collection, value_method, text_method, options, html_options)
16
19
  end
17
20
  end
@@ -9,9 +9,12 @@ module RailsBootstrapForm
9
9
 
10
10
  included do
11
11
  def color_field(attribute, options = {})
12
- options = {bootstrap_form: {field_class: "form-control form-control-color"}}.deep_merge!(options)
12
+ options = {bootstrap: {field_class: "form-control form-control-color"}}.deep_merge!(options)
13
13
 
14
- field_wrapper_builder(attribute, options) do
14
+ bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
+ return super if bootstrap_options.disabled?
16
+
17
+ field_wrapper_builder(attribute, bootstrap_options, options) do
15
18
  super(attribute, options)
16
19
  end
17
20
  end
@@ -9,9 +9,12 @@ module RailsBootstrapForm
9
9
 
10
10
  included do
11
11
  def grouped_collection_select(attribute, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {})
12
- options = {bootstrap_form: {field_class: "form-select"}}.deep_merge!(options)
12
+ options = {bootstrap: {field_class: "form-select"}}.deep_merge!(options)
13
13
 
14
- field_wrapper_builder(attribute, options, html_options) do
14
+ bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
+ return super if bootstrap_options.disabled?
16
+
17
+ field_wrapper_builder(attribute, bootstrap_options, options, html_options) do
15
18
  super(attribute, collection, group_method, group_label_method, option_key_method, option_value_method, options, html_options)
16
19
  end
17
20
  end
@@ -9,7 +9,8 @@ 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_form))
12
+ bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
13
+ return super if bootstrap_options.disabled?
13
14
 
14
15
  options[:class] = radio_button_classes(attribute, options)
15
16
 
@@ -21,24 +22,20 @@ module RailsBootstrapForm
21
22
  radio_button_html = tag.div(**radio_button_wrapper_options(bootstrap_options)) do
22
23
  concat(radio_button_field)
23
24
  concat(radio_button_label)
24
- concat(radio_button_help_text) unless bootstrap_options.inline?
25
+ concat(radio_button_help_text)
25
26
  concat(generate_error(attribute)) if (is_invalid?(attribute) && !bootstrap_options.inline?)
26
27
  end
27
28
 
28
- if bootstrap_options.inline?
29
- radio_button_html
30
- else
31
- if bootstrap_options.layout_horizontal?
32
- tag.div(class: field_wrapper_classes(bootstrap_options)) do
33
- tag.div(class: radio_button_container_classes(bootstrap_options)) do
34
- radio_button_html
35
- end
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
32
+ radio_button_html
36
33
  end
37
- elsif bootstrap_options.layout_inline?
38
- tag.div(class: "col-12") { radio_button_html }
39
- else
40
- radio_button_html
41
34
  end
35
+ elsif bootstrap_options.layout_inline?
36
+ tag.div(class: "col-12") { radio_button_html }
37
+ else
38
+ radio_button_html
42
39
  end
43
40
  end
44
41
  end
@@ -9,9 +9,12 @@ module RailsBootstrapForm
9
9
 
10
10
  included do
11
11
  def range_field(attribute, options = {})
12
- options = {bootstrap_form: {field_class: "form-range"}}.deep_merge!(options)
12
+ options = {bootstrap: {field_class: "form-range"}}.deep_merge!(options)
13
13
 
14
- field_wrapper_builder(attribute, options) do
14
+ bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
+ return super if bootstrap_options.disabled?
16
+
17
+ field_wrapper_builder(attribute, bootstrap_options, options) do
15
18
  super(attribute, options)
16
19
  end
17
20
  end
@@ -11,7 +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
- field_wrapper_builder(attribute, options) do
14
+ bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
+ return super if bootstrap_options.disabled?
16
+
17
+ field_wrapper_builder(attribute, bootstrap_options, options) do
15
18
  super(attribute, options)
16
19
  end
17
20
  end
@@ -9,9 +9,12 @@ module RailsBootstrapForm
9
9
 
10
10
  included do
11
11
  def select(attribute, choices = nil, options = {}, html_options = {}, &block)
12
- options = {bootstrap_form: {field_class: "form-select"}}.deep_merge!(options)
12
+ options = {bootstrap: {field_class: "form-select"}}.deep_merge!(options)
13
13
 
14
- field_wrapper_builder(attribute, options, html_options) do
14
+ bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
+ return super if bootstrap_options.disabled?
16
+
17
+ field_wrapper_builder(attribute, bootstrap_options, options, html_options) do
15
18
  super(attribute, choices, options, html_options, &block)
16
19
  end
17
20
  end
@@ -15,7 +15,7 @@ module RailsBootstrapForm
15
15
  static_options = options.merge(
16
16
  readonly: true,
17
17
  disabled: true,
18
- bootstrap_form: {
18
+ bootstrap: {
19
19
  field_class: bootstrap_form_options.static_field_class
20
20
  }
21
21
  )
@@ -9,9 +9,12 @@ module RailsBootstrapForm
9
9
 
10
10
  included do
11
11
  def time_zone_select(attribute, priority_zones = nil, options = {}, html_options = {})
12
- options = {bootstrap_form: {field_class: "form-select"}}.deep_merge!(options)
12
+ options = {bootstrap: {field_class: "form-select"}}.deep_merge!(options)
13
13
 
14
- field_wrapper_builder(attribute, options, html_options) do
14
+ bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
+ return super if bootstrap_options.disabled?
16
+
17
+ field_wrapper_builder(attribute, bootstrap_options, options, html_options) do
15
18
  super(attribute, priority_zones, options, html_options)
16
19
  end
17
20
  end
@@ -9,9 +9,12 @@ module RailsBootstrapForm
9
9
 
10
10
  included do
11
11
  def weekday_select(attribute, options = {}, html_options = {}, &block)
12
- options = {bootstrap_form: {field_class: "form-select"}}.deep_merge!(options)
12
+ options = {bootstrap: {field_class: "form-select"}}.deep_merge!(options)
13
13
 
14
- field_wrapper_builder(attribute, options, html_options) do
14
+ bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
+ return super if bootstrap_options.disabled?
16
+
17
+ field_wrapper_builder(attribute, bootstrap_options, options, html_options) do
15
18
  super(attribute, options, html_options, &block)
16
19
  end
17
20
  end
@@ -3,6 +3,6 @@
3
3
  # -*- warn_indent: true -*-
4
4
 
5
5
  module RailsBootstrapForm
6
- VERSION = "0.8.3".freeze
6
+ VERSION = "0.9.1".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.8.3
4
+ version: 0.9.1
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-29 00:00:00.000000000 Z
11
+ date: 2023-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: generator_spec