rails_bootstrap_form 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -1
- data/Gemfile.lock +1 -1
- data/README.md +71 -41
- data/lib/rails_bootstrap_form/bootstrap_form_builder.rb +5 -2
- data/lib/rails_bootstrap_form/field_wrapper_builder.rb +50 -49
- data/lib/rails_bootstrap_form/helpers/buttons.rb +3 -3
- data/lib/rails_bootstrap_form/helpers/check_box.rb +26 -30
- data/lib/rails_bootstrap_form/helpers/help_text.rb +3 -3
- data/lib/rails_bootstrap_form/helpers/labels.rb +16 -16
- data/lib/rails_bootstrap_form/helpers/radio_button.rb +21 -26
- data/lib/rails_bootstrap_form/helpers.rb +2 -2
- data/lib/rails_bootstrap_form/input_group_builder.rb +14 -14
- data/lib/rails_bootstrap_form/inputs/base.rb +13 -12
- data/lib/rails_bootstrap_form/inputs/check_box.rb +11 -19
- data/lib/rails_bootstrap_form/inputs/collection_check_boxes.rb +11 -5
- data/lib/rails_bootstrap_form/inputs/collection_radio_buttons.rb +11 -5
- data/lib/rails_bootstrap_form/inputs/collection_select.rb +3 -3
- data/lib/rails_bootstrap_form/inputs/color_field.rb +3 -3
- data/lib/rails_bootstrap_form/inputs/grouped_collection_select.rb +3 -3
- data/lib/rails_bootstrap_form/inputs/radio_button.rb +11 -19
- data/lib/rails_bootstrap_form/inputs/range_field.rb +3 -3
- data/lib/rails_bootstrap_form/inputs/rich_text_area.rb +3 -3
- data/lib/rails_bootstrap_form/inputs/select.rb +3 -3
- data/lib/rails_bootstrap_form/inputs/time_zone_select.rb +3 -3
- data/lib/rails_bootstrap_form/inputs/weekday_select.rb +3 -3
- data/lib/rails_bootstrap_form/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23429dc16ad64529ba65b78cf376ff4bb5b31134bb87b1f8808af1fd32fe0427
|
4
|
+
data.tar.gz: 83785c866c4705460b55cbad301971492f360407b4d91abf49e0f11d25f07070
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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
data/README.md
CHANGED
@@ -103,10 +103,12 @@ This generates the following HTML:
|
|
103
103
|
<label class="form-label required" for="user_password">Password</label>
|
104
104
|
<input class="form-control" aria-required="true" required="required" type="password" name="user[password]" id="user_password">
|
105
105
|
</div>
|
106
|
-
<div class="
|
107
|
-
<
|
108
|
-
|
109
|
-
|
106
|
+
<div class="mb-3">
|
107
|
+
<div class="form-check">
|
108
|
+
<input class="form-check-input" type="checkbox" value="1" name="user[terms]" id="user_terms">
|
109
|
+
<label class="form-check-label" for="user_terms">I accept terms and conditions</label>
|
110
|
+
<div class="form-text text-muted">You must first accept terms and conditions in order to continue</div>
|
111
|
+
</div>
|
110
112
|
</div>
|
111
113
|
<input type="submit" name="commit" value="Log In" class="btn btn-primary" data-disable-with="Log In">
|
112
114
|
</form>
|
@@ -139,10 +141,12 @@ This generates the following HTML:
|
|
139
141
|
<label class="form-label required" for="user_password">Password</label>
|
140
142
|
<input class="form-control" aria-required="true" required="required" type="password" name="user[password]" id="user_password">
|
141
143
|
</div>
|
142
|
-
<div class="
|
143
|
-
<
|
144
|
-
|
145
|
-
|
144
|
+
<div class="mb-3">
|
145
|
+
<div class="form-check">
|
146
|
+
<input class="form-check-input" type="checkbox" value="1" name="user[terms]" id="user_terms">
|
147
|
+
<label class="form-check-label" for="user_terms">I accept terms and conditions</label>
|
148
|
+
<div class="form-text text-muted">You must first accept terms and conditions in order to continue</div>
|
149
|
+
</div>
|
146
150
|
</div>
|
147
151
|
<input type="submit" name="commit" value="Log In" class="btn btn-primary" data-disable-with="Log In">
|
148
152
|
</form>
|
@@ -171,7 +175,7 @@ Here's a list of all possible options you can pass via `bootstrap` option that c
|
|
171
175
|
| `floating` | An option to control whether the field should have a floating label. | `false` |
|
172
176
|
| `static_field_class` | A CSS class that will be applied to all static fields. | `form-control-plaintext` |
|
173
177
|
| `switch` | An option to control whether the check box should look like Bootstrap switches. | `false` |
|
174
|
-
| `wrapper` | An option to control the HTML attributes and options that will be added to a field wrapper. | `{}` |
|
178
|
+
| `wrapper` | An option to control the HTML attributes and options that will be added to a field wrapper. You can set it false if you don't the field to be rendered in a wrapper. | `{}` |
|
175
179
|
| `size` | An option to control the size of input groups, buttons, labels, and fields. It can be `sm` or `lg`. | `nil` |
|
176
180
|
| `inline` | An option to group checkboxes and radio buttons on the same horizontal row. | `false` |
|
177
181
|
| `label_col_class` | A CSS class that will be applied to all labels when layout is `horizontal`. | `col-form-label` |
|
@@ -189,7 +193,7 @@ Here's an example of a form where one field uses different layout:
|
|
189
193
|
<%= form.text_field :name %>
|
190
194
|
<%= form.email_field :email %>
|
191
195
|
<%= form.password_field :password, bootstrap: {layout: :horizontal} %>
|
192
|
-
<%= form.check_box :terms
|
196
|
+
<%= form.check_box :terms %>
|
193
197
|
<%= form.primary "Register" %>
|
194
198
|
<% end %>
|
195
199
|
```
|
@@ -212,11 +216,12 @@ This generates the following HTML:
|
|
212
216
|
<input class="form-control" aria-required="true" required="required" type="password" name="user[password]" id="user_password">
|
213
217
|
</div>
|
214
218
|
</div>
|
215
|
-
<div class="
|
216
|
-
<
|
217
|
-
|
218
|
-
|
219
|
-
|
219
|
+
<div class="mb-3">
|
220
|
+
<div class="form-check">
|
221
|
+
<input class="form-check-input" type="checkbox" value="1" name="user[terms]" id="user_terms">
|
222
|
+
<label class="form-check-label" for="user_terms">I accept terms and conditions</label>
|
223
|
+
<div class="form-text text-muted">You must first accept terms and conditions in order to continue</div>
|
224
|
+
</div>
|
220
225
|
</div>
|
221
226
|
<input type="submit" name="commit" value="Register" class="btn btn-primary" data-disable-with="Register">
|
222
227
|
</form>
|
@@ -230,6 +235,23 @@ You can completely disable bootstrap and use default form builder by passing `di
|
|
230
235
|
<%= form.text_field :username, bootstrap: {disabled: true} %>
|
231
236
|
```
|
232
237
|
|
238
|
+
### Disabling wrapper
|
239
|
+
|
240
|
+
In some cases, you may need to disable the default wrapper. You can do this by passing 'wrapper: false':
|
241
|
+
|
242
|
+
![wrapper_false](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/1693cf0f-7a30-494d-9fb5-394f4fb2c676)
|
243
|
+
|
244
|
+
```erb
|
245
|
+
<%= form.text_field :name, bootstrap: {wrapper: false} %>
|
246
|
+
```
|
247
|
+
|
248
|
+
This generates the following HTML:
|
249
|
+
|
250
|
+
```html
|
251
|
+
<label class="form-label required" for="user_name">Name</label>
|
252
|
+
<input class="form-control" aria-required="true" required="required" type="text" name="user[name]" id="user_name">
|
253
|
+
```
|
254
|
+
|
233
255
|
## Supported Form Helpers
|
234
256
|
|
235
257
|
This gem wraps most of the form field helpers. Here's the current list:
|
@@ -677,10 +699,11 @@ This helper will render check box and label for you.
|
|
677
699
|
This generates the following HTML:
|
678
700
|
|
679
701
|
```html
|
680
|
-
<div class="
|
681
|
-
<
|
682
|
-
|
683
|
-
|
702
|
+
<div class="mb-3">
|
703
|
+
<div class="form-check">
|
704
|
+
<input class="form-check-input" type="checkbox" value="1" name="user[remember_me]" id="user_remember_me">
|
705
|
+
<label class="form-check-label" for="user_remember_me">Keep me signed in</label>
|
706
|
+
</div>
|
684
707
|
</div>
|
685
708
|
```
|
686
709
|
|
@@ -695,10 +718,11 @@ You can set `switch` option to `true` if you want check box to look like switche
|
|
695
718
|
This generates the following HTML:
|
696
719
|
|
697
720
|
```html
|
698
|
-
<div class="
|
699
|
-
<
|
700
|
-
|
701
|
-
|
721
|
+
<div class="mb-3">
|
722
|
+
<div class="form-check form-switch">
|
723
|
+
<input class="form-check-input" type="checkbox" value="1" name="user[remember_me]" id="user_remember_me">
|
724
|
+
<label class="form-check-label" for="user_remember_me">Keep me signed in</label>
|
725
|
+
</div>
|
702
726
|
</div>
|
703
727
|
```
|
704
728
|
|
@@ -713,11 +737,12 @@ This helper also renders help text if `help_text` option is set or information o
|
|
713
737
|
This generates the following HTML:
|
714
738
|
|
715
739
|
```html
|
716
|
-
<div class="
|
717
|
-
<
|
718
|
-
|
719
|
-
|
720
|
-
|
740
|
+
<div class="mb-3">
|
741
|
+
<div class="form-check">
|
742
|
+
<input required="required" class="form-check-input" type="checkbox" value="1" name="user[terms]" id="user_terms">
|
743
|
+
<label class="form-check-label required" for="user_terms">I accept terms and conditions</label>
|
744
|
+
<div class="form-text text-muted">You must first accept terms and conditions in order to continue</div>
|
745
|
+
</div>
|
721
746
|
</div>
|
722
747
|
```
|
723
748
|
|
@@ -872,11 +897,12 @@ This generates the following HTML:
|
|
872
897
|
</select>
|
873
898
|
</div>
|
874
899
|
</div>
|
875
|
-
<div class="
|
876
|
-
<
|
877
|
-
|
878
|
-
|
879
|
-
|
900
|
+
<div class="mb-3">
|
901
|
+
<div class="form-check">
|
902
|
+
<input required="required" class="form-check-input" type="checkbox" value="1" name="user[terms]" id="user_terms">
|
903
|
+
<label class="form-check-label required" for="user_terms">I accept terms and conditions</label>
|
904
|
+
<div class="form-text text-muted">You must first accept terms and conditions in order to continue</div>
|
905
|
+
</div>
|
880
906
|
</div>
|
881
907
|
<input type="submit" name="commit" value="Register" class="btn btn-primary" data-disable-with="Register">
|
882
908
|
</form>
|
@@ -1065,9 +1091,11 @@ This helper will render check box and label for you.
|
|
1065
1091
|
This generates the following HTML:
|
1066
1092
|
|
1067
1093
|
```html
|
1068
|
-
<div class="
|
1069
|
-
<
|
1070
|
-
|
1094
|
+
<div class="mb-3">
|
1095
|
+
<div class="form-check">
|
1096
|
+
<input class="form-check-input" type="radio" value="male" name="user[gender]" id="user_gender_male">
|
1097
|
+
<label class="form-check-label" for="user_gender_male">Male</label>
|
1098
|
+
</div>
|
1071
1099
|
</div>
|
1072
1100
|
```
|
1073
1101
|
|
@@ -1082,10 +1110,12 @@ This helper also renders help text if `help_text` option is set or information o
|
|
1082
1110
|
This generates the following HTML:
|
1083
1111
|
|
1084
1112
|
```html
|
1085
|
-
<div class="
|
1086
|
-
<
|
1087
|
-
|
1088
|
-
|
1113
|
+
<div class="mb-3">
|
1114
|
+
<div class="form-check">
|
1115
|
+
<input class="form-check-input" type="radio" value="male" name="user[gender]" id="user_gender_male">
|
1116
|
+
<label class="form-check-label" for="user_gender_male">Male</label>
|
1117
|
+
<div class="form-text text-muted">Please select your gender</div>
|
1118
|
+
</div>
|
1089
1119
|
</div>
|
1090
1120
|
```
|
1091
1121
|
|
@@ -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
|
-
|
46
|
-
fields_options =
|
48
|
+
bootstrap = {bootstrap: options.fetch(:bootstrap, {})}
|
49
|
+
fields_options = bootstrap.deep_merge!(fields_options)
|
47
50
|
fields_options
|
48
51
|
end
|
49
52
|
|
@@ -4,88 +4,89 @@
|
|
4
4
|
|
5
5
|
module RailsBootstrapForm
|
6
6
|
module FieldWrapperBuilder
|
7
|
-
def field_wrapper_builder(attribute,
|
8
|
-
field_options = field_css_options(attribute,
|
7
|
+
def field_wrapper_builder(attribute, bootstrap, options, html_options = nil, &block)
|
8
|
+
field_options = field_css_options(attribute, bootstrap, options, html_options.try(:symbolize_keys!))
|
9
9
|
|
10
|
-
field_wrapper(attribute,
|
10
|
+
field_wrapper(attribute, bootstrap, field_options, &block)
|
11
11
|
end
|
12
12
|
|
13
|
-
def field_wrapper(attribute,
|
14
|
-
label = draw_label(attribute, options,
|
15
|
-
help_text = help_text(attribute,
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
concat(help_text)
|
25
|
-
end)
|
13
|
+
def field_wrapper(attribute, bootstrap, options, &block)
|
14
|
+
label = draw_label(attribute, options, bootstrap)
|
15
|
+
help_text = help_text(attribute, bootstrap)
|
16
|
+
wrapper_content = ActiveSupport::SafeBuffer.new
|
17
|
+
|
18
|
+
if bootstrap.layout_horizontal?
|
19
|
+
wrapper_content << label
|
20
|
+
wrapper_content << tag.div(class: bootstrap.field_col_wrapper_class) do
|
21
|
+
input_group_wrapper(attribute, bootstrap) do
|
22
|
+
capture(&block)
|
23
|
+
end + help_text
|
26
24
|
end
|
27
25
|
else
|
28
|
-
if
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
concat(label)
|
34
|
-
end
|
35
|
-
end)
|
36
|
-
concat(help_text)
|
26
|
+
if bootstrap.floating?
|
27
|
+
wrapper_content << input_group_wrapper(attribute, bootstrap) do
|
28
|
+
tag.div(class: floating_label_classes(attribute)) do
|
29
|
+
capture(&block) + label
|
30
|
+
end
|
37
31
|
end
|
32
|
+
wrapper_content << help_text
|
38
33
|
else
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
capture(&block)
|
43
|
-
end)
|
44
|
-
concat(help_text)
|
34
|
+
wrapper_content << label
|
35
|
+
wrapper_content << input_group_wrapper(attribute, bootstrap) do
|
36
|
+
capture(&block)
|
45
37
|
end
|
38
|
+
wrapper_content << help_text
|
46
39
|
end
|
47
40
|
end
|
41
|
+
|
42
|
+
if bootstrap.wrapper
|
43
|
+
tag.div(**field_wrapper_options(bootstrap)) do
|
44
|
+
wrapper_content
|
45
|
+
end
|
46
|
+
else
|
47
|
+
wrapper_content
|
48
|
+
end
|
48
49
|
end
|
49
50
|
|
50
|
-
def field_wrapper_options(
|
51
|
-
wrapper_options =
|
51
|
+
def field_wrapper_options(bootstrap)
|
52
|
+
wrapper_options = bootstrap.wrapper
|
52
53
|
|
53
54
|
{}.tap do |option|
|
54
|
-
option[:class] = field_wrapper_classes(
|
55
|
+
option[:class] = field_wrapper_classes(bootstrap)
|
55
56
|
option.merge!(wrapper_options.except(:class)) if wrapper_options.is_a?(Hash)
|
56
57
|
end
|
57
58
|
end
|
58
59
|
|
59
|
-
def field_wrapper_classes(
|
60
|
+
def field_wrapper_classes(bootstrap)
|
60
61
|
classes = []
|
61
|
-
classes << "row" if
|
62
|
-
classes << field_wrapper_default_class(
|
63
|
-
classes <<
|
62
|
+
classes << "row" if bootstrap.layout_horizontal?
|
63
|
+
classes << field_wrapper_default_class(bootstrap)
|
64
|
+
classes << bootstrap.wrapper[:class] if bootstrap.wrapper.is_a?(Hash)
|
64
65
|
classes.flatten.compact
|
65
66
|
end
|
66
67
|
|
67
|
-
def field_wrapper_default_class(
|
68
|
-
|
68
|
+
def field_wrapper_default_class(bootstrap)
|
69
|
+
bootstrap.layout_inline? ? "col-12" : "mb-3"
|
69
70
|
end
|
70
71
|
|
71
|
-
def field_css_options(attribute,
|
72
|
+
def field_css_options(attribute, bootstrap, options, html_options)
|
72
73
|
css_options = (html_options || options)
|
73
74
|
|
74
75
|
field_classes = Array(options[:class])
|
75
76
|
field_classes << [
|
76
|
-
|
77
|
-
|
77
|
+
bootstrap.field_class,
|
78
|
+
bootstrap.additional_field_class
|
78
79
|
]
|
79
80
|
field_classes << "is-invalid" if is_invalid?(attribute)
|
80
|
-
if is_size_valid?(
|
81
|
-
field_classes << "#{
|
81
|
+
if is_size_valid?(bootstrap)
|
82
|
+
field_classes << "#{bootstrap.field_class}-#{bootstrap.size}"
|
82
83
|
end
|
83
84
|
|
84
85
|
css_options[:class] = field_classes.flatten.compact
|
85
86
|
css_options.merge!(required_field_options(attribute, options))
|
86
87
|
|
87
|
-
if placeholder_required?(
|
88
|
-
css_options[:placeholder] ||= label_text(attribute,
|
88
|
+
if placeholder_required?(bootstrap)
|
89
|
+
css_options[:placeholder] ||= label_text(attribute, bootstrap)
|
89
90
|
end
|
90
91
|
|
91
92
|
css_options
|
@@ -99,8 +100,8 @@ module RailsBootstrapForm
|
|
99
100
|
classes
|
100
101
|
end
|
101
102
|
|
102
|
-
def placeholder_required?(
|
103
|
-
(
|
103
|
+
def placeholder_required?(bootstrap)
|
104
|
+
(bootstrap.floating? && !bootstrap.layout_horizontal?) || bootstrap.layout_inline?
|
104
105
|
end
|
105
106
|
|
106
107
|
private :field_wrapper, :field_wrapper_classes, :field_wrapper_default_class,
|
@@ -10,15 +10,15 @@ module RailsBootstrapForm
|
|
10
10
|
def self.included(base_class)
|
11
11
|
def render_button(value = nil, options = {}, &block)
|
12
12
|
value, options = nil, value if value.is_a?(Hash)
|
13
|
-
|
13
|
+
bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
|
14
14
|
|
15
|
-
button_html = if (
|
15
|
+
button_html = if (bootstrap.render_as_button? || block)
|
16
16
|
button(value, options, &block)
|
17
17
|
else
|
18
18
|
submit(value, options)
|
19
19
|
end
|
20
20
|
|
21
|
-
if
|
21
|
+
if bootstrap.layout_inline?
|
22
22
|
tag.div(class: "col-12") { button_html }
|
23
23
|
else
|
24
24
|
button_html
|
@@ -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,
|
12
|
-
unless
|
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,
|
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,
|
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
|
31
|
-
|
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,
|
57
|
-
classes = Array("form-check-label") <<
|
58
|
-
classes << "required" if is_field_required?(attribute, options)
|
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 <<
|
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(
|
55
|
+
def check_box_wrapper_classes(bootstrap)
|
65
56
|
classes = Array("form-check")
|
66
|
-
classes << "form-switch" if
|
67
|
-
classes << "form-check-inline" if
|
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(
|
76
|
-
classes = Array(
|
77
|
-
classes << field_offset_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,
|
12
|
-
return if
|
11
|
+
def help_text(attribute, bootstrap)
|
12
|
+
return if bootstrap.help_text == false
|
13
13
|
|
14
|
-
help_text = (
|
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,
|
12
|
-
unless
|
11
|
+
def draw_label(attribute, options, bootstrap)
|
12
|
+
unless bootstrap.skip_label? && !bootstrap.floating?
|
13
13
|
label_options = {
|
14
|
-
class: label_classes(attribute, 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,
|
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,
|
23
|
+
def label_classes(attribute, options, bootstrap)
|
24
24
|
classes = []
|
25
|
-
classes << label_layout_classes(
|
26
|
-
classes <<
|
27
|
-
classes <<
|
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(
|
34
|
-
if
|
35
|
-
[
|
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
|
-
|
37
|
+
bootstrap.label_class
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
def label_text(attribute,
|
42
|
-
|
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?(
|
46
|
-
|
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,
|
12
|
-
unless
|
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,
|
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,
|
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,
|
54
|
-
classes = Array("form-check-label") <<
|
55
|
-
classes << "required" if is_field_required?(attribute, options)
|
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 <<
|
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(
|
52
|
+
def radio_button_wrapper_classes(bootstrap)
|
62
53
|
classes = Array("form-check")
|
63
|
-
classes << "form-check-inline" if
|
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(
|
72
|
-
classes = Array(
|
73
|
-
classes << field_offset_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?(
|
37
|
-
|
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,
|
10
|
+
def input_group_wrapper(attribute, bootstrap, &block)
|
11
11
|
input = capture(&block) || ActiveSupport::SafeBuffer.new
|
12
12
|
|
13
|
-
if input_group_required?(
|
14
|
-
prepend = attach_input(
|
15
|
-
append = attach_input(
|
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,
|
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,
|
29
|
-
classes = Array("input-group") <<
|
30
|
-
if is_size_valid?(
|
31
|
-
classes << "input-group-#{
|
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(
|
39
|
-
tags = [*
|
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?(
|
52
|
+
def input_group_required?(bootstrap)
|
53
53
|
[
|
54
|
-
|
55
|
-
|
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,
|
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
|
-
|
19
|
-
|
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,
|
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) :
|
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
|
-
|
40
|
-
return super(attribute, options) if
|
40
|
+
bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
|
41
|
+
return super(attribute, options) if bootstrap.disabled?
|
41
42
|
|
42
|
-
field_wrapper_builder(attribute,
|
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
|
-
|
53
|
-
return super(attribute, options, html_options) if
|
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,
|
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
|
-
|
13
|
-
return super if
|
12
|
+
bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
|
13
|
+
return super if bootstrap.disabled?
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
30
|
-
tag.div(
|
31
|
-
|
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
|
-
|
13
|
-
return super if
|
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,
|
16
|
-
|
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,
|
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
|
-
|
13
|
-
return super if
|
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,
|
16
|
-
|
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,
|
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
|
-
|
15
|
-
return super if
|
14
|
+
bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
|
15
|
+
return super if bootstrap.disabled?
|
16
16
|
|
17
|
-
field_wrapper_builder(attribute,
|
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
|
-
|
15
|
-
return super if
|
14
|
+
bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
|
15
|
+
return super if bootstrap.disabled?
|
16
16
|
|
17
|
-
field_wrapper_builder(attribute,
|
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
|
-
|
15
|
-
return super if
|
14
|
+
bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
|
15
|
+
return super if bootstrap.disabled?
|
16
16
|
|
17
|
-
field_wrapper_builder(attribute,
|
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
|
-
|
13
|
-
return super if
|
12
|
+
bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
|
13
|
+
return super if bootstrap.disabled?
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
30
|
-
tag.div(
|
31
|
-
|
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
|
-
|
15
|
-
return super if
|
14
|
+
bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
|
15
|
+
return super if bootstrap.disabled?
|
16
16
|
|
17
|
-
field_wrapper_builder(attribute,
|
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
|
-
|
15
|
-
return super if
|
14
|
+
bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
|
15
|
+
return super if bootstrap.disabled?
|
16
16
|
|
17
|
-
field_wrapper_builder(attribute,
|
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
|
-
|
15
|
-
return super if
|
14
|
+
bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
|
15
|
+
return super if bootstrap.disabled?
|
16
16
|
|
17
|
-
field_wrapper_builder(attribute,
|
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
|
-
|
15
|
-
return super if
|
14
|
+
bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
|
15
|
+
return super if bootstrap.disabled?
|
16
16
|
|
17
|
-
field_wrapper_builder(attribute,
|
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
|
-
|
15
|
-
return super if
|
14
|
+
bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
|
15
|
+
return super if bootstrap.disabled?
|
16
16
|
|
17
|
-
field_wrapper_builder(attribute,
|
17
|
+
field_wrapper_builder(attribute, bootstrap, options, html_options) do
|
18
18
|
super(attribute, options, html_options, &block)
|
19
19
|
end
|
20
20
|
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.
|
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-
|
11
|
+
date: 2023-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: generator_spec
|