rails_bootstrap_form 0.8.2 → 0.9.0

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 (28) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +17 -0
  3. data/Gemfile.lock +1 -1
  4. data/README.md +184 -37
  5. data/demo/app/views/users/_horizontal_form.html.erb +1 -1
  6. data/demo/app/views/users/_inline_form.html.erb +1 -1
  7. data/lib/rails_bootstrap_form/bootstrap_form_builder.rb +5 -5
  8. data/lib/rails_bootstrap_form/bootstrap_form_options.rb +16 -10
  9. data/lib/rails_bootstrap_form/field_wrapper_builder.rb +2 -4
  10. data/lib/rails_bootstrap_form/helpers/buttons.rb +1 -1
  11. data/lib/rails_bootstrap_form/helpers/check_box.rb +1 -1
  12. data/lib/rails_bootstrap_form/helpers/radio_button.rb +1 -1
  13. data/lib/rails_bootstrap_form/inputs/base.rb +9 -3
  14. data/lib/rails_bootstrap_form/inputs/check_box.rb +10 -13
  15. data/lib/rails_bootstrap_form/inputs/collection_check_boxes.rb +5 -2
  16. data/lib/rails_bootstrap_form/inputs/collection_radio_buttons.rb +5 -2
  17. data/lib/rails_bootstrap_form/inputs/collection_select.rb +5 -2
  18. data/lib/rails_bootstrap_form/inputs/color_field.rb +5 -2
  19. data/lib/rails_bootstrap_form/inputs/grouped_collection_select.rb +5 -2
  20. data/lib/rails_bootstrap_form/inputs/radio_button.rb +10 -13
  21. data/lib/rails_bootstrap_form/inputs/range_field.rb +5 -2
  22. data/lib/rails_bootstrap_form/inputs/rich_text_area.rb +4 -1
  23. data/lib/rails_bootstrap_form/inputs/select.rb +5 -2
  24. data/lib/rails_bootstrap_form/inputs/static_field.rb +1 -1
  25. data/lib/rails_bootstrap_form/inputs/time_zone_select.rb +5 -2
  26. data/lib/rails_bootstrap_form/inputs/weekday_select.rb +5 -2
  27. data/lib/rails_bootstrap_form/version.rb +1 -1
  28. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e02719566479d775dbcff16d248f1a2498c34a71000c192202d45656b5412343
4
- data.tar.gz: 26b36857096e847a7c2fc43c83ff3dff3b49f76d6d3b053bbefb3f98a8fa01d0
3
+ metadata.gz: 15ea5c9f97b548a1fbadb720b875c2a0a784ea6184e77b62af1191865bcef46c
4
+ data.tar.gz: 70f4b371a945958580eb8883868a799deb9b189454a1c8bf97ef263905dd0a39
5
5
  SHA512:
6
- metadata.gz: 4e17627f2bdb97af7c136d211428695bc853490d3f7fd2c65fb29de6199c8744782852c2c92b72f40c134f2c4285ef76684e5574644fda4ea77e59dd8e7c27f1
7
- data.tar.gz: 85218ad2ab4b9bf3a22f478dcdf150930453d4326e51807f3018278df3c0d3e93d30b99af1e04b52f47765f5626f5899b8c26d7156a8b3a94aadf7886b536d94
6
+ metadata.gz: 82b6509a781a1acd0ac837b1bd51900a2fa023bc1a55870905c25509fc48d674d1ee164ca309c8cf8446dae4364f815bf639ecab14b4c205c60cca0edd2e0a4b
7
+ data.tar.gz: f2e4dd5bcd9a4f0f4aa5763d22bc9003118b8f8ad3e56f56c16dc30defd86ea95d877d6b0fdeaca54ffc11eeb32358bf3dd5a388c7165e966c4d9f366d709fef
data/CHANGELOG.md CHANGED
@@ -4,6 +4,23 @@ 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.0](https://github.com/shivam091/rails_bootstrap_form/compare/v0.8.3...v0.9.0) - 2023-05-31
8
+
9
+ ### What's new
10
+
11
+ - Added `disabled` option to allow user to render default Rails form builder element.
12
+
13
+ ### BREAKING CHANGES
14
+
15
+ - Renamed `wrapper_options` option to `wrapper`
16
+ - Renamed `bootstrap_form` option to `bootstrap`
17
+
18
+ ## [0.8.3](https://github.com/shivam091/rails_bootstrap_form/compare/v0.8.2...v0.8.3) - 2023-05-29
19
+
20
+ ### What's new
21
+
22
+ - Added support to specify `bootstrap` option on `fields_for` helper ([#30](https://github.com/shivam091/rails_bootstrap_form/issues/30))
23
+
7
24
  ## [0.8.2](https://github.com/shivam091/rails_bootstrap_form/compare/v0.8.1...v0.8.2) - 2023-05-28
8
25
 
9
26
  ### What's fixed
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails_bootstrap_form (0.8.2)
4
+ rails_bootstrap_form (0.9.0)
5
5
  actionpack (~> 7.0)
6
6
  activemodel (~> 7.0)
7
7
 
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # RailsBootstrapForm
2
2
 
3
+ [![Ruby](https://github.com/shivam091/rails_bootstrap_form/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/shivam091/rails_bootstrap_form/actions/workflows/main.yml)
3
4
  [![Gem Version](https://badge.fury.io/rb/rails_bootstrap_form.svg)](https://badge.fury.io/rb/rails_bootstrap_form)
4
5
 
5
6
  **rails_bootstrap_form** is a Rails form builder that makes it super easy to integrate [Bootstrap 5](https://getbootstrap.com/) forms into your Rails application.
@@ -149,10 +150,11 @@ This generates the following HTML:
149
150
 
150
151
  ## Bootstrap Configuration Options
151
152
 
152
- 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:
153
154
 
154
155
  | Option | Description | Default value |
155
156
  | ------ | ------------- | ----------- |
157
+ | `disabled` | An option to disable **rails_bootstrap_form** helpers. Default rails form builder element is rendered when set to `true` | `false` |
156
158
  | `layout` | Controls layout of form and field helpers. It can be `vertical` `horizontal`, or `inline`. | `vertical` |
157
159
  | `field_class` | A CSS class that will be applied to all form fields. | `form-control` |
158
160
  | `additional_field_class` | An additional CSS class that will be added along with the existing css classes of field helpers. | `nil` |
@@ -169,7 +171,7 @@ Here's a list of all possible options you can pass via `bootstrap_form` option t
169
171
  | `floating` | An option to control whether the field should have a floating label. | `false` |
170
172
  | `static_field_class` | A CSS class that will be applied to all static fields. | `form-control-plaintext` |
171
173
  | `switch` | An option to control whether the check box should look like Bootstrap switches. | `false` |
172
- | `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. | `{}` |
173
175
  | `size` | An option to control the size of input groups, buttons, labels, and fields. It can be `sm` or `lg`. | `nil` |
174
176
  | `inline` | An option to group checkboxes and radio buttons on the same horizontal row. | `false` |
175
177
  | `label_col_class` | A CSS class that will be applied to all labels when layout is `horizontal`. | `col-form-label` |
@@ -186,7 +188,7 @@ Here's an example of a form where one field uses different layout:
186
188
  <%= bootstrap_form_for @user do |form| %>
187
189
  <%= form.text_field :name %>
188
190
  <%= form.email_field :email %>
189
- <%= form.password_field :password, bootstrap_form: {layout: :horizontal} %>
191
+ <%= form.password_field :password, bootstrap: {layout: :horizontal} %>
190
192
  <%= form.check_box :terms, required: true %>
191
193
  <%= form.primary "Register" %>
192
194
  <% end %>
@@ -220,6 +222,14 @@ This generates the following HTML:
220
222
  </form>
221
223
  ```
222
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
+
223
233
  ## Supported Form Helpers
224
234
 
225
235
  This gem wraps most of the form field helpers. Here's the current list:
@@ -283,7 +293,7 @@ Here's an example of how it looks like by default:
283
293
  ![horizontal_layout](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/71493945-31d5-4917-83c2-8cb7b0825371)
284
294
 
285
295
  ```erb
286
- <%= bootstrap_form_for @user, bootstrap_form: {layout: :horizontal} do |form| %>
296
+ <%= bootstrap_form_for @user, bootstrap: {layout: :horizontal} do |form| %>
287
297
  <%= form.email_field :email %>
288
298
  <%= form.password_field :password %>
289
299
  <%= form.primary "Sign in" %>
@@ -314,9 +324,9 @@ The `label_col_wrapper_class` and `field_col_wrapper_class` css classes can also
314
324
  ![horizontal_form_custom_classes](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/ae5492f0-4a10-4f63-ae4d-9675bfb93226)
315
325
 
316
326
  ```erb
317
- <%= bootstrap_form_for @user, bootstrap_form: {layout: :horizontal} do |form| %>
327
+ <%= bootstrap_form_for @user, bootstrap: {layout: :horizontal} do |form| %>
318
328
  <%= form.text_field :name %>
319
- <%= 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"} %>
320
330
  <%= form.password_field :password %>
321
331
  <%= form.fields_for :address, include_id: false do |address_form| %>
322
332
  <%= address_form.select :country_id, options_for_select(::Country.pluck(:name, :id), address_form.object.country_id),
@@ -373,7 +383,7 @@ Here's an example of how it looks like:
373
383
  ![inline_layout](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/644a08ec-b249-4e1c-8d61-5350e6649f11)
374
384
 
375
385
  ```erb
376
- <%= bootstrap_form_for @user, bootstrap_form: {layout: :inline} do |form| %>
386
+ <%= bootstrap_form_for @user, bootstrap: {layout: :inline} do |form| %>
377
387
  <%= form.email_field :email %>
378
388
  <%= form.password_field :password %>
379
389
  <%= form.primary "Sign in" %>
@@ -410,7 +420,7 @@ generated by the Rails.
410
420
  ![label_text](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/b6378a06-c8e0-4944-8e0c-940a25964062)
411
421
 
412
422
  ```erb
413
- <%= form.password_field :password, bootstrap_form: {label_text: "New password"} %>
423
+ <%= form.password_field :password, bootstrap: {label_text: "New password"} %>
414
424
  ```
415
425
 
416
426
  This generates the following HTML:
@@ -428,7 +438,7 @@ to those using screen readers.
428
438
  ![hide_label](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/512a16b9-6829-40a2-bf07-f087970c9dac)
429
439
 
430
440
  ```erb
431
- <%= form.password_field :password, bootstrap_form: {hide_label: true} %>
441
+ <%= form.password_field :password, bootstrap: {hide_label: true} %>
432
442
  ```
433
443
 
434
444
  This generates the following HTML:
@@ -445,7 +455,7 @@ To skip a label, you can set `skip_label` option to `true`. This will not render
445
455
  ![skip_label](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/251e28ac-b98b-4e6a-8d55-8c0cb061e65a)
446
456
 
447
457
  ```erb
448
- <%= form.password_field :password, bootstrap_form: {skip_label: true} %>
458
+ <%= form.password_field :password, bootstrap: {skip_label: true} %>
449
459
  ```
450
460
 
451
461
  This generates the following HTML:
@@ -461,7 +471,7 @@ To add additional CSS class to the label, you can use `additional_label_class` o
461
471
  ![additional_label_class](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/b5ab4efe-2512-4ee4-9d35-99d3b7f78171)
462
472
 
463
473
  ```erb
464
- <%= form.password_field :password, bootstrap_form: {additional_label_class: "text-danger"} %>
474
+ <%= form.password_field :password, bootstrap: {additional_label_class: "text-danger"} %>
465
475
  ```
466
476
 
467
477
  This generates the following HTML:
@@ -507,7 +517,7 @@ You can customize the help text using `help_text` option:
507
517
  ![help_text](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/cdfe0e3c-6fcd-45a4-9621-9f0341925a1c)
508
518
 
509
519
  ```erb
510
- <%= 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."} %>
511
521
  ```
512
522
 
513
523
  This generates the following HTML:
@@ -546,7 +556,7 @@ You can use `prepend` and/or `append` options to attach addons to input fields:
546
556
  ![input_group_addon](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/e7fb8f52-558d-458d-a112-2ee3bab366db)
547
557
 
548
558
  ```erb
549
- <%= form.number_field :expected_ctc, bootstrap_form: {prepend: "₹", append: ".00"} %>
559
+ <%= form.number_field :expected_ctc, bootstrap: {prepend: "₹", append: ".00"} %>
550
560
  ```
551
561
 
552
562
  This generates the following HTML:
@@ -567,7 +577,7 @@ If you want to attach multiple addons to the input, pass them as an array:
567
577
  ![input_group_multiple_addons](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/8a6179c2-0def-428a-8429-c97db2c4a567)
568
578
 
569
579
  ```erb
570
- <%= 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"]} %>
571
581
  ```
572
582
 
573
583
  This generates the following HTML:
@@ -590,7 +600,7 @@ You can also prepend and append buttons. Note that these buttons must contain th
590
600
  ![input_group_button](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/f0d1e22a-ca2b-42da-b99c-f3e7003d8c27)
591
601
 
592
602
  ```erb
593
- <%= form.text_field :search, bootstrap_form: {append: form.secondary("Search")} %>
603
+ <%= form.text_field :search, bootstrap: {append: form.secondary("Search")} %>
594
604
  ```
595
605
 
596
606
  This generates the following HTML:
@@ -610,7 +620,7 @@ To add additional CSS class to the input group wrapper, you can use `additional_
610
620
  ![additional_input_group_class](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/1814ec85-1efe-4ffc-ba87-c171d1b73e2c)
611
621
 
612
622
  ```erb
613
- <%= 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"} %>
614
624
  ```
615
625
 
616
626
  This generates the following HTML:
@@ -631,7 +641,7 @@ You can customize size of the input group using `size` option. Input group suppo
631
641
  ![input_group_size](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/b7236bd6-4dad-4142-b14e-f6325a612958)
632
642
 
633
643
  ```erb
634
- <%= form.number_field :expected_ctc, bootstrap_form: {prepend: "₹", append: ".00", size: :sm} %>
644
+ <%= form.number_field :expected_ctc, bootstrap: {prepend: "₹", append: ".00", size: :sm} %>
635
645
  ```
636
646
 
637
647
  This generates the following HTML:
@@ -650,7 +660,7 @@ This generates the following HTML:
650
660
  ## Form Helpers
651
661
 
652
662
  Our form helpers accept the same arguments as the default Rails form helpers.
653
- 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.
654
664
  Here's an example of how you pass the arguments for each form helper:
655
665
 
656
666
  ### check_box
@@ -679,7 +689,7 @@ You can set `switch` option to `true` if you want check box to look like switche
679
689
  ![check_box_switch](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/20c493ce-7f2c-4ac9-a854-e1520cae6a54)
680
690
 
681
691
  ```erb
682
- <%= form.check_box :remember_me, bootstrap_form: {switch: true} %>
692
+ <%= form.check_box :remember_me, bootstrap: {switch: true} %>
683
693
  ```
684
694
 
685
695
  This generates the following HTML:
@@ -806,6 +816,143 @@ This generates the following HTML:
806
816
  </div>
807
817
  ```
808
818
 
819
+ ### fields_for
820
+
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).
822
+
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:
824
+
825
+ ![fields_for](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/f515302f-a92a-4b5c-a444-af91cbb00dff)
826
+
827
+ ```erb
828
+ <%= bootstrap_form_for @user do |form| %>
829
+ <%= form.email_field :email, autocomplete: "new-email" %>
830
+ <%= form.password_field :password, autocomplete: "new-password", bootstrap: {layout: :horizontal} %>
831
+ <%= form.phone_field :mobile_number %>
832
+ <%= form.fields_for :address, include_id: false, bootstrap: {layout: :horizontal} do |address_form| %>
833
+ <%= address_form.select :country_id, options_for_select(::Country.pluck(:name, :id), address_form.object.country_id),
834
+ {include_blank: "Select Country"} %>
835
+ <% end %>
836
+ <%= form.check_box :terms, required: true %>
837
+ <%= form.primary "Register" %>
838
+ <% end %>
839
+
840
+ ```
841
+
842
+ This generates the following HTML:
843
+
844
+ ```html
845
+ <form role="form" novalidate="novalidate" class="new_user" id="new_user" action="/users" accept-charset="UTF-8" method="post">
846
+ <div class="mb-3">
847
+ <label class="form-label required" for="user_email">Email address</label>
848
+ <input autocomplete="new-email" class="form-control" aria-required="true" required="required" type="email" name="user[email]" id="user_email">
849
+ <div class="form-text text-muted">Please use official email address</div>
850
+ </div>
851
+ <div class="row mb-3">
852
+ <label class="col-form-label col-sm-2 required" for="user_password">Password</label>
853
+ <div class="col-sm-10">
854
+ <input autocomplete="new-password" class="form-control" aria-required="true" required="required" type="password" name="user[password]" id="user_password">
855
+ </div>
856
+ </div>
857
+ <div class="mb-3">
858
+ <label class="form-label required" for="user_mobile_number">Mobile number</label>
859
+ <input class="form-control" aria-required="true" required="required" type="tel" name="user[mobile_number]" id="user_mobile_number">
860
+ </div>
861
+ <div class="row mb-3">
862
+ <label class="col-form-label col-sm-2 required" for="user_address_attributes_country_id">Country</label>
863
+ <div class="col-sm-10">
864
+ <select class="form-select" aria-required="true" required="required" name="user[address_attributes][country_id]" id="user_address_attributes_country_id">
865
+ <option value="">Select Country</option>
866
+ <option value="1">India</option>
867
+ <option value="2">Ireland</option>
868
+ <option value="3">United States</option>
869
+ <option value="4">United Kingdom</option>
870
+ <option value="5">Spain</option>
871
+ <option value="6">France</option>
872
+ <option value="7">Canada</option>
873
+ </select>
874
+ </div>
875
+ </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>
881
+ </div>
882
+ <input type="submit" name="commit" value="Register" class="btn btn-primary" data-disable-with="Register">
883
+ </form>
884
+ ```
885
+
886
+ 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:
887
+
888
+ ![fields_for_horizontal](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/cb75e76b-e8a3-48f1-83a1-9eb150aa2466)
889
+
890
+ ```erb
891
+ <%= bootstrap_form_for @user, bootstrap: {layout: :horizontal} do |form| %>
892
+ <%= form.email_field :email, autocomplete: "new-email" %>
893
+ <%= form.password_field :password, autocomplete: "new-password" %>
894
+ <%= form.phone_field :mobile_number %>
895
+ <%= form.fields_for :address, include_id: false do |address_form| %>
896
+ <%= address_form.select :country_id, options_for_select(::Country.pluck(:name, :id), address_form.object.country_id),
897
+ {include_blank: "Select Country"} %>
898
+ <% end %>
899
+ <%= form.check_box :terms, required: true %>
900
+ <%= form.primary "Register" %>
901
+ <% end %>
902
+ ```
903
+
904
+ This generates the following HTML:
905
+
906
+ ```html
907
+ <form role="form" novalidate="novalidate" class="new_user" id="new_user" action="/users" accept-charset="UTF-8" method="post">
908
+ <div class="row mb-3">
909
+ <label class="col-form-label col-sm-2 required" for="user_email">Email address</label>
910
+ <div class="col-sm-10">
911
+ <input autocomplete="new-email" class="form-control" aria-required="true" required="required" type="email" name="user[email]" id="user_email">
912
+ <div class="form-text text-muted">Please use official email address</div>
913
+ </div>
914
+ </div>
915
+ <div class="row mb-3">
916
+ <label class="col-form-label col-sm-2 required" for="user_password">Password</label>
917
+ <div class="col-sm-10">
918
+ <input autocomplete="new-password" class="form-control" aria-required="true" required="required" type="password" name="user[password]" id="user_password">
919
+ </div>
920
+ </div>
921
+ <div class="row mb-3">
922
+ <label class="col-form-label col-sm-2 required" for="user_mobile_number">Mobile number</label>
923
+ <div class="col-sm-10">
924
+ <input class="form-control" aria-required="true" required="required" type="tel" name="user[mobile_number]" id="user_mobile_number">
925
+ </div>
926
+ </div>
927
+ <div class="row mb-3">
928
+ <label class="col-form-label col-sm-2 required" for="user_address_attributes_country_id">Country</label>
929
+ <div class="col-sm-10">
930
+ <select class="form-select" aria-required="true" required="required" name="user[address_attributes][country_id]" id="user_address_attributes_country_id">
931
+ <option value="">Select Country</option>
932
+ <option value="1">India</option>
933
+ <option value="2">Ireland</option>
934
+ <option value="3">United States</option>
935
+ <option value="4">United Kingdom</option>
936
+ <option value="5">Spain</option>
937
+ <option value="6">France</option>
938
+ <option value="7">Canada</option>
939
+ </select>
940
+ </div>
941
+ </div>
942
+ <div class="row mb-3">
943
+ <div class="col-sm-10 offset-sm-2">
944
+ <div class="form-check">
945
+ <input name="user[terms]" type="hidden" value="0" autocomplete="off">
946
+ <input required="required" class="form-check-input" type="checkbox" value="1" name="user[terms]" id="user_terms">
947
+ <label class="form-check-label required" for="user_terms">I accept terms and conditions</label>
948
+ <div class="form-text text-muted">You must first accept terms and conditions in order to continue</div>
949
+ </div>
950
+ </div>
951
+ </div>
952
+ <input type="submit" name="commit" value="Register" class="btn btn-primary" data-disable-with="Register">
953
+ </form>
954
+ ```
955
+
809
956
  ### file_field
810
957
 
811
958
  Our `file_field` helper accepts the same arguments as the [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-file_field).
@@ -913,7 +1060,7 @@ This helper will render check box and label for you.
913
1060
  ![radio_button](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/9afa4065-6eea-44a6-a5be-d2936d1d2f9c)
914
1061
 
915
1062
  ```erb
916
- <%= form.radio_button :gender, :male, bootstrap_form: {label_text: "Male"} %>
1063
+ <%= form.radio_button :gender, :male, bootstrap: {label_text: "Male"} %>
917
1064
  ```
918
1065
 
919
1066
  This generates the following HTML:
@@ -930,7 +1077,7 @@ This helper also renders help text if `help_text` option is set or information o
930
1077
  ![radio_button_help_text](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/2409e822-c1bd-499b-b80f-e2948acf3403)
931
1078
 
932
1079
  ```erb
933
- <%= form.radio_button :gender, :male, bootstrap_form: {label_text: "Male", help_text: "Please select your gender"} %>
1080
+ <%= form.radio_button :gender, :male, bootstrap: {label_text: "Male", help_text: "Please select your gender"} %>
934
1081
  ```
935
1082
 
936
1083
  This generates the following HTML:
@@ -1098,7 +1245,7 @@ This generates the following HTML:
1098
1245
  ## Form Options Helpers
1099
1246
 
1100
1247
  Our form options helpers accept the same arguments as the default Rails form options helpers.
1101
- In order to apply addition options of `rails_bootstrap_form`, `bootstrap_form` object is passed in `options` argument of the helper.
1248
+ In order to apply addition options of `rails_bootstrap_form`, `bootstrap` object is passed in `options` argument of the helper.
1102
1249
  Here's an example of how you pass the arguments for each form option helper:
1103
1250
 
1104
1251
  ### select
@@ -1109,7 +1256,7 @@ Here's an example of how you pass both options and html_options hashes:
1109
1256
  ![select](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/e21f092c-d439-4817-bba1-8ec0c21330c1)
1110
1257
 
1111
1258
  ```erb
1112
- <%= 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();"} %>
1259
+ <%= 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();"} %>
1113
1260
  ```
1114
1261
 
1115
1262
  This generates the following HTML:
@@ -1135,7 +1282,7 @@ Here's an example of how you pass both options and html_options hashes:
1135
1282
  ![collection_select](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/c3a24265-81a9-4d1b-aa01-2b066d2f8bc7)
1136
1283
 
1137
1284
  ```erb
1138
- <%= 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();"} %>
1285
+ <%= 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();"} %>
1139
1286
  ```
1140
1287
 
1141
1288
  This generates the following HTML:
@@ -1161,7 +1308,7 @@ Here's an example of how you pass both options and html_options hashes:
1161
1308
  ![grouped_collection_select](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/d8f90065-3aa8-4d52-9c3e-0486324b3624)
1162
1309
 
1163
1310
  ```erb
1164
- <%= form.grouped_collection_select :city, ::Country.includes(:cities), :cities, :name, :id, :name, {include_blank: "Select city", bootstrap_form: {floating: true}}, {onchange: "this.form.submit();"} %>
1311
+ <%= form.grouped_collection_select :city, ::Country.includes(:cities), :cities, :name, :id, :name, {include_blank: "Select city", bootstrap: {floating: true}}, {onchange: "this.form.submit();"} %>
1165
1312
  ```
1166
1313
 
1167
1314
  This generates the following HTML:
@@ -1205,7 +1352,7 @@ Here's an example of how you pass both options and html_options hashes:
1205
1352
  ![time_zone_select](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/e161585c-1bbf-485c-9baf-c57b15258fe8)
1206
1353
 
1207
1354
  ```erb
1208
- <%= form.time_zone_select :timezone, ::ActiveSupport::TimeZone.all, {include_blank: "Select time zone", bootstrap_form: {label_text: "Preferred time zone"}}, {onchange: "this.form.submit();"} %>
1355
+ <%= form.time_zone_select :timezone, ::ActiveSupport::TimeZone.all, {include_blank: "Select time zone", bootstrap: {label_text: "Preferred time zone"}}, {onchange: "this.form.submit();"} %>
1209
1356
  ```
1210
1357
 
1211
1358
  This generates the following HTML:
@@ -1237,7 +1384,7 @@ Here's an example of how you pass both options and html_options hashes:
1237
1384
  ![weekday_select](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/e469a57d-3d22-4c9e-829b-4ba825593ae1)
1238
1385
 
1239
1386
  ```erb
1240
- <%= form.weekday_select :weekly_off, {selected: "Monday", bootstrap_form: {label_text: "Week off"}}, {onchange: "this.form.submit();} %>
1387
+ <%= form.weekday_select :weekly_off, {selected: "Monday", bootstrap: {label_text: "Week off"}}, {onchange: "this.form.submit();"} %>
1241
1388
  ```
1242
1389
 
1243
1390
  This generates the following HTML:
@@ -1265,7 +1412,7 @@ an argument and takes care of rendering labels, check boxes, and wrapper for you
1265
1412
  ![collection_check_boxes](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/c92f5921-e572-4384-812e-31308e018f66)
1266
1413
 
1267
1414
  ```erb
1268
- <%= form.collection_check_boxes :skill_ids, ::Skill.all, :id, :name, {bootstrap_form: {layout: :horizontal}, onchange: "this.form.submit();"}, {} %>
1415
+ <%= form.collection_check_boxes :skill_ids, ::Skill.all, :id, :name, {bootstrap: {layout: :horizontal}, onchange: "this.form.submit();"}, {} %>
1269
1416
  ```
1270
1417
 
1271
1418
  This generates the following HTML:
@@ -1330,7 +1477,7 @@ an argument and takes care of rendering labels, radio button, and wrapper for yo
1330
1477
  ![collection_radio_buttons](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/798a8b0c-915a-40b1-9874-dd74f50d3695)
1331
1478
 
1332
1479
  ```erb
1333
- <%= form.collection_radio_buttons :fruit_id, ::Fruit.all, :id, :name, {checked: form.object.fruit_id, bootstrap_form: {layout: :horizontal}}, {} %>
1480
+ <%= form.collection_radio_buttons :fruit_id, ::Fruit.all, :id, :name, {checked: form.object.fruit_id, bootstrap: {layout: :horizontal}}, {} %>
1334
1481
  ```
1335
1482
 
1336
1483
  This generates the following HTML:
@@ -1366,7 +1513,7 @@ This generates the following HTML:
1366
1513
 
1367
1514
  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.
1368
1515
  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`.
1369
- In order to apply addition options of `rails_bootstrap_form`, `bootstrap_form` object is passed in `options` argument of the helper.
1516
+ In order to apply addition options of `rails_bootstrap_form`, `bootstrap` object is passed in `options` argument of the helper.
1370
1517
 
1371
1518
  ### date_select
1372
1519
 
@@ -1376,7 +1523,7 @@ Here's an example of how you pass both options and html_options hashes:
1376
1523
  ![date_select](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/45fe5d72-43da-498e-a1c2-ac6729446bba)
1377
1524
 
1378
1525
  ```erb
1379
- <%= form.date_select :interview_date, {selected: form.object.interview_date, bootstrap_form: {label_text: "Choose interview date"}}, {onchange: "this.form.submit();"} %>
1526
+ <%= form.date_select :interview_date, {selected: form.object.interview_date, bootstrap: {label_text: "Choose interview date"}}, {onchange: "this.form.submit();"} %>
1380
1527
  ```
1381
1528
 
1382
1529
  This generates the following HTML:
@@ -1428,7 +1575,7 @@ Here's an example of how you pass both options and html_options hashes:
1428
1575
  ![time_select](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/2195922c-c7cc-48dc-9912-3ef3cbb8e017)
1429
1576
 
1430
1577
  ```erb
1431
- <%= form.time_select :interview_time, {selected: form.object.interview_time, bootstrap_form: {label_text: "Choose interview time"}}, {onchange: "this.form.submit();"} %>
1578
+ <%= form.time_select :interview_time, {selected: form.object.interview_time, bootstrap: {label_text: "Choose interview time"}}, {onchange: "this.form.submit();"} %>
1432
1579
  ```
1433
1580
 
1434
1581
  This generates the following HTML:
@@ -1472,7 +1619,7 @@ Here's an example of how you pass both options and html_options hashes:
1472
1619
  ![datetime_select](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/c0e0cd83-d44a-4308-bfa9-e25a2a488d66)
1473
1620
 
1474
1621
  ```erb
1475
- <%= form.datetime_select :interview_datetime, {selected: form.object.interview_datetime, bootstrap_form: {label_text: "Choose interview date & time"}}, {onchange: "this.form.submit();"} %>
1622
+ <%= form.datetime_select :interview_datetime, {selected: form.object.interview_datetime, bootstrap: {label_text: "Choose interview date & time"}}, {onchange: "this.form.submit();"} %>
1476
1623
  ```
1477
1624
 
1478
1625
  This generates the following HTML:
@@ -1572,7 +1719,7 @@ To render submit helper as a button helper, you can set `render_as_button` optio
1572
1719
  ![render_as_button](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/dffd72d8-3acf-4029-be04-3bf7776e8d9c)
1573
1720
 
1574
1721
  ```erb
1575
- <%= form.primary "Register", bootstrap_form: {render_as_button: true} %>
1722
+ <%= form.primary "Register", bootstrap: {render_as_button: true} %>
1576
1723
  <%= form.secondary do %>
1577
1724
  Sign in
1578
1725
  <% end %>
@@ -1617,7 +1764,7 @@ The `floating` option can be used to enable Bootstrap floating labels. This opti
1617
1764
  ![floating_labels](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/3976629d-4717-47b0-ab91-9a16e6c9ed5f)
1618
1765
 
1619
1766
  ```erb
1620
- <%= bootstrap_form_for @user, bootstrap_form: {floating: true} do |form| %>
1767
+ <%= bootstrap_form_for @user, bootstrap: {floating: true} do |form| %>
1621
1768
  <%= form.text_field :name %>
1622
1769
  <%= form.email_field :username %>
1623
1770
  <%= form.password_field :password %>
@@ -1790,13 +1937,13 @@ Some third party plug-ins require an empty but visible label on an input control
1790
1937
  The solution is to use a zero-width character for the label, or some other "empty" HTML. For example:
1791
1938
 
1792
1939
  ```erb
1793
- bootstrap_form: {label_text: "&#8203;".html_safe}
1940
+ bootstrap: {label_text: "&#8203;".html_safe}
1794
1941
  ```
1795
1942
 
1796
1943
  or
1797
1944
 
1798
1945
  ```erb
1799
- bootstrap_form: {label_text: "<span></span>".html_safe}
1946
+ bootstrap: {label_text: "<span></span>".html_safe}
1800
1947
  ```
1801
1948
 
1802
1949
  ## 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" %>
@@ -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 %>
@@ -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)
@@ -41,10 +41,10 @@ module RailsBootstrapForm
41
41
  end
42
42
 
43
43
  def fields_for_options(record_object, fields_options)
44
- field_options = record_object if record_object.is_a?(Hash) && record_object.extractable_options?
45
- field_options = {bootstrap_form: options.fetch(:bootstrap_form, {})}
46
- field_options.deep_merge!(field_options) if field_options.respond_to?(:deep_merge!)
47
- field_options
44
+ 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)
47
+ fields_options
48
48
  end
49
49
 
50
50
  private :apply_default_form_options, :fields_for_options, :apply_default_form_classes
@@ -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)
@@ -52,7 +50,7 @@ module RailsBootstrapForm
52
50
  def field_wrapper_options(bootstrap_options)
53
51
  {}.tap do |option|
54
52
  option[:class] = field_wrapper_classes(bootstrap_options)
55
- end.merge(bootstrap_options.wrapper_options)
53
+ end.merge(bootstrap_options.wrapper)
56
54
  end
57
55
 
58
56
  def field_wrapper_classes(bootstrap_options)
@@ -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)
@@ -30,7 +30,7 @@ module RailsBootstrapForm
30
30
  def check_box_wrapper_options(bootstrap_options)
31
31
  {}.tap do |option|
32
32
  option[:class] = check_box_wrapper_class(bootstrap_options)
33
- end.merge(bootstrap_options.wrapper_options)
33
+ end.merge(bootstrap_options.wrapper)
34
34
  end
35
35
 
36
36
  def check_box_label_text(attribute, options, bootstrap_options, &block)
@@ -31,7 +31,7 @@ module RailsBootstrapForm
31
31
  def radio_button_wrapper_options(bootstrap_options)
32
32
  {}.tap do |option|
33
33
  option[:class] = radio_button_wrapper_class(bootstrap_options)
34
- end.merge(bootstrap_options.wrapper_options)
34
+ end.merge(bootstrap_options.wrapper)
35
35
  end
36
36
 
37
37
  def radio_button_value(attribute, value)
@@ -10,7 +10,10 @@ module RailsBootstrapForm
10
10
  class_methods do
11
11
  def bootstrap_field(field_name)
12
12
  define_method(field_name) do |attribute, options = {}|
13
- field_wrapper_builder(attribute, options) do
13
+ bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
14
+ return super(attribute, options) if bootstrap_options.disabled?
15
+
16
+ field_wrapper_builder(attribute, bootstrap_options, options) do
14
17
  super(attribute, options)
15
18
  end
16
19
  end
@@ -18,9 +21,12 @@ module RailsBootstrapForm
18
21
 
19
22
  def bootstrap_select_group(field_name)
20
23
  define_method(field_name) do |attribute, options = {}, html_options = {}|
21
- options = {bootstrap_form: {field_class: "form-select"}}.deep_merge!(options)
24
+ options = {bootstrap: {field_class: "form-select"}}.deep_merge!(options)
25
+
26
+ bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
27
+ return super(attribute, options, html_options) if bootstrap_options.disabled?
22
28
 
23
- field_wrapper_builder(attribute, options, html_options) do
29
+ field_wrapper_builder(attribute, bootstrap_options, options, html_options) do
24
30
  tag.fieldset(class: control_specific_class(field_name)) do
25
31
  super(attribute, options, html_options)
26
32
  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
 
@@ -25,20 +26,16 @@ module RailsBootstrapForm
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,6 +9,9 @@ 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?
14
+
12
15
  options[:multiple] = true
13
16
 
14
17
  inputs = ActiveSupport::SafeBuffer.new
@@ -16,7 +19,7 @@ module RailsBootstrapForm
16
19
  collection.each do |object|
17
20
  input_value = value_method.respond_to?(:call) ? value_method.call(object) : object.send(value_method)
18
21
  input_options = {
19
- bootstrap_form: {
22
+ bootstrap: {
20
23
  label_text: text_method.respond_to?(:call) ? text_method.call(object) : object.send(text_method),
21
24
  inline: true
22
25
  }
@@ -29,7 +32,7 @@ module RailsBootstrapForm
29
32
  inputs.prepend(hidden_field(attribute, value: "", multiple: options[:multiple]))
30
33
  end
31
34
 
32
- field_wrapper_builder(attribute, options, html_options) do
35
+ field_wrapper_builder(attribute, bootstrap_options, options, html_options) do
33
36
  concat(tag.div(class: control_specific_class(:collection_check_boxes)) do
34
37
  concat(inputs)
35
38
  end)
@@ -9,12 +9,15 @@ 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?
14
+
12
15
  inputs = ActiveSupport::SafeBuffer.new
13
16
 
14
17
  collection.each do |object|
15
18
  input_value = value_method.respond_to?(:call) ? value_method.call(object) : object.send(value_method)
16
19
  input_options = {
17
- bootstrap_form: {
20
+ bootstrap: {
18
21
  label_text: text_method.respond_to?(:call) ? text_method.call(object) : object.send(text_method),
19
22
  inline: true
20
23
  }
@@ -27,7 +30,7 @@ module RailsBootstrapForm
27
30
  inputs << radio_button(attribute, input_value, input_options)
28
31
  end
29
32
 
30
- field_wrapper_builder(attribute, options, html_options) do
33
+ field_wrapper_builder(attribute, bootstrap_options, options, html_options) do
31
34
  concat(tag.div(class: control_specific_class(:collection_radio_buttons)) do
32
35
  concat(inputs)
33
36
  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
 
@@ -25,20 +26,16 @@ module RailsBootstrapForm
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.2".freeze
6
+ VERSION = "0.9.0".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.2
4
+ version: 0.9.0
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-28 00:00:00.000000000 Z
11
+ date: 2023-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: generator_spec