comfy_bootstrap_form 4.0.0.beta2 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +103 -0
- data/.travis.yml +3 -0
- data/Gemfile +6 -2
- data/README.md +63 -25
- data/Rakefile +12 -12
- data/bootstrap_form.gemspec +1 -1
- data/demo/app/controllers/bootstrap_controller.rb +9 -3
- data/demo/app/views/bootstrap/form.html.erb +110 -65
- data/demo/db/schema.rb +3 -0
- data/demo/form_preview_horizontal.png +0 -0
- data/demo/form_preview_horizontal_with_errors.png +0 -0
- data/demo/form_preview_inline.png +0 -0
- data/demo/form_preview_vertical.png +0 -0
- data/lib/bootstrap_form/bootstrap_options.rb +115 -0
- data/lib/bootstrap_form/form_builder.rb +96 -133
- data/lib/bootstrap_form/version.rb +3 -1
- data/lib/bootstrap_form/view_helper.rb +2 -1
- data/lib/bootstrap_form.rb +2 -2
- data/test/bootstrap_form/bootstrap_options_test.rb +114 -0
- data/test/bootstrap_form/fields_test.rb +5 -5
- data/test/bootstrap_form/fields_with_errors_test.rb +10 -8
- data/test/bootstrap_form/form_builder_test.rb +5 -37
- data/test/bootstrap_form/horizontal_form_test.rb +9 -8
- data/test/bootstrap_form/inline_form_test.rb +2 -2
- data/test/bootstrap_form/input_group_test.rb +10 -7
- data/test/bootstrap_form/radios_and_checkboxes_test.rb +19 -20
- data/test/bootstrap_form/submit_test.rb +1 -1
- data/test/bootstrap_form/view_helpers_test.rb +3 -3
- data/test/gemfiles/5.2.gemfile +1 -0
- data/test/test_helper.rb +5 -5
- metadata +11 -4
@@ -0,0 +1,115 @@
|
|
1
|
+
module BootstrapForm
|
2
|
+
# Container for bootstrap specific form builder options. It controls options
|
3
|
+
# that define form layout and grid sizing. They are passed-in into form helper
|
4
|
+
# and field helpers via `:bootstrap` option. For example:
|
5
|
+
#
|
6
|
+
# bootstrap_form_with scope: :login, url: "/login", bootstrap: {layout: :inline} do |f|
|
7
|
+
# f.text_field :username, bootstrap: {label: {text: "Your username"}}
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
class BootstrapOptions
|
11
|
+
|
12
|
+
# Controls form layout. Can be: "vertical" (default), "horizontal" or "inline"
|
13
|
+
attr_reader :layout
|
14
|
+
|
15
|
+
# CSS class for label column when using horizontal form. Default: "col-sm-2"
|
16
|
+
attr_reader :label_col_class
|
17
|
+
|
18
|
+
# CSS class for control column when using horizontal form. Default: "col-sm-10"
|
19
|
+
attr_reader :control_col_class
|
20
|
+
|
21
|
+
# CSS class for label alignment in horizontal form. Default: "text-sm-right"
|
22
|
+
attr_reader :label_align_class
|
23
|
+
|
24
|
+
# CSS class used to space out form groups for inline forms. Default: "mr-sm-2"
|
25
|
+
attr_reader :inline_margin_class
|
26
|
+
|
27
|
+
# Label specific options. Default is and empty hash. Options are as follows:
|
28
|
+
# text: "Label Text" - override automatically generated label text
|
29
|
+
# hide: true - label only visible to screen readers
|
30
|
+
# class: "custom" - append custom CSS class
|
31
|
+
# Example:
|
32
|
+
#
|
33
|
+
# form.label :username, bootstrap: {label: {text: "Name", class: "important"}}
|
34
|
+
#
|
35
|
+
attr_reader :label
|
36
|
+
|
37
|
+
# Input groups allow prepending and appending arbitrary html. By default
|
38
|
+
# these are nil. Example usage:
|
39
|
+
#
|
40
|
+
# form.text_field :dollars, bootstrap: {prepend: "$", append: ".00"}
|
41
|
+
#
|
42
|
+
# For non-text values, use hash like so:
|
43
|
+
#
|
44
|
+
# form.text_field :search, bootstrap: {append: {html: "<button>Go</button>".html_safe}}
|
45
|
+
#
|
46
|
+
attr_reader :prepend
|
47
|
+
attr_reader :append
|
48
|
+
|
49
|
+
# Help text that goes under the form field. Example usage:
|
50
|
+
#
|
51
|
+
# form.password_field :password, bootstrap: {help: "Password should be more than 8 characters in length"}
|
52
|
+
#
|
53
|
+
attr_reader :help
|
54
|
+
|
55
|
+
# Options to render checkboxes and radio buttons inline. Default is false. Example:
|
56
|
+
#
|
57
|
+
# form.collection_radio_buttons :choices, ["yes", "no"], :to_s, :to_s, bootstrap: {check_inline: true}
|
58
|
+
#
|
59
|
+
attr_reader :check_inline
|
60
|
+
|
61
|
+
def initialize(options = {})
|
62
|
+
set_defaults
|
63
|
+
set_options(options)
|
64
|
+
end
|
65
|
+
|
66
|
+
def horizontal?
|
67
|
+
@layout.to_s == "horizontal"
|
68
|
+
end
|
69
|
+
|
70
|
+
def inline?
|
71
|
+
@layout.to_s == "inline"
|
72
|
+
end
|
73
|
+
|
74
|
+
def offset_col_class
|
75
|
+
label_col_class.sub(%r{\Acol-(\w+)-(\d+)\z}, 'offset-\1-\2')
|
76
|
+
end
|
77
|
+
|
78
|
+
# This will return a copy of BootstrapOptions object with new options set
|
79
|
+
# that don't affect original object. This way we can have options specific
|
80
|
+
# to a given form field. For example, we can change grid just for one field:
|
81
|
+
#
|
82
|
+
# bootstrap_form_with scope: :login do |f|
|
83
|
+
# f.text_field :email, bootstrap: {label_col_class: "col-md-6", control_col_class: "col-md-6"}
|
84
|
+
# f.password_field :password
|
85
|
+
# end
|
86
|
+
#
|
87
|
+
def scoped(options = {})
|
88
|
+
scope = clone
|
89
|
+
scope.set_options(options)
|
90
|
+
scope
|
91
|
+
end
|
92
|
+
|
93
|
+
def set_options(options = {})
|
94
|
+
options.is_a?(Hash) && options.each do |key, value|
|
95
|
+
instance_variable_set("@#{key}", value)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
private
|
100
|
+
|
101
|
+
def set_defaults
|
102
|
+
@layout = "vertical"
|
103
|
+
@label_col_class = "col-sm-2"
|
104
|
+
@control_col_class = "col-sm-10"
|
105
|
+
@label_align_class = "text-sm-right"
|
106
|
+
@inline_margin_class = "mr-sm-2"
|
107
|
+
@label = {}
|
108
|
+
@append = nil
|
109
|
+
@prepend = nil
|
110
|
+
@help = nil
|
111
|
+
@check_inline = false
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
end
|
@@ -1,59 +1,37 @@
|
|
1
|
+
require_relative "bootstrap_options"
|
2
|
+
|
1
3
|
module BootstrapForm
|
2
4
|
class FormBuilder < ActionView::Helpers::FormBuilder
|
3
5
|
|
4
6
|
FIELD_HELPERS = %w[
|
5
|
-
color_field
|
6
|
-
|
7
|
-
|
8
|
-
email_field password_field text_area week_field
|
7
|
+
color_field date_field datetime_field email_field file_field month_field
|
8
|
+
number_field password_field phone_field range_field search_field text_area
|
9
|
+
text_field time_field url_field week_field
|
9
10
|
].freeze
|
10
11
|
|
11
|
-
# Container for bootstrap specific form builder options. It controls options
|
12
|
-
# that define form layout and grid sizing.
|
13
|
-
class BootstrapOptions
|
14
|
-
|
15
|
-
attr_reader :layout,
|
16
|
-
:label_col_class,
|
17
|
-
:control_col_class,
|
18
|
-
:label_align_class,
|
19
|
-
:inline_margin_class
|
20
|
-
|
21
|
-
def initialize(options = {})
|
22
|
-
@layout = options[:layout] || "default"
|
23
|
-
@label_col_class = options[:label_col_class] || "col-sm-2"
|
24
|
-
@control_col_class = options[:control_col_class] || "col-sm-10"
|
25
|
-
@label_align_class = options[:label_align_class] || "text-sm-right"
|
26
|
-
@inline_margin_class = options[:inline_margin_class] || "mr-sm-2"
|
27
|
-
end
|
28
|
-
|
29
|
-
def horizontal?
|
30
|
-
@layout.to_s == "horizontal"
|
31
|
-
end
|
32
|
-
|
33
|
-
def inline?
|
34
|
-
@layout.to_s == "inline"
|
35
|
-
end
|
36
|
-
|
37
|
-
def offset_col_class
|
38
|
-
label_col_class.sub(/\Acol-(\w+)-(\d+)\z/, 'offset-\1-\2')
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
12
|
delegate :content_tag, :capture, :concat, to: :@template
|
44
13
|
|
45
|
-
|
14
|
+
# Bootstrap settings set on the form itself
|
15
|
+
attr_accessor :form_bootstrap
|
46
16
|
|
47
17
|
def initialize(object_name, object, template, options)
|
48
|
-
@
|
18
|
+
@form_bootstrap = BootstrapForm::BootstrapOptions.new(options.delete(:bootstrap))
|
49
19
|
super(object_name, object, template, options)
|
50
20
|
end
|
51
21
|
|
52
|
-
#
|
22
|
+
# Wrapper for all field helpers. Example usage:
|
23
|
+
#
|
24
|
+
# bootstrap_form_with model: @user do |form|
|
25
|
+
# form.text_field :name
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# Output of the `text_field` will be wrapped in Bootstrap markup
|
29
|
+
#
|
53
30
|
FIELD_HELPERS.each do |field_helper|
|
54
31
|
class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
|
55
32
|
def #{field_helper}(method, options = {})
|
56
|
-
|
33
|
+
bootstrap = form_bootstrap.scoped(options.delete(:bootstrap))
|
34
|
+
draw_form_group(bootstrap, method, options) do
|
57
35
|
super(method, options)
|
58
36
|
end
|
59
37
|
end
|
@@ -65,8 +43,8 @@ module BootstrapForm
|
|
65
43
|
# select :choices, ["a", "b"], {}, bootstrap: {label: {text: "Custom"}}
|
66
44
|
#
|
67
45
|
def select(method, choices = nil, options = {}, html_options = {}, &block)
|
68
|
-
|
69
|
-
draw_form_group(
|
46
|
+
bootstrap = form_bootstrap.scoped(options.delete(:bootstrap))
|
47
|
+
draw_form_group(bootstrap, method, html_options) do
|
70
48
|
super(method, choices, options, html_options, &block)
|
71
49
|
end
|
72
50
|
end
|
@@ -76,17 +54,16 @@ module BootstrapForm
|
|
76
54
|
# checkbox :agree, bootstrap: {label: {text: "Do you agree?"}}
|
77
55
|
#
|
78
56
|
def check_box(method, options = {}, checked_value = "1", unchecked_value = "0")
|
79
|
-
|
80
|
-
bootstrap_label_options = bootstrap_options[:label] || {}
|
57
|
+
bootstrap = form_bootstrap.scoped(options.delete(:bootstrap))
|
81
58
|
|
82
|
-
help_text = draw_help(
|
59
|
+
help_text = draw_help(bootstrap.help)
|
83
60
|
errors = draw_errors(method)
|
84
61
|
|
85
62
|
add_css_class!(options, "form-check-input")
|
86
63
|
add_css_class!(options, "is-invalid") if errors.present?
|
87
64
|
|
88
65
|
label_text = nil
|
89
|
-
if (custom_text =
|
66
|
+
if (custom_text = bootstrap.label[:text]).present?
|
90
67
|
label_text = custom_text
|
91
68
|
end
|
92
69
|
|
@@ -95,7 +72,7 @@ module BootstrapForm
|
|
95
72
|
fieldset_css_class << " #{bootstrap.inline_margin_class}" if bootstrap.inline?
|
96
73
|
|
97
74
|
content_tag(:fieldset, class: fieldset_css_class) do
|
98
|
-
draw_control_column(offset: true) do
|
75
|
+
draw_control_column(bootstrap, offset: true) do
|
99
76
|
content_tag(:div, class: "form-check") do
|
100
77
|
concat super(method, options, checked_value, unchecked_value)
|
101
78
|
concat label(method, label_text, class: "form-check-label")
|
@@ -118,9 +95,9 @@ module BootstrapForm
|
|
118
95
|
# label: {hide: true} - to not render label at all
|
119
96
|
#
|
120
97
|
def collection_radio_buttons(method, collection, value_method, text_method, options = {}, html_options = {})
|
121
|
-
|
98
|
+
bootstrap = form_bootstrap.scoped(options.delete(:bootstrap))
|
122
99
|
|
123
|
-
args = [
|
100
|
+
args = [bootstrap, method, collection, value_method, text_method, options, html_options]
|
124
101
|
draw_choices(*args) do |m, v, opts|
|
125
102
|
radio_button(m, v, opts)
|
126
103
|
end
|
@@ -132,14 +109,14 @@ module BootstrapForm
|
|
132
109
|
# collection_check_boxes :choices, Choice.all, :id, :label
|
133
110
|
#
|
134
111
|
def collection_check_boxes(method, collection, value_method, text_method, options = {}, html_options = {})
|
135
|
-
|
112
|
+
bootstrap = form_bootstrap.scoped(options.delete(:bootstrap))
|
136
113
|
|
137
114
|
content = "".html_safe
|
138
115
|
unless options[:include_hidden] == false
|
139
116
|
content << hidden_field(method, multiple: true, value: "")
|
140
117
|
end
|
141
118
|
|
142
|
-
args = [
|
119
|
+
args = [bootstrap, method, collection, value_method, text_method, options, html_options]
|
143
120
|
content << draw_choices(*args) do |m, v, opts|
|
144
121
|
opts[:multiple] = true
|
145
122
|
opts[:include_hidden] = false
|
@@ -152,8 +129,8 @@ module BootstrapForm
|
|
152
129
|
# plaintext(:value)
|
153
130
|
#
|
154
131
|
def plaintext(method, options = {})
|
155
|
-
|
156
|
-
draw_form_group(
|
132
|
+
bootstrap = form_bootstrap.scoped(options.delete(:bootstrap))
|
133
|
+
draw_form_group(bootstrap, method, options) do
|
157
134
|
remove_css_class!(options, "form-control")
|
158
135
|
add_css_class!(options, "form-control-plaintext")
|
159
136
|
options[:readonly] = true
|
@@ -174,14 +151,20 @@ module BootstrapForm
|
|
174
151
|
# end
|
175
152
|
#
|
176
153
|
def submit(value = nil, options = {}, &block)
|
177
|
-
|
154
|
+
if value.is_a?(Hash)
|
155
|
+
options = value
|
156
|
+
value = nil
|
157
|
+
end
|
158
|
+
|
159
|
+
bootstrap = form_bootstrap.scoped(options.delete(:bootstrap))
|
160
|
+
|
178
161
|
add_css_class!(options, "btn")
|
179
162
|
|
180
163
|
form_group_class = "form-group"
|
181
164
|
form_group_class << " row" if bootstrap.horizontal?
|
182
165
|
|
183
166
|
content_tag(:div, class: form_group_class) do
|
184
|
-
draw_control_column(offset: true) do
|
167
|
+
draw_control_column(bootstrap, offset: true) do
|
185
168
|
out = super(value, options)
|
186
169
|
out << capture(&block) if block_given?
|
187
170
|
out
|
@@ -202,27 +185,27 @@ module BootstrapForm
|
|
202
185
|
# "Some content"
|
203
186
|
# end
|
204
187
|
#
|
205
|
-
def form_group(options = {}
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
188
|
+
def form_group(options = {})
|
189
|
+
bootstrap = form_bootstrap.scoped(options.delete(:bootstrap))
|
190
|
+
|
191
|
+
label_text = bootstrap.label[:text]
|
192
|
+
|
193
|
+
label =
|
194
|
+
if label_text.present?
|
195
|
+
label_options = {}
|
196
|
+
add_css_class!(label_options, bootstrap.label[:class])
|
197
|
+
|
198
|
+
if bootstrap.horizontal?
|
199
|
+
add_css_class!(label_options, "col-form-label")
|
200
|
+
add_css_class!(label_options, bootstrap.label_col_class)
|
201
|
+
add_css_class!(label_options, bootstrap.label_align_class)
|
202
|
+
elsif bootstrap.inline?
|
203
|
+
add_css_class!(label_options, bootstrap.inline_margin_class)
|
204
|
+
end
|
214
205
|
|
215
|
-
|
216
|
-
add_css_class!(label_options, "col-form-label")
|
217
|
-
add_css_class!(label_options, bootstrap.label_col_class)
|
218
|
-
add_css_class!(label_options, bootstrap.label_align_class)
|
219
|
-
elsif bootstrap.inline?
|
220
|
-
add_css_class!(label_options, bootstrap.inline_margin_class)
|
206
|
+
content_tag(:label, label_text, label_options)
|
221
207
|
end
|
222
208
|
|
223
|
-
content_tag(:label, label_text, label_options)
|
224
|
-
end
|
225
|
-
|
226
209
|
form_group_class = "form-group"
|
227
210
|
form_group_class << " row" if bootstrap.horizontal?
|
228
211
|
form_group_class << " mr-sm-2" if bootstrap.inline?
|
@@ -230,7 +213,7 @@ module BootstrapForm
|
|
230
213
|
content_tag(:div, class: form_group_class) do
|
231
214
|
content = "".html_safe
|
232
215
|
content << label if label.present?
|
233
|
-
content << draw_control_column(offset: label.blank?) do
|
216
|
+
content << draw_control_column(bootstrap, offset: label.blank?) do
|
234
217
|
yield
|
235
218
|
end
|
236
219
|
end
|
@@ -238,27 +221,12 @@ module BootstrapForm
|
|
238
221
|
|
239
222
|
private
|
240
223
|
|
241
|
-
# Wrapper for all field helpers. Example usage:
|
242
|
-
#
|
243
|
-
# bootstrap_form_with model: @user do |form|
|
244
|
-
# form.text_field :name
|
245
|
-
# end
|
246
|
-
#
|
247
|
-
# Output of the `text_field` will be wrapped in Bootstrap markup
|
248
|
-
#
|
249
|
-
def field_helper(method, options, &block)
|
250
|
-
bootstrap_options = (options.delete(:bootstrap) || {})
|
251
|
-
draw_form_group(bootstrap_options, method, options) do
|
252
|
-
yield
|
253
|
-
end
|
254
|
-
end
|
255
|
-
|
256
224
|
# form group wrapper for input fields
|
257
|
-
def draw_form_group(
|
258
|
-
label = draw_label(
|
225
|
+
def draw_form_group(bootstrap, method, options)
|
226
|
+
label = draw_label(bootstrap, method)
|
259
227
|
errors = draw_errors(method)
|
260
228
|
|
261
|
-
control = draw_control(
|
229
|
+
control = draw_control(bootstrap, errors, method, options) do
|
262
230
|
yield
|
263
231
|
end
|
264
232
|
|
@@ -290,18 +258,16 @@ module BootstrapForm
|
|
290
258
|
#
|
291
259
|
# text_field(:value, bootstrap: {label: {text: "Custom", class: "custom"}})
|
292
260
|
#
|
293
|
-
def draw_label(
|
294
|
-
bootstrap_label_options = bootstrap_options[:label] || {}
|
295
|
-
|
261
|
+
def draw_label(bootstrap, method)
|
296
262
|
text = nil
|
297
263
|
options = {}
|
298
264
|
|
299
|
-
if (custom_text =
|
265
|
+
if (custom_text = bootstrap.label[:text]).present?
|
300
266
|
text = custom_text
|
301
267
|
end
|
302
268
|
|
303
|
-
add_css_class!(options,
|
304
|
-
add_css_class!(options, "sr-only") if
|
269
|
+
add_css_class!(options, bootstrap.label[:class])
|
270
|
+
add_css_class!(options, "sr-only") if bootstrap.label[:hide]
|
305
271
|
add_css_class!(options, bootstrap.inline_margin_class) if bootstrap.inline?
|
306
272
|
|
307
273
|
if bootstrap.horizontal?
|
@@ -314,16 +280,12 @@ module BootstrapForm
|
|
314
280
|
end
|
315
281
|
|
316
282
|
# Renders control for a given field
|
317
|
-
def draw_control(
|
318
|
-
bootstrap_label_options = bootstrap_options[:label] || {}
|
319
|
-
|
283
|
+
def draw_control(bootstrap, errors, _method, options)
|
320
284
|
add_css_class!(options, "form-control")
|
321
285
|
add_css_class!(options, "is-invalid") if errors.present?
|
322
286
|
|
323
|
-
offset
|
324
|
-
|
325
|
-
draw_control_column(offset: offset) do
|
326
|
-
draw_input_group(bootstrap_options, errors) do
|
287
|
+
draw_control_column(bootstrap, offset: bootstrap.label[:hide]) do
|
288
|
+
draw_input_group(bootstrap, errors) do
|
327
289
|
yield
|
328
290
|
end
|
329
291
|
end
|
@@ -331,9 +293,9 @@ module BootstrapForm
|
|
331
293
|
|
332
294
|
# Wrapping in control in column wrapper
|
333
295
|
#
|
334
|
-
def draw_control_column(offset
|
296
|
+
def draw_control_column(bootstrap, offset:)
|
335
297
|
return yield unless bootstrap.horizontal?
|
336
|
-
css_class =
|
298
|
+
css_class = bootstrap.control_col_class.to_s
|
337
299
|
css_class << " #{bootstrap.offset_col_class}" if offset
|
338
300
|
content_tag(:div, class: css_class) do
|
339
301
|
yield
|
@@ -346,11 +308,11 @@ module BootstrapForm
|
|
346
308
|
# text_field(:value, bootstrap: {prepend: "$.$$"}})
|
347
309
|
# text_field(:value, bootstrap: {append: {html: "<button>Go</button>"}}})
|
348
310
|
#
|
349
|
-
def draw_input_group(
|
350
|
-
prepend_html = draw_input_group_content(
|
351
|
-
append_html = draw_input_group_content(
|
311
|
+
def draw_input_group(bootstrap, errors, &block)
|
312
|
+
prepend_html = draw_input_group_content(bootstrap, :prepend)
|
313
|
+
append_html = draw_input_group_content(bootstrap, :append)
|
352
314
|
|
353
|
-
help_text = draw_help(
|
315
|
+
help_text = draw_help(bootstrap.help)
|
354
316
|
|
355
317
|
# Not prepending or appending anything. Bail.
|
356
318
|
if prepend_html.blank? && append_html.blank?
|
@@ -360,17 +322,19 @@ module BootstrapForm
|
|
360
322
|
return content
|
361
323
|
end
|
362
324
|
|
363
|
-
|
325
|
+
content = "".html_safe
|
326
|
+
content << content_tag(:div, class: "input-group") do
|
364
327
|
concat prepend_html if prepend_html.present?
|
365
328
|
concat capture(&block)
|
366
329
|
concat append_html if append_html.present?
|
367
330
|
concat errors if errors.present?
|
368
|
-
concat help_text if help_text.present?
|
369
331
|
end
|
332
|
+
content << help_text if help_text.present?
|
333
|
+
content
|
370
334
|
end
|
371
335
|
|
372
|
-
def draw_input_group_content(
|
373
|
-
value =
|
336
|
+
def draw_input_group_content(bootstrap, type)
|
337
|
+
value = bootstrap.send(type)
|
374
338
|
return unless value.present?
|
375
339
|
|
376
340
|
content_tag(:div, class: "input-group-#{type}") do
|
@@ -392,16 +356,15 @@ module BootstrapForm
|
|
392
356
|
end
|
393
357
|
|
394
358
|
# Rendering of choices for checkboxes and radio buttons
|
395
|
-
def draw_choices(
|
359
|
+
def draw_choices(bootstrap, method, collection, value_method, text_method, _options, html_options)
|
396
360
|
add_css_class!(html_options, "form-check-input")
|
397
361
|
|
398
|
-
draw_form_group_fieldset(
|
399
|
-
|
362
|
+
draw_form_group_fieldset(bootstrap, method, html_options) do
|
400
363
|
form_check_css_class = "form-check"
|
401
|
-
form_check_css_class << " form-check-inline" if
|
364
|
+
form_check_css_class << " form-check-inline" if bootstrap.check_inline
|
402
365
|
|
403
366
|
errors = draw_errors(method)
|
404
|
-
help_text = draw_help(
|
367
|
+
help_text = draw_help(bootstrap.help)
|
405
368
|
|
406
369
|
add_css_class!(html_options, "is-invalid") if errors.present?
|
407
370
|
|
@@ -411,16 +374,16 @@ module BootstrapForm
|
|
411
374
|
item_text = item.send(text_method)
|
412
375
|
|
413
376
|
content << content_tag(:div, class: form_check_css_class) do
|
414
|
-
concat
|
377
|
+
concat yield method, item_value, html_options
|
415
378
|
concat label(method, item_text, value: item_value, class: "form-check-label")
|
416
|
-
if ((collection.count - 1) == index) && !
|
379
|
+
if ((collection.count - 1) == index) && !bootstrap.check_inline
|
417
380
|
concat errors if errors.present?
|
418
381
|
concat help_text if help_text.present?
|
419
382
|
end
|
420
383
|
end
|
421
384
|
end
|
422
385
|
|
423
|
-
if
|
386
|
+
if bootstrap.check_inline
|
424
387
|
content << errors if errors.present?
|
425
388
|
content << help_text if help_text.present?
|
426
389
|
end
|
@@ -430,22 +393,23 @@ module BootstrapForm
|
|
430
393
|
end
|
431
394
|
|
432
395
|
# Wrapper for collections of radio buttons and checkboxes
|
433
|
-
def draw_form_group_fieldset(
|
434
|
-
|
396
|
+
def draw_form_group_fieldset(bootstrap, method, _html_options)
|
397
|
+
options = {}
|
435
398
|
|
436
|
-
unless
|
437
|
-
label_text =
|
399
|
+
unless bootstrap.label[:hide]
|
400
|
+
label_text = bootstrap.label[:text]
|
438
401
|
label_text ||= ActionView::Helpers::Tags::Label::LabelBuilder
|
439
402
|
.new(@template, @object_name.to_s, method, @object, nil).translation
|
440
403
|
|
441
|
-
add_css_class!(
|
404
|
+
add_css_class!(options, "col-form-label pt-0")
|
405
|
+
add_css_class!(options, bootstrap.label[:class])
|
442
406
|
|
443
407
|
if bootstrap.horizontal?
|
444
|
-
add_css_class!(
|
445
|
-
add_css_class!(
|
408
|
+
add_css_class!(options, bootstrap.label_col_class)
|
409
|
+
add_css_class!(options, bootstrap.label_align_class)
|
446
410
|
end
|
447
411
|
|
448
|
-
label = content_tag(:legend,
|
412
|
+
label = content_tag(:legend, options) do
|
449
413
|
label_text
|
450
414
|
end
|
451
415
|
end
|
@@ -453,7 +417,7 @@ module BootstrapForm
|
|
453
417
|
content_tag(:fieldset, class: "form-group") do
|
454
418
|
content = "".html_safe
|
455
419
|
content << label if label.present?
|
456
|
-
content << draw_control_column(offset:
|
420
|
+
content << draw_control_column(bootstrap, offset: bootstrap.label[:hide]) do
|
457
421
|
yield
|
458
422
|
end
|
459
423
|
|
@@ -477,5 +441,4 @@ module BootstrapForm
|
|
477
441
|
end
|
478
442
|
|
479
443
|
end
|
480
|
-
|
481
444
|
end
|
@@ -24,10 +24,11 @@ module BootstrapForm
|
|
24
24
|
# Bootstrap specific markup. So we need to bypass this.
|
25
25
|
def supress_field_errors
|
26
26
|
original_proc = ActionView::Base.field_error_proc
|
27
|
-
ActionView::Base.field_error_proc = proc { |input,
|
27
|
+
ActionView::Base.field_error_proc = proc { |input, _instance| input }
|
28
28
|
yield
|
29
29
|
ensure
|
30
30
|
ActionView::Base.field_error_proc = original_proc
|
31
31
|
end
|
32
|
+
|
32
33
|
end
|
33
34
|
end
|
data/lib/bootstrap_form.rb
CHANGED