simple_form 5.0.3 → 5.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/README.md +69 -15
- data/lib/generators/simple_form/install_generator.rb +2 -2
- data/lib/generators/simple_form/templates/README +1 -1
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +1 -1
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +126 -194
- data/lib/simple_form/components/labels.rb +3 -5
- data/lib/simple_form/components/maxlength.rb +0 -4
- data/lib/simple_form/components/minlength.rb +0 -4
- data/lib/simple_form/form_builder.rb +1 -1
- data/lib/simple_form/inputs/base.rb +0 -3
- data/lib/simple_form/inputs/boolean_input.rb +6 -2
- data/lib/simple_form/inputs/collection_input.rb +2 -4
- data/lib/simple_form/inputs/grouped_collection_select_input.rb +1 -1
- data/lib/simple_form/inputs/priority_input.rb +16 -2
- data/lib/simple_form/version.rb +1 -1
- data/lib/simple_form.rb +1 -1
- data/test/components/label_test.rb +0 -4
- data/test/form_builder/wrapper_test.rb +2 -2
- data/test/inputs/boolean_input_test.rb +13 -0
- data/test/inputs/collection_check_boxes_input_test.rb +0 -4
- data/test/inputs/collection_radio_buttons_input_test.rb +0 -4
- data/test/inputs/collection_select_input_test.rb +0 -4
- data/test/inputs/country_input_test.rb +36 -0
- data/test/inputs/grouped_collection_select_input_test.rb +13 -0
- data/test/inputs/{priority_input_test.rb → time_zone_input_test.rb} +5 -19
- metadata +45 -38
- data/lib/simple_form/i18n_cache.rb +0 -23
@@ -1,10 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
# All future development, tests, and organization should happen there.
|
7
|
-
# Background history: https://github.com/heartcombo/simple_form/issues/1561
|
3
|
+
# These defaults are defined and maintained by the community at
|
4
|
+
# https://github.com/heartcombo/simple_form-bootstrap
|
5
|
+
# Please submit feedback, changes and tests only there.
|
8
6
|
|
9
7
|
# Uncomment this and change the path if necessary to include your own
|
10
8
|
# components.
|
@@ -49,7 +47,7 @@ SimpleForm.setup do |config|
|
|
49
47
|
# vertical forms
|
50
48
|
#
|
51
49
|
# vertical default_wrapper
|
52
|
-
config.wrappers :vertical_form,
|
50
|
+
config.wrappers :vertical_form, class: 'mb-3' do |b|
|
53
51
|
b.use :html5
|
54
52
|
b.use :placeholder
|
55
53
|
b.optional :maxlength
|
@@ -57,90 +55,100 @@ SimpleForm.setup do |config|
|
|
57
55
|
b.optional :pattern
|
58
56
|
b.optional :min_max
|
59
57
|
b.optional :readonly
|
60
|
-
b.use :label
|
58
|
+
b.use :label, class: 'form-label'
|
61
59
|
b.use :input, class: 'form-control', error_class: 'is-invalid', valid_class: 'is-valid'
|
62
|
-
b.use :full_error, wrap_with: {
|
63
|
-
b.use :hint, wrap_with: {
|
60
|
+
b.use :full_error, wrap_with: { class: 'invalid-feedback' }
|
61
|
+
b.use :hint, wrap_with: { class: 'form-text' }
|
64
62
|
end
|
65
63
|
|
66
64
|
# vertical input for boolean
|
67
|
-
config.wrappers :vertical_boolean, tag: 'fieldset', class: '
|
65
|
+
config.wrappers :vertical_boolean, tag: 'fieldset', class: 'mb-3' do |b|
|
68
66
|
b.use :html5
|
69
67
|
b.optional :readonly
|
70
|
-
b.wrapper :form_check_wrapper,
|
68
|
+
b.wrapper :form_check_wrapper, class: 'form-check' do |bb|
|
71
69
|
bb.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid'
|
72
70
|
bb.use :label, class: 'form-check-label'
|
73
|
-
bb.use :full_error, wrap_with: {
|
74
|
-
bb.use :hint, wrap_with: {
|
71
|
+
bb.use :full_error, wrap_with: { class: 'invalid-feedback' }
|
72
|
+
bb.use :hint, wrap_with: { class: 'form-text' }
|
75
73
|
end
|
76
74
|
end
|
77
75
|
|
78
76
|
# vertical input for radio buttons and check boxes
|
79
|
-
config.wrappers :vertical_collection, item_wrapper_class: 'form-check', item_label_class: 'form-check-label', tag: 'fieldset', class: '
|
77
|
+
config.wrappers :vertical_collection, item_wrapper_class: 'form-check', item_label_class: 'form-check-label', tag: 'fieldset', class: 'mb-3' do |b|
|
80
78
|
b.use :html5
|
81
79
|
b.optional :readonly
|
82
80
|
b.wrapper :legend_tag, tag: 'legend', class: 'col-form-label pt-0' do |ba|
|
83
81
|
ba.use :label_text
|
84
82
|
end
|
85
83
|
b.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid'
|
86
|
-
b.use :full_error, wrap_with: {
|
87
|
-
b.use :hint, wrap_with: {
|
84
|
+
b.use :full_error, wrap_with: { class: 'invalid-feedback d-block' }
|
85
|
+
b.use :hint, wrap_with: { class: 'form-text' }
|
88
86
|
end
|
89
87
|
|
90
88
|
# vertical input for inline radio buttons and check boxes
|
91
|
-
config.wrappers :vertical_collection_inline, item_wrapper_class: 'form-check form-check-inline', item_label_class: 'form-check-label', tag: 'fieldset', class: '
|
89
|
+
config.wrappers :vertical_collection_inline, item_wrapper_class: 'form-check form-check-inline', item_label_class: 'form-check-label', tag: 'fieldset', class: 'mb-3' do |b|
|
92
90
|
b.use :html5
|
93
91
|
b.optional :readonly
|
94
92
|
b.wrapper :legend_tag, tag: 'legend', class: 'col-form-label pt-0' do |ba|
|
95
93
|
ba.use :label_text
|
96
94
|
end
|
97
95
|
b.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid'
|
98
|
-
b.use :full_error, wrap_with: {
|
99
|
-
b.use :hint, wrap_with: {
|
96
|
+
b.use :full_error, wrap_with: { class: 'invalid-feedback d-block' }
|
97
|
+
b.use :hint, wrap_with: { class: 'form-text' }
|
100
98
|
end
|
101
99
|
|
102
100
|
# vertical file input
|
103
|
-
config.wrappers :vertical_file,
|
101
|
+
config.wrappers :vertical_file, class: 'mb-3' do |b|
|
104
102
|
b.use :html5
|
105
103
|
b.use :placeholder
|
106
104
|
b.optional :maxlength
|
107
105
|
b.optional :minlength
|
108
106
|
b.optional :readonly
|
109
|
-
b.use :label
|
110
|
-
b.use :input, class: 'form-control
|
111
|
-
b.use :full_error, wrap_with: {
|
112
|
-
b.use :hint, wrap_with: {
|
107
|
+
b.use :label, class: 'form-label'
|
108
|
+
b.use :input, class: 'form-control', error_class: 'is-invalid', valid_class: 'is-valid'
|
109
|
+
b.use :full_error, wrap_with: { class: 'invalid-feedback' }
|
110
|
+
b.use :hint, wrap_with: { class: 'form-text' }
|
111
|
+
end
|
112
|
+
|
113
|
+
# vertical select input
|
114
|
+
config.wrappers :vertical_select, class: 'mb-3' do |b|
|
115
|
+
b.use :html5
|
116
|
+
b.optional :readonly
|
117
|
+
b.use :label, class: 'form-label'
|
118
|
+
b.use :input, class: 'form-select', error_class: 'is-invalid', valid_class: 'is-valid'
|
119
|
+
b.use :full_error, wrap_with: { class: 'invalid-feedback' }
|
120
|
+
b.use :hint, wrap_with: { class: 'form-text' }
|
113
121
|
end
|
114
122
|
|
115
123
|
# vertical multi select
|
116
|
-
config.wrappers :vertical_multi_select,
|
124
|
+
config.wrappers :vertical_multi_select, class: 'mb-3' do |b|
|
117
125
|
b.use :html5
|
118
126
|
b.optional :readonly
|
119
|
-
b.use :label
|
120
|
-
b.wrapper
|
121
|
-
ba.use :input, class: 'form-
|
127
|
+
b.use :label, class: 'form-label'
|
128
|
+
b.wrapper class: 'd-flex flex-row justify-content-between align-items-center' do |ba|
|
129
|
+
ba.use :input, class: 'form-select mx-1', error_class: 'is-invalid', valid_class: 'is-valid'
|
122
130
|
end
|
123
|
-
b.use :full_error, wrap_with: {
|
124
|
-
b.use :hint, wrap_with: {
|
131
|
+
b.use :full_error, wrap_with: { class: 'invalid-feedback d-block' }
|
132
|
+
b.use :hint, wrap_with: { class: 'form-text' }
|
125
133
|
end
|
126
134
|
|
127
135
|
# vertical range input
|
128
|
-
config.wrappers :vertical_range,
|
136
|
+
config.wrappers :vertical_range, class: 'mb-3' do |b|
|
129
137
|
b.use :html5
|
130
138
|
b.use :placeholder
|
131
139
|
b.optional :readonly
|
132
140
|
b.optional :step
|
133
|
-
b.use :label
|
134
|
-
b.use :input, class: 'form-
|
135
|
-
b.use :full_error, wrap_with: {
|
136
|
-
b.use :hint, wrap_with: {
|
141
|
+
b.use :label, class: 'form-label'
|
142
|
+
b.use :input, class: 'form-range', error_class: 'is-invalid', valid_class: 'is-valid'
|
143
|
+
b.use :full_error, wrap_with: { class: 'invalid-feedback' }
|
144
|
+
b.use :hint, wrap_with: { class: 'form-text' }
|
137
145
|
end
|
138
146
|
|
139
147
|
|
140
148
|
# horizontal forms
|
141
149
|
#
|
142
150
|
# horizontal default_wrapper
|
143
|
-
config.wrappers :horizontal_form,
|
151
|
+
config.wrappers :horizontal_form, class: 'row mb-3' do |b|
|
144
152
|
b.use :html5
|
145
153
|
b.use :placeholder
|
146
154
|
b.optional :maxlength
|
@@ -149,94 +157,103 @@ SimpleForm.setup do |config|
|
|
149
157
|
b.optional :min_max
|
150
158
|
b.optional :readonly
|
151
159
|
b.use :label, class: 'col-sm-3 col-form-label'
|
152
|
-
b.wrapper :grid_wrapper,
|
160
|
+
b.wrapper :grid_wrapper, class: 'col-sm-9' do |ba|
|
153
161
|
ba.use :input, class: 'form-control', error_class: 'is-invalid', valid_class: 'is-valid'
|
154
|
-
ba.use :full_error, wrap_with: {
|
155
|
-
ba.use :hint, wrap_with: {
|
162
|
+
ba.use :full_error, wrap_with: { class: 'invalid-feedback' }
|
163
|
+
ba.use :hint, wrap_with: { class: 'form-text' }
|
156
164
|
end
|
157
165
|
end
|
158
166
|
|
159
167
|
# horizontal input for boolean
|
160
|
-
config.wrappers :horizontal_boolean,
|
168
|
+
config.wrappers :horizontal_boolean, class: 'row mb-3' do |b|
|
161
169
|
b.use :html5
|
162
170
|
b.optional :readonly
|
163
|
-
b.wrapper
|
164
|
-
|
165
|
-
end
|
166
|
-
b.wrapper :grid_wrapper, tag: 'div', class: 'col-sm-9' do |wr|
|
167
|
-
wr.wrapper :form_check_wrapper, tag: 'div', class: 'form-check' do |bb|
|
171
|
+
b.wrapper :grid_wrapper, class: 'col-sm-9 offset-sm-3' do |wr|
|
172
|
+
wr.wrapper :form_check_wrapper, class: 'form-check' do |bb|
|
168
173
|
bb.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid'
|
169
174
|
bb.use :label, class: 'form-check-label'
|
170
|
-
bb.use :full_error, wrap_with: {
|
171
|
-
bb.use :hint, wrap_with: {
|
175
|
+
bb.use :full_error, wrap_with: { class: 'invalid-feedback' }
|
176
|
+
bb.use :hint, wrap_with: { class: 'form-text' }
|
172
177
|
end
|
173
178
|
end
|
174
179
|
end
|
175
180
|
|
176
181
|
# horizontal input for radio buttons and check boxes
|
177
|
-
config.wrappers :horizontal_collection, item_wrapper_class: 'form-check', item_label_class: 'form-check-label',
|
182
|
+
config.wrappers :horizontal_collection, item_wrapper_class: 'form-check', item_label_class: 'form-check-label', class: 'row mb-3' do |b|
|
178
183
|
b.use :html5
|
179
184
|
b.optional :readonly
|
180
185
|
b.use :label, class: 'col-sm-3 col-form-label pt-0'
|
181
|
-
b.wrapper :grid_wrapper,
|
186
|
+
b.wrapper :grid_wrapper, class: 'col-sm-9' do |ba|
|
182
187
|
ba.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid'
|
183
|
-
ba.use :full_error, wrap_with: {
|
184
|
-
ba.use :hint, wrap_with: {
|
188
|
+
ba.use :full_error, wrap_with: { class: 'invalid-feedback d-block' }
|
189
|
+
ba.use :hint, wrap_with: { class: 'form-text' }
|
185
190
|
end
|
186
191
|
end
|
187
192
|
|
188
193
|
# horizontal input for inline radio buttons and check boxes
|
189
|
-
config.wrappers :horizontal_collection_inline, item_wrapper_class: 'form-check form-check-inline', item_label_class: 'form-check-label',
|
194
|
+
config.wrappers :horizontal_collection_inline, item_wrapper_class: 'form-check form-check-inline', item_label_class: 'form-check-label', class: 'row mb-3' do |b|
|
190
195
|
b.use :html5
|
191
196
|
b.optional :readonly
|
192
197
|
b.use :label, class: 'col-sm-3 col-form-label pt-0'
|
193
|
-
b.wrapper :grid_wrapper,
|
198
|
+
b.wrapper :grid_wrapper, class: 'col-sm-9' do |ba|
|
194
199
|
ba.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid'
|
195
|
-
ba.use :full_error, wrap_with: {
|
196
|
-
ba.use :hint, wrap_with: {
|
200
|
+
ba.use :full_error, wrap_with: { class: 'invalid-feedback d-block' }
|
201
|
+
ba.use :hint, wrap_with: { class: 'form-text' }
|
197
202
|
end
|
198
203
|
end
|
199
204
|
|
200
205
|
# horizontal file input
|
201
|
-
config.wrappers :horizontal_file,
|
206
|
+
config.wrappers :horizontal_file, class: 'row mb-3' do |b|
|
202
207
|
b.use :html5
|
203
208
|
b.use :placeholder
|
204
209
|
b.optional :maxlength
|
205
210
|
b.optional :minlength
|
206
211
|
b.optional :readonly
|
207
212
|
b.use :label, class: 'col-sm-3 col-form-label'
|
208
|
-
b.wrapper :grid_wrapper,
|
209
|
-
ba.use :input, error_class: 'is-invalid', valid_class: 'is-valid'
|
210
|
-
ba.use :full_error, wrap_with: {
|
211
|
-
ba.use :hint, wrap_with: {
|
213
|
+
b.wrapper :grid_wrapper, class: 'col-sm-9' do |ba|
|
214
|
+
ba.use :input, class: 'form-control', error_class: 'is-invalid', valid_class: 'is-valid'
|
215
|
+
ba.use :full_error, wrap_with: { class: 'invalid-feedback' }
|
216
|
+
ba.use :hint, wrap_with: { class: 'form-text' }
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
# horizontal select input
|
221
|
+
config.wrappers :horizontal_select, class: 'row mb-3' do |b|
|
222
|
+
b.use :html5
|
223
|
+
b.optional :readonly
|
224
|
+
b.use :label, class: 'col-sm-3 col-form-label'
|
225
|
+
b.wrapper :grid_wrapper, class: 'col-sm-9' do |ba|
|
226
|
+
ba.use :input, class: 'form-select', error_class: 'is-invalid', valid_class: 'is-valid'
|
227
|
+
ba.use :full_error, wrap_with: { class: 'invalid-feedback' }
|
228
|
+
ba.use :hint, wrap_with: { class: 'form-text' }
|
212
229
|
end
|
213
230
|
end
|
214
231
|
|
215
232
|
# horizontal multi select
|
216
|
-
config.wrappers :horizontal_multi_select,
|
233
|
+
config.wrappers :horizontal_multi_select, class: 'row mb-3' do |b|
|
217
234
|
b.use :html5
|
218
235
|
b.optional :readonly
|
219
236
|
b.use :label, class: 'col-sm-3 col-form-label'
|
220
|
-
b.wrapper :grid_wrapper,
|
221
|
-
ba.wrapper
|
222
|
-
bb.use :input, class: 'form-
|
237
|
+
b.wrapper :grid_wrapper, class: 'col-sm-9' do |ba|
|
238
|
+
ba.wrapper class: 'd-flex flex-row justify-content-between align-items-center' do |bb|
|
239
|
+
bb.use :input, class: 'form-select mx-1', error_class: 'is-invalid', valid_class: 'is-valid'
|
223
240
|
end
|
224
|
-
ba.use :full_error, wrap_with: {
|
225
|
-
ba.use :hint, wrap_with: {
|
241
|
+
ba.use :full_error, wrap_with: { class: 'invalid-feedback d-block' }
|
242
|
+
ba.use :hint, wrap_with: { class: 'form-text' }
|
226
243
|
end
|
227
244
|
end
|
228
245
|
|
229
246
|
# horizontal range input
|
230
|
-
config.wrappers :horizontal_range,
|
247
|
+
config.wrappers :horizontal_range, class: 'row mb-3' do |b|
|
231
248
|
b.use :html5
|
232
249
|
b.use :placeholder
|
233
250
|
b.optional :readonly
|
234
251
|
b.optional :step
|
235
|
-
b.use :label, class: 'col-sm-3 col-form-label'
|
236
|
-
b.wrapper :grid_wrapper,
|
237
|
-
ba.use :input, class: 'form-
|
238
|
-
ba.use :full_error, wrap_with: {
|
239
|
-
ba.use :hint, wrap_with: {
|
252
|
+
b.use :label, class: 'col-sm-3 col-form-label pt-0'
|
253
|
+
b.wrapper :grid_wrapper, class: 'col-sm-9' do |ba|
|
254
|
+
ba.use :input, class: 'form-range', error_class: 'is-invalid', valid_class: 'is-valid'
|
255
|
+
ba.use :full_error, wrap_with: { class: 'invalid-feedback' }
|
256
|
+
ba.use :hint, wrap_with: { class: 'form-text' }
|
240
257
|
end
|
241
258
|
end
|
242
259
|
|
@@ -244,7 +261,7 @@ SimpleForm.setup do |config|
|
|
244
261
|
# inline forms
|
245
262
|
#
|
246
263
|
# inline default_wrapper
|
247
|
-
config.wrappers :inline_form,
|
264
|
+
config.wrappers :inline_form, class: 'col-12' do |b|
|
248
265
|
b.use :html5
|
249
266
|
b.use :placeholder
|
250
267
|
b.optional :maxlength
|
@@ -252,140 +269,66 @@ SimpleForm.setup do |config|
|
|
252
269
|
b.optional :pattern
|
253
270
|
b.optional :min_max
|
254
271
|
b.optional :readonly
|
255
|
-
b.use :label, class: '
|
272
|
+
b.use :label, class: 'visually-hidden'
|
256
273
|
|
257
274
|
b.use :input, class: 'form-control', error_class: 'is-invalid', valid_class: 'is-valid'
|
258
|
-
b.use :error, wrap_with: {
|
259
|
-
b.optional :hint, wrap_with: {
|
275
|
+
b.use :error, wrap_with: { class: 'invalid-feedback' }
|
276
|
+
b.optional :hint, wrap_with: { class: 'form-text' }
|
260
277
|
end
|
261
278
|
|
262
279
|
# inline input for boolean
|
263
|
-
config.wrappers :inline_boolean,
|
280
|
+
config.wrappers :inline_boolean, class: 'col-12' do |b|
|
264
281
|
b.use :html5
|
265
282
|
b.optional :readonly
|
266
|
-
b.
|
267
|
-
|
268
|
-
|
269
|
-
|
283
|
+
b.wrapper :form_check_wrapper, class: 'form-check' do |bb|
|
284
|
+
bb.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid'
|
285
|
+
bb.use :label, class: 'form-check-label'
|
286
|
+
bb.use :error, wrap_with: { class: 'invalid-feedback' }
|
287
|
+
bb.optional :hint, wrap_with: { class: 'form-text' }
|
288
|
+
end
|
270
289
|
end
|
271
290
|
|
272
291
|
|
273
292
|
# bootstrap custom forms
|
274
293
|
#
|
275
|
-
# custom input for boolean
|
276
|
-
config.wrappers :custom_boolean, tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
|
277
|
-
b.use :html5
|
278
|
-
b.optional :readonly
|
279
|
-
b.wrapper :form_check_wrapper, tag: 'div', class: 'custom-control custom-checkbox' do |bb|
|
280
|
-
bb.use :input, class: 'custom-control-input', error_class: 'is-invalid', valid_class: 'is-valid'
|
281
|
-
bb.use :label, class: 'custom-control-label'
|
282
|
-
bb.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback' }
|
283
|
-
bb.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
|
284
|
-
end
|
285
|
-
end
|
286
|
-
|
287
294
|
# custom input switch for boolean
|
288
|
-
config.wrappers :custom_boolean_switch,
|
295
|
+
config.wrappers :custom_boolean_switch, class: 'mb-3' do |b|
|
289
296
|
b.use :html5
|
290
297
|
b.optional :readonly
|
291
|
-
b.wrapper :form_check_wrapper, tag: 'div', class: '
|
292
|
-
bb.use :input, class: '
|
293
|
-
bb.use :label, class: '
|
298
|
+
b.wrapper :form_check_wrapper, tag: 'div', class: 'form-check form-switch' do |bb|
|
299
|
+
bb.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid'
|
300
|
+
bb.use :label, class: 'form-check-label'
|
294
301
|
bb.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback' }
|
295
|
-
bb.use :hint, wrap_with: {
|
302
|
+
bb.use :hint, wrap_with: { class: 'form-text' }
|
296
303
|
end
|
297
304
|
end
|
298
305
|
|
299
|
-
# custom input for radio buttons and check boxes
|
300
|
-
config.wrappers :custom_collection, item_wrapper_class: 'custom-control', item_label_class: 'custom-control-label', tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
|
301
|
-
b.use :html5
|
302
|
-
b.optional :readonly
|
303
|
-
b.wrapper :legend_tag, tag: 'legend', class: 'col-form-label pt-0' do |ba|
|
304
|
-
ba.use :label_text
|
305
|
-
end
|
306
|
-
b.use :input, class: 'custom-control-input', error_class: 'is-invalid', valid_class: 'is-valid'
|
307
|
-
b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
|
308
|
-
b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
|
309
|
-
end
|
310
306
|
|
311
|
-
#
|
312
|
-
|
313
|
-
|
314
|
-
b.optional :readonly
|
315
|
-
b.wrapper :legend_tag, tag: 'legend', class: 'col-form-label pt-0' do |ba|
|
316
|
-
ba.use :label_text
|
317
|
-
end
|
318
|
-
b.use :input, class: 'custom-control-input', error_class: 'is-invalid', valid_class: 'is-valid'
|
319
|
-
b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
|
320
|
-
b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
|
321
|
-
end
|
322
|
-
|
323
|
-
# custom file input
|
324
|
-
config.wrappers :custom_file, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
|
307
|
+
# Input Group - custom component
|
308
|
+
# see example app and config at https://github.com/heartcombo/simple_form-bootstrap
|
309
|
+
config.wrappers :input_group, class: 'mb-3' do |b|
|
325
310
|
b.use :html5
|
326
311
|
b.use :placeholder
|
327
312
|
b.optional :maxlength
|
328
313
|
b.optional :minlength
|
314
|
+
b.optional :pattern
|
315
|
+
b.optional :min_max
|
329
316
|
b.optional :readonly
|
330
|
-
b.use :label
|
331
|
-
b.wrapper :
|
332
|
-
ba.
|
333
|
-
ba.use :
|
334
|
-
ba.
|
335
|
-
|
336
|
-
b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
|
337
|
-
end
|
338
|
-
|
339
|
-
# custom multi select
|
340
|
-
config.wrappers :custom_multi_select, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
|
341
|
-
b.use :html5
|
342
|
-
b.optional :readonly
|
343
|
-
b.use :label
|
344
|
-
b.wrapper tag: 'div', class: 'd-flex flex-row justify-content-between align-items-center' do |ba|
|
345
|
-
ba.use :input, class: 'custom-select mx-1', error_class: 'is-invalid', valid_class: 'is-valid'
|
317
|
+
b.use :label, class: 'form-label'
|
318
|
+
b.wrapper :input_group_tag, class: 'input-group' do |ba|
|
319
|
+
ba.optional :prepend
|
320
|
+
ba.use :input, class: 'form-control', error_class: 'is-invalid', valid_class: 'is-valid'
|
321
|
+
ba.optional :append
|
322
|
+
ba.use :full_error, wrap_with: { class: 'invalid-feedback' }
|
346
323
|
end
|
347
|
-
b.use :
|
348
|
-
b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
|
349
|
-
end
|
350
|
-
|
351
|
-
# custom range input
|
352
|
-
config.wrappers :custom_range, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
|
353
|
-
b.use :html5
|
354
|
-
b.use :placeholder
|
355
|
-
b.optional :readonly
|
356
|
-
b.optional :step
|
357
|
-
b.use :label
|
358
|
-
b.use :input, class: 'custom-range', error_class: 'is-invalid', valid_class: 'is-valid'
|
359
|
-
b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
|
360
|
-
b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
|
324
|
+
b.use :hint, wrap_with: { class: 'form-text' }
|
361
325
|
end
|
362
326
|
|
363
327
|
|
364
|
-
# Input Group - custom component
|
365
|
-
# see example app and config at https://github.com/rafaelfranca/simple_form-bootstrap
|
366
|
-
# config.wrappers :input_group, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
|
367
|
-
# b.use :html5
|
368
|
-
# b.use :placeholder
|
369
|
-
# b.optional :maxlength
|
370
|
-
# b.optional :minlength
|
371
|
-
# b.optional :pattern
|
372
|
-
# b.optional :min_max
|
373
|
-
# b.optional :readonly
|
374
|
-
# b.use :label
|
375
|
-
# b.wrapper :input_group_tag, tag: 'div', class: 'input-group' do |ba|
|
376
|
-
# ba.optional :prepend
|
377
|
-
# ba.use :input, class: 'form-control', error_class: 'is-invalid', valid_class: 'is-valid'
|
378
|
-
# ba.optional :append
|
379
|
-
# end
|
380
|
-
# b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
|
381
|
-
# b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
|
382
|
-
# end
|
383
|
-
|
384
|
-
|
385
328
|
# Floating Labels form
|
386
329
|
#
|
387
330
|
# floating labels default_wrapper
|
388
|
-
config.wrappers :floating_labels_form,
|
331
|
+
config.wrappers :floating_labels_form, class: 'form-floating mb-3' do |b|
|
389
332
|
b.use :html5
|
390
333
|
b.use :placeholder
|
391
334
|
b.optional :maxlength
|
@@ -395,18 +338,18 @@ SimpleForm.setup do |config|
|
|
395
338
|
b.optional :readonly
|
396
339
|
b.use :input, class: 'form-control', error_class: 'is-invalid', valid_class: 'is-valid'
|
397
340
|
b.use :label
|
398
|
-
b.use :full_error, wrap_with: {
|
399
|
-
b.use :hint, wrap_with: {
|
341
|
+
b.use :full_error, wrap_with: { class: 'invalid-feedback' }
|
342
|
+
b.use :hint, wrap_with: { class: 'form-text' }
|
400
343
|
end
|
401
344
|
|
402
345
|
# custom multi select
|
403
|
-
config.wrappers :floating_labels_select,
|
346
|
+
config.wrappers :floating_labels_select, class: 'form-floating mb-3' do |b|
|
404
347
|
b.use :html5
|
405
348
|
b.optional :readonly
|
406
|
-
b.use :input, class: '
|
349
|
+
b.use :input, class: 'form-select', error_class: 'is-invalid', valid_class: 'is-valid'
|
407
350
|
b.use :label
|
408
|
-
b.use :full_error, wrap_with: {
|
409
|
-
b.use :hint, wrap_with: {
|
351
|
+
b.use :full_error, wrap_with: { class: 'invalid-feedback' }
|
352
|
+
b.use :hint, wrap_with: { class: 'form-text' }
|
410
353
|
end
|
411
354
|
|
412
355
|
|
@@ -423,18 +366,7 @@ SimpleForm.setup do |config|
|
|
423
366
|
file: :vertical_file,
|
424
367
|
radio_buttons: :vertical_collection,
|
425
368
|
range: :vertical_range,
|
426
|
-
time: :vertical_multi_select
|
369
|
+
time: :vertical_multi_select,
|
370
|
+
select: :vertical_select
|
427
371
|
}
|
428
|
-
|
429
|
-
# enable custom form wrappers
|
430
|
-
# config.wrapper_mappings = {
|
431
|
-
# boolean: :custom_boolean,
|
432
|
-
# check_boxes: :custom_collection,
|
433
|
-
# date: :custom_multi_select,
|
434
|
-
# datetime: :custom_multi_select,
|
435
|
-
# file: :custom_file,
|
436
|
-
# radio_buttons: :custom_collection,
|
437
|
-
# range: :custom_range,
|
438
|
-
# time: :custom_multi_select
|
439
|
-
# }
|
440
372
|
end
|
@@ -6,11 +6,9 @@ module SimpleForm
|
|
6
6
|
|
7
7
|
module ClassMethods #:nodoc:
|
8
8
|
def translate_required_html
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
)
|
13
|
-
end
|
9
|
+
I18n.t(:"required.html", scope: i18n_scope, default:
|
10
|
+
%(<abbr title="#{translate_required_text}">#{translate_required_mark}</abbr>)
|
11
|
+
)
|
14
12
|
end
|
15
13
|
|
16
14
|
def translate_required_text
|
@@ -24,10 +24,6 @@ module SimpleForm
|
|
24
24
|
find_validator(:length)
|
25
25
|
end
|
26
26
|
|
27
|
-
def has_tokenizer?(length_validator)
|
28
|
-
length_validator.options[:tokenizer]
|
29
|
-
end
|
30
|
-
|
31
27
|
def maximum_length_value_from(length_validator)
|
32
28
|
if length_validator
|
33
29
|
length_validator.options[:is] || length_validator.options[:maximum]
|
@@ -24,10 +24,6 @@ module SimpleForm
|
|
24
24
|
find_validator(:length)
|
25
25
|
end
|
26
26
|
|
27
|
-
def has_tokenizer?(length_validator)
|
28
|
-
length_validator.options[:tokenizer]
|
29
|
-
end
|
30
|
-
|
31
27
|
def minimum_length_value_from(length_validator)
|
32
28
|
if length_validator
|
33
29
|
length_validator.options[:is] || length_validator.options[:minimum]
|
@@ -497,7 +497,7 @@ module SimpleForm
|
|
497
497
|
conditions = reflection.options[:conditions]
|
498
498
|
conditions = object.instance_exec(&conditions) if conditions.respond_to?(:call)
|
499
499
|
|
500
|
-
relation = relation.where(conditions) if relation.respond_to?(:where)
|
500
|
+
relation = relation.where(conditions) if relation.respond_to?(:where) && conditions.present?
|
501
501
|
relation = relation.order(order) if relation.respond_to?(:order)
|
502
502
|
end
|
503
503
|
|
@@ -1,5 +1,4 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require 'simple_form/i18n_cache'
|
3
2
|
require 'active_support/core_ext/string/output_safety'
|
4
3
|
require 'action_view/helpers'
|
5
4
|
|
@@ -9,8 +8,6 @@ module SimpleForm
|
|
9
8
|
include ERB::Util
|
10
9
|
include ActionView::Helpers::TranslationHelper
|
11
10
|
|
12
|
-
extend I18nCache
|
13
|
-
|
14
11
|
include SimpleForm::Helpers::Autofocus
|
15
12
|
include SimpleForm::Helpers::Disabled
|
16
13
|
include SimpleForm::Helpers::Readonly
|
@@ -12,7 +12,11 @@ module SimpleForm
|
|
12
12
|
inline_label
|
13
13
|
}
|
14
14
|
else
|
15
|
-
|
15
|
+
if include_hidden?
|
16
|
+
build_check_box(unchecked_value, merged_input_options)
|
17
|
+
else
|
18
|
+
build_check_box_without_hidden_field(merged_input_options)
|
19
|
+
end
|
16
20
|
end
|
17
21
|
end
|
18
22
|
|
@@ -60,7 +64,7 @@ module SimpleForm
|
|
60
64
|
# we need the hidden field to be *outside* the label (otherwise it
|
61
65
|
# generates invalid html - html5 only).
|
62
66
|
def build_hidden_field_for_checkbox
|
63
|
-
return "" if !include_hidden? || !unchecked_value
|
67
|
+
return "".html_safe if !include_hidden? || !unchecked_value
|
64
68
|
options = { value: unchecked_value, id: nil, disabled: input_html_options[:disabled] }
|
65
69
|
options[:name] = input_html_options[:name] if input_html_options.key?(:name)
|
66
70
|
options[:form] = input_html_options[:form] if input_html_options.key?(:form)
|
@@ -10,10 +10,8 @@ module SimpleForm
|
|
10
10
|
# Texts can be translated using i18n in "simple_form.yes" and
|
11
11
|
# "simple_form.no" keys. See the example locale file.
|
12
12
|
def self.boolean_collection
|
13
|
-
|
14
|
-
[
|
15
|
-
[I18n.t(:"simple_form.no", default: 'No'), false] ]
|
16
|
-
end
|
13
|
+
[ [I18n.t(:"simple_form.yes", default: 'Yes'), true],
|
14
|
+
[I18n.t(:"simple_form.no", default: 'No'), false] ]
|
17
15
|
end
|
18
16
|
|
19
17
|
def input(wrapper_options = nil)
|
@@ -23,7 +23,7 @@ module SimpleForm
|
|
23
23
|
|
24
24
|
# Sample collection
|
25
25
|
def collection
|
26
|
-
@collection ||= grouped_collection.map { |collection| collection.try(:send, group_method) }.detect(&:present?) || []
|
26
|
+
@collection ||= grouped_collection.map { |collection| group_method.respond_to?(:call) ? group_method.call(collection) : collection.try(:send, group_method) }.detect(&:present?) || []
|
27
27
|
end
|
28
28
|
|
29
29
|
def group_method
|