rails_bootstrap_form 0.9.1 → 0.9.2

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 +15 -1
  3. data/Gemfile.lock +1 -1
  4. data/README.md +71 -41
  5. data/lib/rails_bootstrap_form/bootstrap_form_builder.rb +5 -2
  6. data/lib/rails_bootstrap_form/field_wrapper_builder.rb +50 -49
  7. data/lib/rails_bootstrap_form/helpers/buttons.rb +3 -3
  8. data/lib/rails_bootstrap_form/helpers/check_box.rb +26 -30
  9. data/lib/rails_bootstrap_form/helpers/help_text.rb +3 -3
  10. data/lib/rails_bootstrap_form/helpers/labels.rb +16 -16
  11. data/lib/rails_bootstrap_form/helpers/radio_button.rb +21 -26
  12. data/lib/rails_bootstrap_form/helpers.rb +2 -2
  13. data/lib/rails_bootstrap_form/input_group_builder.rb +14 -14
  14. data/lib/rails_bootstrap_form/inputs/base.rb +13 -12
  15. data/lib/rails_bootstrap_form/inputs/check_box.rb +11 -19
  16. data/lib/rails_bootstrap_form/inputs/collection_check_boxes.rb +11 -5
  17. data/lib/rails_bootstrap_form/inputs/collection_radio_buttons.rb +11 -5
  18. data/lib/rails_bootstrap_form/inputs/collection_select.rb +3 -3
  19. data/lib/rails_bootstrap_form/inputs/color_field.rb +3 -3
  20. data/lib/rails_bootstrap_form/inputs/grouped_collection_select.rb +3 -3
  21. data/lib/rails_bootstrap_form/inputs/radio_button.rb +11 -19
  22. data/lib/rails_bootstrap_form/inputs/range_field.rb +3 -3
  23. data/lib/rails_bootstrap_form/inputs/rich_text_area.rb +3 -3
  24. data/lib/rails_bootstrap_form/inputs/select.rb +3 -3
  25. data/lib/rails_bootstrap_form/inputs/time_zone_select.rb +3 -3
  26. data/lib/rails_bootstrap_form/inputs/weekday_select.rb +3 -3
  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: 4cc018cfa787b152387078681629abadc1794699ef4151423db7fad244560be7
4
- data.tar.gz: 4e932a41a3c992a79f766b868d04b655b4fb3aafabb08559caa8714189ac25d0
3
+ metadata.gz: 23429dc16ad64529ba65b78cf376ff4bb5b31134bb87b1f8808af1fd32fe0427
4
+ data.tar.gz: 83785c866c4705460b55cbad301971492f360407b4d91abf49e0f11d25f07070
5
5
  SHA512:
6
- metadata.gz: 6738ad4f1381fe2ef85aa87e87b825ac0b0d96a3131f5727a5550361945cf99a9223fbed1b4018f139e89d39c9ab679df3a57b43e8e66dccfd1adb11af4610b6
7
- data.tar.gz: c6e9250a1ea90b92398a2e3834450fbf6bdcc27f3ab8a5189c394795d53548caca48371f55e91b786bd9c2d05acb2702021d31b8a1fe5f6debaf9b1574611ced
6
+ metadata.gz: 3be8e0f60800ddd2fabf8b6db7a5d2d996bb45c932f184578448e4525bddd85d87f798b69dbc13787e04e87d2d2ed53dcabd4f9e78f97914247379a83237bafb
7
+ data.tar.gz: 2ab6a13c6b251556033636c06baa061b4379b8acea6461e1b6a36ddda9fd85a8892b322c660aa7d68e2377f6271250fa28fe35691c7f35a5001e5b928597d21f
data/CHANGELOG.md CHANGED
@@ -4,7 +4,21 @@ 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-
7
+ ## [0.9.2](https://github.com/shivam091/rails_bootstrap_form/compare/v0.9.1...v0.9.2) - 2023-06-03
8
+
9
+ ### What's new
10
+
11
+ - Added support to disable wrapper by passing option `wrapper: false`.
12
+
13
+ ### What's fixed
14
+
15
+ - Changes to not showing required `asterisk` in `collection_check_boxes` and `collection_radio_buttons` helper ([#34](https://github.com/shivam091/rails_bootstrap_form/issues/34)).
16
+
17
+ ### What's changed
18
+
19
+ - Wrappers of `check_box`, `collection_check_boxes`, `radio_button`, and `collection_radio_buttons` helpers.
20
+
21
+ ## [0.9.1](https://github.com/shivam091/rails_bootstrap_form/compare/v0.9.0...v0.9.1) - 2023-06-02
8
22
 
9
23
  ### What's new
10
24
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails_bootstrap_form (0.9.1)
4
+ rails_bootstrap_form (0.9.2)
5
5
  actionpack (~> 7.0)
6
6
  activemodel (~> 7.0)
7
7
 
data/README.md CHANGED
@@ -103,10 +103,12 @@ This generates the following HTML:
103
103
  <label class="form-label required" for="user_password">Password</label>
104
104
  <input class="form-control" aria-required="true" required="required" type="password" name="user[password]" id="user_password">
105
105
  </div>
106
- <div class="form-check mb-3">
107
- <input name="user[remember_me]" type="hidden" value="0" autocomplete="off">
108
- <input class="form-check-input" type="checkbox" value="1" name="user[remember_me]" id="user_remember_me">
109
- <label class="form-check-label" for="user_remember_me">Remember me</label>
106
+ <div class="mb-3">
107
+ <div class="form-check">
108
+ <input class="form-check-input" type="checkbox" value="1" name="user[terms]" id="user_terms">
109
+ <label class="form-check-label" for="user_terms">I accept terms and conditions</label>
110
+ <div class="form-text text-muted">You must first accept terms and conditions in order to continue</div>
111
+ </div>
110
112
  </div>
111
113
  <input type="submit" name="commit" value="Log In" class="btn btn-primary" data-disable-with="Log In">
112
114
  </form>
@@ -139,10 +141,12 @@ This generates the following HTML:
139
141
  <label class="form-label required" for="user_password">Password</label>
140
142
  <input class="form-control" aria-required="true" required="required" type="password" name="user[password]" id="user_password">
141
143
  </div>
142
- <div class="form-check mb-3">
143
- <input name="user[remember_me]" type="hidden" value="0" autocomplete="off">
144
- <input class="form-check-input" type="checkbox" value="1" name="user[remember_me]" id="user_remember_me">
145
- <label class="form-check-label" for="user_remember_me">Remember me</label>
144
+ <div class="mb-3">
145
+ <div class="form-check">
146
+ <input class="form-check-input" type="checkbox" value="1" name="user[terms]" id="user_terms">
147
+ <label class="form-check-label" for="user_terms">I accept terms and conditions</label>
148
+ <div class="form-text text-muted">You must first accept terms and conditions in order to continue</div>
149
+ </div>
146
150
  </div>
147
151
  <input type="submit" name="commit" value="Log In" class="btn btn-primary" data-disable-with="Log In">
148
152
  </form>
@@ -171,7 +175,7 @@ Here's a list of all possible options you can pass via `bootstrap` option that c
171
175
  | `floating` | An option to control whether the field should have a floating label. | `false` |
172
176
  | `static_field_class` | A CSS class that will be applied to all static fields. | `form-control-plaintext` |
173
177
  | `switch` | An option to control whether the check box should look like Bootstrap switches. | `false` |
174
- | `wrapper` | An option to control the HTML attributes and options that will be added to a field wrapper. | `{}` |
178
+ | `wrapper` | An option to control the HTML attributes and options that will be added to a field wrapper. You can set it false if you don't the field to be rendered in a wrapper. | `{}` |
175
179
  | `size` | An option to control the size of input groups, buttons, labels, and fields. It can be `sm` or `lg`. | `nil` |
176
180
  | `inline` | An option to group checkboxes and radio buttons on the same horizontal row. | `false` |
177
181
  | `label_col_class` | A CSS class that will be applied to all labels when layout is `horizontal`. | `col-form-label` |
@@ -189,7 +193,7 @@ Here's an example of a form where one field uses different layout:
189
193
  <%= form.text_field :name %>
190
194
  <%= form.email_field :email %>
191
195
  <%= form.password_field :password, bootstrap: {layout: :horizontal} %>
192
- <%= form.check_box :terms, required: true %>
196
+ <%= form.check_box :terms %>
193
197
  <%= form.primary "Register" %>
194
198
  <% end %>
195
199
  ```
@@ -212,11 +216,12 @@ This generates the following HTML:
212
216
  <input class="form-control" aria-required="true" required="required" type="password" name="user[password]" id="user_password">
213
217
  </div>
214
218
  </div>
215
- <div class="form-check mb-3">
216
- <input name="user[terms]" type="hidden" value="0" autocomplete="off">
217
- <input required="required" class="form-check-input" type="checkbox" value="1" name="user[terms]" id="user_terms">
218
- <label class="form-check-label required" for="user_terms">I accept terms and conditions</label>
219
- <div class="form-text text-muted">You must first accept terms and conditions in order to continue</div>
219
+ <div class="mb-3">
220
+ <div class="form-check">
221
+ <input class="form-check-input" type="checkbox" value="1" name="user[terms]" id="user_terms">
222
+ <label class="form-check-label" for="user_terms">I accept terms and conditions</label>
223
+ <div class="form-text text-muted">You must first accept terms and conditions in order to continue</div>
224
+ </div>
220
225
  </div>
221
226
  <input type="submit" name="commit" value="Register" class="btn btn-primary" data-disable-with="Register">
222
227
  </form>
@@ -230,6 +235,23 @@ You can completely disable bootstrap and use default form builder by passing `di
230
235
  <%= form.text_field :username, bootstrap: {disabled: true} %>
231
236
  ```
232
237
 
238
+ ### Disabling wrapper
239
+
240
+ In some cases, you may need to disable the default wrapper. You can do this by passing 'wrapper: false':
241
+
242
+ ![wrapper_false](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/1693cf0f-7a30-494d-9fb5-394f4fb2c676)
243
+
244
+ ```erb
245
+ <%= form.text_field :name, bootstrap: {wrapper: false} %>
246
+ ```
247
+
248
+ This generates the following HTML:
249
+
250
+ ```html
251
+ <label class="form-label required" for="user_name">Name</label>
252
+ <input class="form-control" aria-required="true" required="required" type="text" name="user[name]" id="user_name">
253
+ ```
254
+
233
255
  ## Supported Form Helpers
234
256
 
235
257
  This gem wraps most of the form field helpers. Here's the current list:
@@ -677,10 +699,11 @@ This helper will render check box and label for you.
677
699
  This generates the following HTML:
678
700
 
679
701
  ```html
680
- <div class="form-check mb-3">
681
- <input name="user[remember_me]" type="hidden" value="0" autocomplete="off">
682
- <input class="form-check-input" type="checkbox" value="1" name="user[remember_me]" id="user_remember_me">
683
- <label class="form-check-label" for="user_remember_me">Keep me signed in</label>
702
+ <div class="mb-3">
703
+ <div class="form-check">
704
+ <input class="form-check-input" type="checkbox" value="1" name="user[remember_me]" id="user_remember_me">
705
+ <label class="form-check-label" for="user_remember_me">Keep me signed in</label>
706
+ </div>
684
707
  </div>
685
708
  ```
686
709
 
@@ -695,10 +718,11 @@ You can set `switch` option to `true` if you want check box to look like switche
695
718
  This generates the following HTML:
696
719
 
697
720
  ```html
698
- <div class="form-check form-switch mb-3">
699
- <input name="user[remember_me]" type="hidden" value="0" autocomplete="off">
700
- <input class="form-check-input" type="checkbox" value="1" name="user[remember_me]" id="user_remember_me">
701
- <label class="form-check-label" for="user_remember_me">Keep me signed in</label>
721
+ <div class="mb-3">
722
+ <div class="form-check form-switch">
723
+ <input class="form-check-input" type="checkbox" value="1" name="user[remember_me]" id="user_remember_me">
724
+ <label class="form-check-label" for="user_remember_me">Keep me signed in</label>
725
+ </div>
702
726
  </div>
703
727
  ```
704
728
 
@@ -713,11 +737,12 @@ This helper also renders help text if `help_text` option is set or information o
713
737
  This generates the following HTML:
714
738
 
715
739
  ```html
716
- <div class="form-check mb-3">
717
- <input name="user[terms]" type="hidden" value="0" autocomplete="off">
718
- <input required="required" class="form-check-input" type="checkbox" value="1" name="user[terms]" id="user_terms">
719
- <label class="form-check-label required" for="user_terms">I accept terms and conditions</label>
720
- <div class="form-text text-muted">You must first accept terms and conditions in order to continue</div>
740
+ <div class="mb-3">
741
+ <div class="form-check">
742
+ <input required="required" class="form-check-input" type="checkbox" value="1" name="user[terms]" id="user_terms">
743
+ <label class="form-check-label required" for="user_terms">I accept terms and conditions</label>
744
+ <div class="form-text text-muted">You must first accept terms and conditions in order to continue</div>
745
+ </div>
721
746
  </div>
722
747
  ```
723
748
 
@@ -872,11 +897,12 @@ This generates the following HTML:
872
897
  </select>
873
898
  </div>
874
899
  </div>
875
- <div class="form-check mb-3">
876
- <input name="user[terms]" type="hidden" value="0" autocomplete="off">
877
- <input required="required" class="form-check-input" type="checkbox" value="1" name="user[terms]" id="user_terms">
878
- <label class="form-check-label required" for="user_terms">I accept terms and conditions</label>
879
- <div class="form-text text-muted">You must first accept terms and conditions in order to continue</div>
900
+ <div class="mb-3">
901
+ <div class="form-check">
902
+ <input required="required" class="form-check-input" type="checkbox" value="1" name="user[terms]" id="user_terms">
903
+ <label class="form-check-label required" for="user_terms">I accept terms and conditions</label>
904
+ <div class="form-text text-muted">You must first accept terms and conditions in order to continue</div>
905
+ </div>
880
906
  </div>
881
907
  <input type="submit" name="commit" value="Register" class="btn btn-primary" data-disable-with="Register">
882
908
  </form>
@@ -1065,9 +1091,11 @@ This helper will render check box and label for you.
1065
1091
  This generates the following HTML:
1066
1092
 
1067
1093
  ```html
1068
- <div class="form-check mb-3">
1069
- <input class="form-check-input" type="radio" value="male" name="user[gender]" id="user_gender_male">
1070
- <label class="form-check-label" for="user_gender_male">Male</label>
1094
+ <div class="mb-3">
1095
+ <div class="form-check">
1096
+ <input class="form-check-input" type="radio" value="male" name="user[gender]" id="user_gender_male">
1097
+ <label class="form-check-label" for="user_gender_male">Male</label>
1098
+ </div>
1071
1099
  </div>
1072
1100
  ```
1073
1101
 
@@ -1082,10 +1110,12 @@ This helper also renders help text if `help_text` option is set or information o
1082
1110
  This generates the following HTML:
1083
1111
 
1084
1112
  ```html
1085
- <div class="form-check mb-3">
1086
- <input class="form-check-input" type="radio" value="male" name="user[gender]" id="user_gender_male">
1087
- <label class="form-check-label" for="user_gender_male">Male</label>
1088
- <div class="form-text text-muted">Please select your gender</div>
1113
+ <div class="mb-3">
1114
+ <div class="form-check">
1115
+ <input class="form-check-input" type="radio" value="male" name="user[gender]" id="user_gender_male">
1116
+ <label class="form-check-label" for="user_gender_male">Male</label>
1117
+ <div class="form-text text-muted">Please select your gender</div>
1118
+ </div>
1089
1119
  </div>
1090
1120
  ```
1091
1121
 
@@ -1971,7 +2001,7 @@ bootstrap: {label_text: "<span></span>".html_safe}
1971
2001
 
1972
2002
  ## Contributing
1973
2003
 
1974
- I welcome contributions. If you wish to contribute in `rails_bootstrap_form`, please review the [Contributing]() document first.
2004
+ I welcome contributions. If you wish to contribute in `rails_bootstrap_form`, please review the [Contributing](/CONTRIBUTING.md) document first.
1975
2005
 
1976
2006
  ## License
1977
2007
 
@@ -5,6 +5,9 @@
5
5
  module RailsBootstrapForm
6
6
  class BootstrapFormBuilder < ActionView::Helpers::FormBuilder
7
7
 
8
+ alias_method :check_box_without_bootstrap, :check_box
9
+ alias_method :radio_button_without_bootstrap, :radio_button
10
+
8
11
  include RailsBootstrapForm::FieldWrapperBuilder
9
12
  include RailsBootstrapForm::Helpers
10
13
  include RailsBootstrapForm::InputGroupBuilder
@@ -42,8 +45,8 @@ module RailsBootstrapForm
42
45
 
43
46
  def fields_for_options(record_object, fields_options)
44
47
  fields_options = record_object if record_object.is_a?(Hash) && record_object.extractable_options?
45
- bootstrap_options = {bootstrap: options.fetch(:bootstrap, {})}
46
- fields_options = bootstrap_options.deep_merge!(fields_options)
48
+ bootstrap = {bootstrap: options.fetch(:bootstrap, {})}
49
+ fields_options = bootstrap.deep_merge!(fields_options)
47
50
  fields_options
48
51
  end
49
52
 
@@ -4,88 +4,89 @@
4
4
 
5
5
  module RailsBootstrapForm
6
6
  module FieldWrapperBuilder
7
- def field_wrapper_builder(attribute, bootstrap_options, options, html_options = nil, &block)
8
- field_options = field_css_options(attribute, bootstrap_options, options, html_options.try(:symbolize_keys!))
7
+ def field_wrapper_builder(attribute, bootstrap, options, html_options = nil, &block)
8
+ field_options = field_css_options(attribute, bootstrap, options, html_options.try(:symbolize_keys!))
9
9
 
10
- field_wrapper(attribute, bootstrap_options, field_options, &block)
10
+ field_wrapper(attribute, bootstrap, field_options, &block)
11
11
  end
12
12
 
13
- def field_wrapper(attribute, bootstrap_options, options, &block)
14
- label = draw_label(attribute, options, bootstrap_options)
15
- help_text = help_text(attribute, bootstrap_options)
16
-
17
- if bootstrap_options.layout_horizontal?
18
- tag.div(**field_wrapper_options(bootstrap_options)) do
19
- concat(label)
20
- concat(tag.div(class: bootstrap_options.field_col_wrapper_class) do
21
- concat(input_group_wrapper(attribute, bootstrap_options) do
22
- capture(&block)
23
- end)
24
- concat(help_text)
25
- end)
13
+ def field_wrapper(attribute, bootstrap, options, &block)
14
+ label = draw_label(attribute, options, bootstrap)
15
+ help_text = help_text(attribute, bootstrap)
16
+ wrapper_content = ActiveSupport::SafeBuffer.new
17
+
18
+ if bootstrap.layout_horizontal?
19
+ wrapper_content << label
20
+ wrapper_content << tag.div(class: bootstrap.field_col_wrapper_class) do
21
+ input_group_wrapper(attribute, bootstrap) do
22
+ capture(&block)
23
+ end + help_text
26
24
  end
27
25
  else
28
- if bootstrap_options.floating?
29
- tag.div(**field_wrapper_options(bootstrap_options)) do
30
- concat(input_group_wrapper(attribute, bootstrap_options) do
31
- tag.div(class: floating_label_classes(attribute)) do
32
- concat(capture(&block))
33
- concat(label)
34
- end
35
- end)
36
- concat(help_text)
26
+ if bootstrap.floating?
27
+ wrapper_content << input_group_wrapper(attribute, bootstrap) do
28
+ tag.div(class: floating_label_classes(attribute)) do
29
+ capture(&block) + label
30
+ end
37
31
  end
32
+ wrapper_content << help_text
38
33
  else
39
- tag.div(**field_wrapper_options(bootstrap_options)) do
40
- concat(label)
41
- concat(input_group_wrapper(attribute, bootstrap_options) do
42
- capture(&block)
43
- end)
44
- concat(help_text)
34
+ wrapper_content << label
35
+ wrapper_content << input_group_wrapper(attribute, bootstrap) do
36
+ capture(&block)
45
37
  end
38
+ wrapper_content << help_text
46
39
  end
47
40
  end
41
+
42
+ if bootstrap.wrapper
43
+ tag.div(**field_wrapper_options(bootstrap)) do
44
+ wrapper_content
45
+ end
46
+ else
47
+ wrapper_content
48
+ end
48
49
  end
49
50
 
50
- def field_wrapper_options(bootstrap_options)
51
- wrapper_options = bootstrap_options.wrapper
51
+ def field_wrapper_options(bootstrap)
52
+ wrapper_options = bootstrap.wrapper
52
53
 
53
54
  {}.tap do |option|
54
- option[:class] = field_wrapper_classes(bootstrap_options)
55
+ option[:class] = field_wrapper_classes(bootstrap)
55
56
  option.merge!(wrapper_options.except(:class)) if wrapper_options.is_a?(Hash)
56
57
  end
57
58
  end
58
59
 
59
- def field_wrapper_classes(bootstrap_options)
60
+ def field_wrapper_classes(bootstrap)
60
61
  classes = []
61
- classes << "row" if bootstrap_options.layout_horizontal?
62
- classes << field_wrapper_default_class(bootstrap_options)
63
- classes << bootstrap_options.wrapper[:class]
62
+ classes << "row" if bootstrap.layout_horizontal?
63
+ classes << field_wrapper_default_class(bootstrap)
64
+ classes << bootstrap.wrapper[:class] if bootstrap.wrapper.is_a?(Hash)
64
65
  classes.flatten.compact
65
66
  end
66
67
 
67
- def field_wrapper_default_class(bootstrap_options)
68
- bootstrap_options.layout_inline? ? "col-12" : "mb-3"
68
+ def field_wrapper_default_class(bootstrap)
69
+ bootstrap.layout_inline? ? "col-12" : "mb-3"
69
70
  end
70
71
 
71
- def field_css_options(attribute, bootstrap_options, options, html_options)
72
+ def field_css_options(attribute, bootstrap, options, html_options)
72
73
  css_options = (html_options || options)
73
74
 
74
75
  field_classes = Array(options[:class])
75
76
  field_classes << [
76
- bootstrap_options.field_class,
77
- bootstrap_options.additional_field_class
77
+ bootstrap.field_class,
78
+ bootstrap.additional_field_class
78
79
  ]
79
80
  field_classes << "is-invalid" if is_invalid?(attribute)
80
- if is_size_valid?(bootstrap_options)
81
- field_classes << "#{bootstrap_options.field_class}-#{bootstrap_options.size}"
81
+ if is_size_valid?(bootstrap)
82
+ field_classes << "#{bootstrap.field_class}-#{bootstrap.size}"
82
83
  end
83
84
 
84
85
  css_options[:class] = field_classes.flatten.compact
85
86
  css_options.merge!(required_field_options(attribute, options))
86
87
 
87
- if placeholder_required?(bootstrap_options)
88
- css_options[:placeholder] ||= label_text(attribute, bootstrap_options)
88
+ if placeholder_required?(bootstrap)
89
+ css_options[:placeholder] ||= label_text(attribute, bootstrap)
89
90
  end
90
91
 
91
92
  css_options
@@ -99,8 +100,8 @@ module RailsBootstrapForm
99
100
  classes
100
101
  end
101
102
 
102
- def placeholder_required?(bootstrap_options)
103
- (bootstrap_options.floating? && !bootstrap_options.layout_horizontal?) || bootstrap_options.layout_inline?
103
+ def placeholder_required?(bootstrap)
104
+ (bootstrap.floating? && !bootstrap.layout_horizontal?) || bootstrap.layout_inline?
104
105
  end
105
106
 
106
107
  private :field_wrapper, :field_wrapper_classes, :field_wrapper_default_class,
@@ -10,15 +10,15 @@ module RailsBootstrapForm
10
10
  def self.included(base_class)
11
11
  def render_button(value = nil, options = {}, &block)
12
12
  value, options = nil, value if value.is_a?(Hash)
13
- bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
13
+ bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
14
14
 
15
- button_html = if (bootstrap_options.render_as_button? || block)
15
+ button_html = if (bootstrap.render_as_button? || block)
16
16
  button(value, options, &block)
17
17
  else
18
18
  submit(value, options)
19
19
  end
20
20
 
21
- if bootstrap_options.layout_inline?
21
+ if bootstrap.layout_inline?
22
22
  tag.div(class: "col-12") { button_html }
23
23
  else
24
24
  button_html
@@ -8,10 +8,10 @@ module RailsBootstrapForm
8
8
  extend ActiveSupport::Concern
9
9
 
10
10
  def self.included(base_class)
11
- def check_box_label(attribute, checked_value, options, bootstrap_options, &block)
12
- unless bootstrap_options.skip_label?
11
+ def check_box_label(attribute, checked_value, options, bootstrap, &block)
12
+ unless bootstrap.skip_label?
13
13
  label_options = {
14
- class: check_box_label_class(attribute, bootstrap_options, options)
14
+ class: check_box_label_class(attribute, bootstrap, options)
15
15
  }
16
16
  label_options[:for] = options[:id] if options[:id].present?
17
17
 
@@ -21,23 +21,14 @@ module RailsBootstrapForm
21
21
  attribute
22
22
  end
23
23
 
24
- label_text = check_box_label_text(attribute, options, bootstrap_options, &block)
24
+ label_text = check_box_label_text(attribute, options, bootstrap, &block)
25
25
 
26
26
  label(label_name, label_text, label_options)
27
27
  end
28
28
  end
29
29
 
30
- def check_box_wrapper_options(bootstrap_options)
31
- wrapper_options = bootstrap_options.wrapper
32
-
33
- {}.tap do |option|
34
- option[:class] = check_box_wrapper_classes(bootstrap_options)
35
- option.merge!(wrapper_options.except(:class)) if wrapper_options.is_a?(Hash)
36
- end
37
- end
38
-
39
- def check_box_label_text(attribute, options, bootstrap_options, &block)
40
- block ? capture(&block) : label_text(attribute, bootstrap_options)
30
+ def check_box_label_text(attribute, options, bootstrap, &block)
31
+ block ? capture(&block) : label_text(attribute, bootstrap)
41
32
  end
42
33
 
43
34
  def check_box_value(attribute, value)
@@ -53,33 +44,38 @@ module RailsBootstrapForm
53
44
  classes.flatten.compact
54
45
  end
55
46
 
56
- def check_box_label_class(attribute, bootstrap_options, options)
57
- classes = Array("form-check-label") << bootstrap_options.additional_label_class
58
- classes << "required" if is_field_required?(attribute, options) && !bootstrap_options.inline?
47
+ def check_box_label_class(attribute, bootstrap, options)
48
+ classes = Array("form-check-label") << bootstrap.additional_label_class
49
+ classes << "required" if is_field_required?(attribute, options)
59
50
  classes << "is-invalid" if is_invalid?(attribute)
60
- classes << bootstrap_options.hide_class if bootstrap_options.hide_label?
51
+ classes << bootstrap.hide_class if bootstrap.hide_label?
61
52
  classes.flatten.compact
62
53
  end
63
54
 
64
- def check_box_wrapper_classes(bootstrap_options)
55
+ def check_box_wrapper_classes(bootstrap)
65
56
  classes = Array("form-check")
66
- classes << "form-switch" if bootstrap_options.switch?
67
- classes << "form-check-inline" if bootstrap_options.inline?
68
- if (bootstrap_options.layout_vertical? && !bootstrap_options.inline?)
69
- classes << "mb-3"
70
- end
71
- classes << bootstrap_options.wrapper[:class]
57
+ classes << "form-switch" if bootstrap.switch?
58
+ classes << "form-check-inline" if bootstrap.inline?
72
59
  classes.flatten.compact
73
60
  end
74
61
 
75
- def check_box_container_classes(bootstrap_options)
76
- classes = Array(bootstrap_options.field_col_wrapper_class)
77
- classes << field_offset_class(bootstrap_options.label_col_wrapper_class)
62
+ def check_box_container_classes(bootstrap)
63
+ classes = Array(bootstrap.field_col_wrapper_class)
64
+ classes << field_offset_class(bootstrap.label_col_wrapper_class)
78
65
  classes.flatten.compact
79
66
  end
80
67
 
68
+ def bootstrap_check_box(attribute, value, options, bootstrap)
69
+ options[:class] = check_box_classes(attribute, options)
70
+ check_box_field = check_box_without_bootstrap(attribute, options, value, nil)
71
+ check_box_label = check_box_label(attribute, value, options, bootstrap)
72
+
73
+ check_box_field + check_box_label
74
+ end
75
+
81
76
  private :check_box_label, :check_box_classes, :check_box_label_class,
82
- :check_box_wrapper_classes, :check_box_container_classes
77
+ :check_box_wrapper_classes, :check_box_container_classes,
78
+ :bootstrap_check_box
83
79
  end
84
80
  end
85
81
  end
@@ -8,10 +8,10 @@ module RailsBootstrapForm
8
8
  extend ActiveSupport::Concern
9
9
 
10
10
  def self.included(base_class)
11
- def help_text(attribute, bootstrap_options)
12
- return if bootstrap_options.help_text == false
11
+ def help_text(attribute, bootstrap)
12
+ return if bootstrap.help_text == false
13
13
 
14
- help_text = (bootstrap_options.help_text || scoped_help_text(attribute))
14
+ help_text = (bootstrap.help_text || scoped_help_text(attribute))
15
15
 
16
16
  tag.div(help_text, class: "form-text text-muted") if help_text.present?
17
17
  end
@@ -8,42 +8,42 @@ module RailsBootstrapForm
8
8
  extend ActiveSupport::Concern
9
9
 
10
10
  def self.included(base_class)
11
- def draw_label(attribute, options, bootstrap_options)
12
- unless bootstrap_options.skip_label? && !bootstrap_options.floating?
11
+ def draw_label(attribute, options, bootstrap)
12
+ unless bootstrap.skip_label? && !bootstrap.floating?
13
13
  label_options = {
14
- class: label_classes(attribute, options, bootstrap_options)
14
+ class: label_classes(attribute, options, bootstrap)
15
15
  }
16
16
  label_options[:for] = options[:id] if options[:id].present?
17
- label_text = label_text(attribute, bootstrap_options)
17
+ label_text = label_text(attribute, bootstrap)
18
18
 
19
19
  label(attribute, label_text, label_options)
20
20
  end
21
21
  end
22
22
 
23
- def label_classes(attribute, options, bootstrap_options)
23
+ def label_classes(attribute, options, bootstrap)
24
24
  classes = []
25
- classes << label_layout_classes(bootstrap_options)
26
- classes << bootstrap_options.additional_label_class
27
- classes << bootstrap_options.hide_class if hide_class_required?(bootstrap_options)
25
+ classes << label_layout_classes(bootstrap)
26
+ classes << bootstrap.additional_label_class
27
+ classes << bootstrap.hide_class if hide_class_required?(bootstrap)
28
28
  classes << "required" if is_field_required?(attribute, options)
29
29
  classes << "is-invalid" if is_invalid?(attribute)
30
30
  classes.flatten.compact
31
31
  end
32
32
 
33
- def label_layout_classes(bootstrap_options)
34
- if bootstrap_options.layout_horizontal?
35
- [bootstrap_options.label_col_class, bootstrap_options.label_col_wrapper_class]
33
+ def label_layout_classes(bootstrap)
34
+ if bootstrap.layout_horizontal?
35
+ [bootstrap.label_col_class, bootstrap.label_col_wrapper_class]
36
36
  else
37
- bootstrap_options.label_class
37
+ bootstrap.label_class
38
38
  end
39
39
  end
40
40
 
41
- def label_text(attribute, bootstrap_options)
42
- bootstrap_options.label_text || object&.class.try(:human_attribute_name, attribute)
41
+ def label_text(attribute, bootstrap)
42
+ bootstrap.label_text || object&.class.try(:human_attribute_name, attribute)
43
43
  end
44
44
 
45
- def hide_class_required?(bootstrap_options)
46
- bootstrap_options.hide_label? || (bootstrap_options.layout_inline? && !bootstrap_options.floating?)
45
+ def hide_class_required?(bootstrap)
46
+ bootstrap.hide_label? || (bootstrap.layout_inline? && !bootstrap.floating?)
47
47
  end
48
48
 
49
49
  private :draw_label, :label_classes, :label_text, :label_layout_classes,
@@ -8,11 +8,11 @@ module RailsBootstrapForm
8
8
  extend ActiveSupport::Concern
9
9
 
10
10
  def self.included(base_class)
11
- def radio_button_label(attribute, value, options, bootstrap_options)
12
- unless bootstrap_options.skip_label?
11
+ def radio_button_label(attribute, value, options, bootstrap)
12
+ unless bootstrap.skip_label?
13
13
  label_options = {
14
14
  value: value,
15
- class: radio_button_label_class(attribute, bootstrap_options, options)
15
+ class: radio_button_label_class(attribute, bootstrap, options)
16
16
  }
17
17
  label_options[:for] = options[:id] if options[:id].present?
18
18
 
@@ -22,21 +22,12 @@ module RailsBootstrapForm
22
22
  attribute
23
23
  end
24
24
 
25
- label_text = label_text(attribute, bootstrap_options)
25
+ label_text = label_text(attribute, bootstrap)
26
26
 
27
27
  label(label_name, label_text, label_options)
28
28
  end
29
29
  end
30
30
 
31
- def radio_button_wrapper_options(bootstrap_options)
32
- wrapper_options = bootstrap_options.wrapper
33
-
34
- {}.tap do |option|
35
- option[:class] = radio_button_wrapper_classes(bootstrap_options)
36
- option.merge!(wrapper_options.except(:class)) if wrapper_options.is_a?(Hash)
37
- end
38
- end
39
-
40
31
  def radio_button_value(attribute, value)
41
32
  # label's `for` attribute needs to match checkbox tag's id,
42
33
  # IE sanitized value, IE
@@ -50,30 +41,34 @@ module RailsBootstrapForm
50
41
  classes.flatten.compact
51
42
  end
52
43
 
53
- def radio_button_label_class(attribute, bootstrap_options, options)
54
- classes = Array("form-check-label") << bootstrap_options.additional_label_class
55
- classes << "required" if is_field_required?(attribute, options) && !bootstrap_options.inline?
44
+ def radio_button_label_class(attribute, bootstrap, options)
45
+ classes = Array("form-check-label") << bootstrap.additional_label_class
46
+ classes << "required" if is_field_required?(attribute, options)
56
47
  classes << "is-invalid" if is_invalid?(attribute)
57
- classes << bootstrap_options.hide_class if bootstrap_options.hide_label?
48
+ classes << bootstrap.hide_class if bootstrap.hide_label?
58
49
  classes.flatten.compact
59
50
  end
60
51
 
61
- def radio_button_wrapper_classes(bootstrap_options)
52
+ def radio_button_wrapper_classes(bootstrap)
62
53
  classes = Array("form-check")
63
- classes << "form-check-inline" if bootstrap_options.inline?
64
- if (bootstrap_options.layout_vertical? && !bootstrap_options.inline?)
65
- classes << "mb-3"
66
- end
67
- classes << bootstrap_options.wrapper[:class]
54
+ classes << "form-check-inline" if bootstrap.inline?
68
55
  classes.flatten.compact
69
56
  end
70
57
 
71
- def radio_button_container_classes(bootstrap_options)
72
- classes = Array(bootstrap_options.field_col_wrapper_class)
73
- classes << field_offset_class(bootstrap_options.label_col_wrapper_class)
58
+ def radio_button_container_classes(bootstrap)
59
+ classes = Array(bootstrap.field_col_wrapper_class)
60
+ classes << field_offset_class(bootstrap.label_col_wrapper_class)
74
61
  classes.flatten.compact
75
62
  end
76
63
 
64
+ def bootstrap_radio_button(attribute, value, options, bootstrap)
65
+ options[:class] = radio_button_classes(attribute, options)
66
+ radio_button_field = radio_button_without_bootstrap(attribute, value, options)
67
+ radio_button_label = radio_button_label(attribute, value, options, bootstrap)
68
+
69
+ radio_button_field + radio_button_label
70
+ end
71
+
77
72
  private :radio_button_label, :radio_button_classes, :radio_button_label_class,
78
73
  :radio_button_wrapper_classes, :radio_button_container_classes
79
74
  end
@@ -33,8 +33,8 @@ module RailsBootstrapForm
33
33
  "rails-bootstrap-forms-#{field_tag_name.to_s.tr("_", "-")}"
34
34
  end
35
35
 
36
- def is_size_valid?(bootstrap_options)
37
- bootstrap_options.size && %i(sm lg).include?(bootstrap_options.size)
36
+ def is_size_valid?(bootstrap)
37
+ bootstrap.size && %i(sm lg).include?(bootstrap.size)
38
38
  end
39
39
 
40
40
  def field_offset_class(label_col_wrapper_class)
@@ -7,17 +7,17 @@ module RailsBootstrapForm
7
7
  extend ActiveSupport::Concern
8
8
 
9
9
  def self.included(base_class)
10
- def input_group_wrapper(attribute, bootstrap_options, &block)
10
+ def input_group_wrapper(attribute, bootstrap, &block)
11
11
  input = capture(&block) || ActiveSupport::SafeBuffer.new
12
12
 
13
- if input_group_required?(bootstrap_options)
14
- prepend = attach_input(bootstrap_options, :prepend)
15
- append = attach_input(bootstrap_options, :append)
13
+ if input_group_required?(bootstrap)
14
+ prepend = attach_input(bootstrap, :prepend)
15
+ append = attach_input(bootstrap, :append)
16
16
 
17
17
  input = prepend + input + append
18
18
  input += generate_error(attribute)
19
19
 
20
- input = tag.div(input, class: input_group_classes(attribute, bootstrap_options))
20
+ input = tag.div(input, class: input_group_classes(attribute, bootstrap))
21
21
  else
22
22
  input += generate_error(attribute)
23
23
  end
@@ -25,18 +25,18 @@ module RailsBootstrapForm
25
25
  input
26
26
  end
27
27
 
28
- def input_group_classes(attribute, bootstrap_options)
29
- classes = Array("input-group") << bootstrap_options.additional_input_group_class
30
- if is_size_valid?(bootstrap_options)
31
- classes << "input-group-#{bootstrap_options.size}"
28
+ def input_group_classes(attribute, bootstrap)
29
+ classes = Array("input-group") << bootstrap.additional_input_group_class
30
+ if is_size_valid?(bootstrap)
31
+ classes << "input-group-#{bootstrap.size}"
32
32
  end
33
33
  # Require `has-validation` class if field has errors.
34
34
  classes << "has-validation" if is_invalid?(attribute)
35
35
  classes.flatten.compact
36
36
  end
37
37
 
38
- def attach_input(bootstrap_options, key)
39
- tags = [*bootstrap_options.send(key)].map do |item|
38
+ def attach_input(bootstrap, key)
39
+ tags = [*bootstrap.send(key)].map do |item|
40
40
  input_group_content(item)
41
41
  end
42
42
 
@@ -49,10 +49,10 @@ module RailsBootstrapForm
49
49
  tag.span(content.html_safe, class: "input-group-text")
50
50
  end
51
51
 
52
- def input_group_required?(bootstrap_options)
52
+ def input_group_required?(bootstrap)
53
53
  [
54
- bootstrap_options.prepend,
55
- bootstrap_options.append
54
+ bootstrap.prepend,
55
+ bootstrap.append
56
56
  ].any?(&:present?)
57
57
  end
58
58
 
@@ -8,23 +8,24 @@ module RailsBootstrapForm
8
8
  extend ActiveSupport::Concern
9
9
 
10
10
  included do
11
- def inputs_collection(attribute, collection, value_method, text_method, bootstrap_options, options = {})
11
+ def inputs_collection(attribute, collection, value_method, text_method, bootstrap, options = {})
12
12
  inputs = ActiveSupport::SafeBuffer.new
13
13
 
14
14
  collection.each do |object|
15
+ value = object.send(value_method)
15
16
  input_options = {
16
17
  bootstrap: {
17
18
  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
- }
19
+ inline: bootstrap.inline?
20
+ },
21
+ required: false
21
22
  }.deep_merge!(options)
22
23
 
23
24
  if (checked = input_options[:checked])
24
- input_options[:checked] = collection_input_checked?(checked, object, object.send(value_method))
25
+ input_options[:checked] = collection_input_checked?(checked, object, value)
25
26
  end
26
27
 
27
- input_value = value_method.respond_to?(:call) ? value_method.call(object) : object.send(value_method)
28
+ input_value = value_method.respond_to?(:call) ? value_method.call(object) : value
28
29
 
29
30
  inputs << yield(attribute, input_value, input_options)
30
31
  end
@@ -36,10 +37,10 @@ module RailsBootstrapForm
36
37
  class_methods do
37
38
  def bootstrap_field(field_name)
38
39
  define_method(field_name) do |attribute, options = {}|
39
- bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
40
- return super(attribute, options) if bootstrap_options.disabled?
40
+ bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
41
+ return super(attribute, options) if bootstrap.disabled?
41
42
 
42
- field_wrapper_builder(attribute, bootstrap_options, options) do
43
+ field_wrapper_builder(attribute, bootstrap, options) do
43
44
  super(attribute, options)
44
45
  end
45
46
  end
@@ -49,10 +50,10 @@ module RailsBootstrapForm
49
50
  define_method(field_name) do |attribute, options = {}, html_options = {}|
50
51
  options = {bootstrap: {field_class: "form-select"}}.deep_merge!(options)
51
52
 
52
- bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
53
- return super(attribute, options, html_options) if bootstrap_options.disabled?
53
+ bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
54
+ return super(attribute, options, html_options) if bootstrap.disabled?
54
55
 
55
- field_wrapper_builder(attribute, bootstrap_options, options, html_options) do
56
+ field_wrapper_builder(attribute, bootstrap, options, html_options) do
56
57
  tag.fieldset(class: control_specific_class(field_name)) do
57
58
  super(attribute, options, html_options)
58
59
  end
@@ -9,31 +9,23 @@ module RailsBootstrapForm
9
9
 
10
10
  included do
11
11
  def check_box(attribute, options = {}, checked_value = "1", unchecked_value = "0", &block)
12
- bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
13
- return super if bootstrap_options.disabled?
12
+ bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
13
+ return super if bootstrap.disabled?
14
14
 
15
- options[:class] = check_box_classes(attribute, options)
16
-
17
- check_box_field = super(attribute, options, checked_value, unchecked_value)
18
- check_box_help_text = help_text(attribute, bootstrap_options)
19
-
20
- check_box_label = check_box_label(attribute, checked_value, options, bootstrap_options, &block)
21
-
22
- check_box_html = tag.div(**check_box_wrapper_options(bootstrap_options)) do
23
- concat(check_box_field)
24
- concat(check_box_label)
25
- concat(check_box_help_text)
26
- concat(generate_error(attribute)) if (is_invalid?(attribute) && !bootstrap_options.inline?)
15
+ check_box_html = tag.div(class: check_box_wrapper_classes(bootstrap)) do
16
+ concat(bootstrap_check_box(attribute, checked_value, options, bootstrap))
17
+ concat(help_text(attribute, bootstrap))
18
+ concat(generate_error(attribute)) if is_invalid?(attribute)
27
19
  end
28
20
 
29
- if (bootstrap_options.layout_horizontal? && !bootstrap_options.inline?)
30
- tag.div(class: field_wrapper_classes(bootstrap_options)) do
31
- tag.div(class: check_box_container_classes(bootstrap_options)) do
21
+ if bootstrap.wrapper
22
+ tag.div(**field_wrapper_options(bootstrap)) do
23
+ if bootstrap.layout_horizontal?
24
+ tag.div(class: check_box_container_classes(bootstrap)) { check_box_html }
25
+ else
32
26
  check_box_html
33
27
  end
34
28
  end
35
- elsif bootstrap_options.layout_inline?
36
- tag.div(class: "col-12") { check_box_html }
37
29
  else
38
30
  check_box_html
39
31
  end
@@ -9,18 +9,24 @@ module RailsBootstrapForm
9
9
 
10
10
  included do
11
11
  def collection_check_boxes(attribute, collection, value_method, text_method, options = {}, html_options = {})
12
- bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
13
- return super if bootstrap_options.disabled?
12
+ bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
13
+ return super if bootstrap.disabled?
14
14
 
15
- inputs = inputs_collection(attribute, collection, value_method, text_method, bootstrap_options, options) do |attribute, value, options|
16
- check_box(attribute, options, value, nil)
15
+ inputs = inputs_collection(attribute, collection, value_method, text_method, bootstrap, options) do |attribute, value, options|
16
+ bootstrap_opts = bootstrap_form_options.scoped(options.delete(:bootstrap))
17
+
18
+ check_box_html = tag.div(class: check_box_wrapper_classes(bootstrap_opts)) do
19
+ bootstrap_check_box(attribute, value, options, bootstrap_opts)
20
+ end
21
+
22
+ check_box_html
17
23
  end
18
24
 
19
25
  if options.delete(:include_hidden) { true }
20
26
  inputs.prepend(hidden_field(attribute, value: "", multiple: options[:multiple]))
21
27
  end
22
28
 
23
- field_wrapper_builder(attribute, bootstrap_options, options, html_options) do
29
+ field_wrapper_builder(attribute, bootstrap, options, html_options) do
24
30
  concat(tag.div(class: control_specific_class(:collection_check_boxes)) do
25
31
  concat(inputs)
26
32
  end)
@@ -9,14 +9,20 @@ module RailsBootstrapForm
9
9
 
10
10
  included do
11
11
  def collection_radio_buttons(attribute, collection, value_method, text_method, options = {}, html_options = {})
12
- bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
13
- return super if bootstrap_options.disabled?
12
+ bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
13
+ return super if bootstrap.disabled?
14
14
 
15
- inputs = inputs_collection(attribute, collection, value_method, text_method, bootstrap_options, options) do |attribute, value, options|
16
- radio_button(attribute, value, options)
15
+ inputs = inputs_collection(attribute, collection, value_method, text_method, bootstrap, options) do |attribute, value, options|
16
+ bootstrap_opts = bootstrap_form_options.scoped(options.delete(:bootstrap))
17
+
18
+ bootstrap_radio_html = tag.div(class: radio_button_wrapper_classes(bootstrap_opts)) do
19
+ bootstrap_radio_button(attribute, value, options, bootstrap_opts)
20
+ end
21
+
22
+ bootstrap_radio_html
17
23
  end
18
24
 
19
- field_wrapper_builder(attribute, bootstrap_options, options, html_options) do
25
+ field_wrapper_builder(attribute, bootstrap, options, html_options) do
20
26
  concat(tag.div(class: control_specific_class(:collection_radio_buttons)) do
21
27
  concat(inputs)
22
28
  end)
@@ -11,10 +11,10 @@ module RailsBootstrapForm
11
11
  def collection_select(attribute, collection, value_method, text_method, options = {}, html_options = {})
12
12
  options = {bootstrap: {field_class: "form-select"}}.deep_merge!(options)
13
13
 
14
- bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
- return super if bootstrap_options.disabled?
14
+ bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
+ return super if bootstrap.disabled?
16
16
 
17
- field_wrapper_builder(attribute, bootstrap_options, options, html_options) do
17
+ field_wrapper_builder(attribute, bootstrap, options, html_options) do
18
18
  super(attribute, collection, value_method, text_method, options, html_options)
19
19
  end
20
20
  end
@@ -11,10 +11,10 @@ module RailsBootstrapForm
11
11
  def color_field(attribute, options = {})
12
12
  options = {bootstrap: {field_class: "form-control form-control-color"}}.deep_merge!(options)
13
13
 
14
- bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
- return super if bootstrap_options.disabled?
14
+ bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
+ return super if bootstrap.disabled?
16
16
 
17
- field_wrapper_builder(attribute, bootstrap_options, options) do
17
+ field_wrapper_builder(attribute, bootstrap, options) do
18
18
  super(attribute, options)
19
19
  end
20
20
  end
@@ -11,10 +11,10 @@ module RailsBootstrapForm
11
11
  def grouped_collection_select(attribute, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {})
12
12
  options = {bootstrap: {field_class: "form-select"}}.deep_merge!(options)
13
13
 
14
- bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
- return super if bootstrap_options.disabled?
14
+ bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
+ return super if bootstrap.disabled?
16
16
 
17
- field_wrapper_builder(attribute, bootstrap_options, options, html_options) do
17
+ field_wrapper_builder(attribute, bootstrap, options, html_options) do
18
18
  super(attribute, collection, group_method, group_label_method, option_key_method, option_value_method, options, html_options)
19
19
  end
20
20
  end
@@ -9,31 +9,23 @@ module RailsBootstrapForm
9
9
 
10
10
  included do
11
11
  def radio_button(attribute, value, options = {})
12
- bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
13
- return super if bootstrap_options.disabled?
12
+ bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
13
+ return super if bootstrap.disabled?
14
14
 
15
- options[:class] = radio_button_classes(attribute, options)
16
-
17
- radio_button_field = super(attribute, value, options)
18
- radio_button_help_text = help_text(attribute, bootstrap_options)
19
-
20
- radio_button_label = radio_button_label(attribute, value, options, bootstrap_options)
21
-
22
- radio_button_html = tag.div(**radio_button_wrapper_options(bootstrap_options)) do
23
- concat(radio_button_field)
24
- concat(radio_button_label)
25
- concat(radio_button_help_text)
26
- concat(generate_error(attribute)) if (is_invalid?(attribute) && !bootstrap_options.inline?)
15
+ radio_button_html = tag.div(class: radio_button_wrapper_classes(bootstrap)) do
16
+ concat(bootstrap_radio_button(attribute, value, options, bootstrap))
17
+ concat(help_text(attribute, bootstrap))
18
+ concat(generate_error(attribute)) if is_invalid?(attribute)
27
19
  end
28
20
 
29
- if (bootstrap_options.layout_horizontal? && !bootstrap_options.inline?)
30
- tag.div(class: field_wrapper_classes(bootstrap_options)) do
31
- tag.div(class: radio_button_container_classes(bootstrap_options)) do
21
+ if bootstrap.wrapper
22
+ tag.div(**field_wrapper_options(bootstrap)) do
23
+ if bootstrap.layout_horizontal?
24
+ tag.div(class: radio_button_container_classes(bootstrap)) { radio_button_html }
25
+ else
32
26
  radio_button_html
33
27
  end
34
28
  end
35
- elsif bootstrap_options.layout_inline?
36
- tag.div(class: "col-12") { radio_button_html }
37
29
  else
38
30
  radio_button_html
39
31
  end
@@ -11,10 +11,10 @@ module RailsBootstrapForm
11
11
  def range_field(attribute, options = {})
12
12
  options = {bootstrap: {field_class: "form-range"}}.deep_merge!(options)
13
13
 
14
- bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
- return super if bootstrap_options.disabled?
14
+ bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
+ return super if bootstrap.disabled?
16
16
 
17
- field_wrapper_builder(attribute, bootstrap_options, options) do
17
+ field_wrapper_builder(attribute, bootstrap, options) do
18
18
  super(attribute, options)
19
19
  end
20
20
  end
@@ -11,10 +11,10 @@ module RailsBootstrapForm
11
11
  def rich_text_area(attribute, options = {})
12
12
  options[:class] = ["trix-content", options[:class]].compact.join(" ")
13
13
 
14
- bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
- return super if bootstrap_options.disabled?
14
+ bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
+ return super if bootstrap.disabled?
16
16
 
17
- field_wrapper_builder(attribute, bootstrap_options, options) do
17
+ field_wrapper_builder(attribute, bootstrap, options) do
18
18
  super(attribute, options)
19
19
  end
20
20
  end
@@ -11,10 +11,10 @@ module RailsBootstrapForm
11
11
  def select(attribute, choices = nil, options = {}, html_options = {}, &block)
12
12
  options = {bootstrap: {field_class: "form-select"}}.deep_merge!(options)
13
13
 
14
- bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
- return super if bootstrap_options.disabled?
14
+ bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
+ return super if bootstrap.disabled?
16
16
 
17
- field_wrapper_builder(attribute, bootstrap_options, options, html_options) do
17
+ field_wrapper_builder(attribute, bootstrap, options, html_options) do
18
18
  super(attribute, choices, options, html_options, &block)
19
19
  end
20
20
  end
@@ -11,10 +11,10 @@ module RailsBootstrapForm
11
11
  def time_zone_select(attribute, priority_zones = nil, options = {}, html_options = {})
12
12
  options = {bootstrap: {field_class: "form-select"}}.deep_merge!(options)
13
13
 
14
- bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
- return super if bootstrap_options.disabled?
14
+ bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
+ return super if bootstrap.disabled?
16
16
 
17
- field_wrapper_builder(attribute, bootstrap_options, options, html_options) do
17
+ field_wrapper_builder(attribute, bootstrap, options, html_options) do
18
18
  super(attribute, priority_zones, options, html_options)
19
19
  end
20
20
  end
@@ -11,10 +11,10 @@ module RailsBootstrapForm
11
11
  def weekday_select(attribute, options = {}, html_options = {}, &block)
12
12
  options = {bootstrap: {field_class: "form-select"}}.deep_merge!(options)
13
13
 
14
- bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
- return super if bootstrap_options.disabled?
14
+ bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
+ return super if bootstrap.disabled?
16
16
 
17
- field_wrapper_builder(attribute, bootstrap_options, options, html_options) do
17
+ field_wrapper_builder(attribute, bootstrap, options, html_options) do
18
18
  super(attribute, options, html_options, &block)
19
19
  end
20
20
  end
@@ -3,6 +3,6 @@
3
3
  # -*- warn_indent: true -*-
4
4
 
5
5
  module RailsBootstrapForm
6
- VERSION = "0.9.1".freeze
6
+ VERSION = "0.9.2".freeze
7
7
  REQUIRED_RAILS_VERSION = "~> 7.0".freeze
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_bootstrap_form
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harshal LADHE (shivam091)
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-02 00:00:00.000000000 Z
11
+ date: 2023-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: generator_spec