simple_form 4.1.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1461390ccbd2b434d67a43a84ada68f255d08bc48a9e23d7734075c8f105b400
4
- data.tar.gz: c81c4b918e6f9e467081e8b534273ef8807ef6e508da40077fe4c91b5b85a66f
3
+ metadata.gz: a1bfd4d5f14c750caf9e2fa6287033c0331473215737a96b4bcece8e6f84a7a9
4
+ data.tar.gz: 9c09b014e449f5b8823c062092b864e538c638fd418d782919a9c0a3cd50df78
5
5
  SHA512:
6
- metadata.gz: 71d69573ae8125232a436ea4c23115584497647de1a3b5fa996c9c95f78599b3a3e9ff07ce0812cd5370a1e2c0351dc8fdc43bbea30b7f35d6c68213c68a5f84
7
- data.tar.gz: dacdc01de808196a155ad1219f913bafff072578ad0bb3c0a9602a9f0377d4359f03e54880dd77a3e27307a35754568064d9dd5dcec95abf8a93f5f0164149a8
6
+ metadata.gz: 620056c8b34f6f93229b2ee0771adb0aa7d267fcc22b9d94c214f62287061930e9b0e35a648f47a890452cb8098bc57643a1dce7bbed3df3c2058546b58c5090
7
+ data.tar.gz: 4fa4e5a106b9065405fbba77b8a84ed99e86d84ea4a4435d0a459ee0196a020afbec0ec62fcd2c79f8885d771e48700409ae055ea4858d15b2b5ddd9c3fb5168
@@ -1,10 +1,33 @@
1
1
  ## Unreleased
2
2
 
3
+ ## 5.0.0
4
+
5
+ ### Enhancements
6
+ * Set multiple attribute for grouped selects also. [@ollym](https://github.com/ollym)
7
+ * Removes or renames label classes. [Abduvakilov](https://github.com/Abduvakilov)
8
+ * Support to label custom classes for inline collections. [@feliperenan](https://github.com/feliperenan)
9
+ * Update bootstrap generator template to match v4.3.x. [@m5o](https://github.com/m5o)
10
+ * Allow "required" attribute in generated select elements of PriorityInput. [@mcountis](https://github.com/mcountis)
11
+
12
+ ### Bug fix
13
+ * Do not call `#send` in form object to check whether the attribute is a file input. [@tegon](https://github.com/tegon)
14
+
15
+ ## Deprecations
16
+ * The config `SimpleForm.file_methods` is deprecated and it has no effect. Simple Form now supports automatically discover of file inputs for the following Gems: activestorage, carrierwave, paperclip, refile and shrine. If you are using a custom method that is not from one of the supported Gems, please change your forms to pass the input type explicitly:
17
+
18
+ ```erb
19
+ <%= form.input :avatar, as: :file %>
20
+ ```
21
+
22
+ See http://blog.plataformatec.com.br/2019/09/incorrect-access-control-in-simple-form-cve-2019-16676 for more information.
23
+
24
+ ## 4.1.0
25
+
3
26
  ### Enhancements
4
27
  * Guess input type more carefully. [@sringling](https://github.com/sringling)
5
28
  * Allow custom error on forms without model. [@victorperez](https://github.com/victorperez)
6
29
  * Do not support Ruby < 2.3 anymore. [@gssbzn](https://github.com/gssbzn)
7
- * Add color inout type. [@gssbzn](https://github.com/gssbzn)
30
+ * Add color input type. [@gssbzn](https://github.com/gssbzn)
8
31
 
9
32
  ### Bug fix
10
33
  * Improve disabled option to input_field. [@betelgeuse](https://github.com/betelgeuse)
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009-2016 Plataformatec http://plataformatec.com.br/
1
+ Copyright (c) 2009-2019 Plataformatec http://plataformatec.com.br/
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -288,13 +288,6 @@ end
288
288
  </form>
289
289
  ```
290
290
 
291
- Produces:
292
-
293
- ```html
294
- <input class="string required" id="user_name" maxlength="100"
295
- name="user[name]" size="100" type="text" value="Carlos" />
296
- ```
297
-
298
291
  To view the actual RDocs for this, check them out here - http://rubydoc.info/github/plataformatec/simple_form/master/SimpleForm/FormBuilder:input_field
299
292
 
300
293
  ### Collections
@@ -507,7 +500,7 @@ Creates a collection of radio inputs with labels associated (same API as `collec
507
500
 
508
501
  ```ruby
509
502
  form_for @user do |f|
510
- f.collection_radio_buttons :options, [[true, 'Yes'] ,[false, 'No']], :first, :last
503
+ f.collection_radio_buttons :options, [[true, 'Yes'], [false, 'No']], :first, :last
511
504
  end
512
505
  ```
513
506
 
@@ -524,7 +517,7 @@ Creates a collection of checkboxes with labels associated (same API as `collecti
524
517
 
525
518
  ```ruby
526
519
  form_for @user do |f|
527
- f.collection_check_boxes :options, [[true, 'Yes'] ,[false, 'No']], :first, :last
520
+ f.collection_check_boxes :options, [[true, 'Yes'], [false, 'No']], :first, :last
528
521
  end
529
522
  ```
530
523
 
@@ -545,6 +538,12 @@ form_for @user do |f|
545
538
  end
546
539
  ```
547
540
 
541
+ To add a CSS class to the label item, you can use the `item_label_class` option:
542
+
543
+ ```ruby
544
+ f.collection_check_boxes :role_ids, Role.all, :id, :name, item_label_class: 'my-custom-class'
545
+ ```
546
+
548
547
  ## Available input types and defaults for each column type
549
548
 
550
549
  The following table shows the html element you will get for each attribute
@@ -910,8 +909,8 @@ config.wrappers do |b|
910
909
  end
911
910
  ```
912
911
 
913
- This you set the input and label class to `'label-input-class'` and will set the class `'is-invalid'`
914
- when the input has errors and `'is-valid'` if the input is valid.
912
+ This sets the input and label classes to `'label-input-class'` and will set the class `'is-invalid'`
913
+ if the input has errors and `'is-valid'` if the input is valid.
915
914
 
916
915
  If you want to customize the custom _Form components_ on demand you can give it a name like this:
917
916
 
@@ -1144,7 +1143,7 @@ by passing the html5 option:
1144
1143
  ### Using non Active Record objects
1145
1144
 
1146
1145
  There are few ways to build forms with objects that don't inherit from Active Record, as
1147
- follow:
1146
+ follows:
1148
1147
 
1149
1148
  You can include the module `ActiveModel::Model`.
1150
1149
 
@@ -1248,7 +1247,7 @@ https://github.com/plataformatec/simple_form/issues
1248
1247
 
1249
1248
  ## License
1250
1249
 
1251
- MIT License. Copyright 2009-2018 Plataformatec. http://plataformatec.com.br
1250
+ MIT License. Copyright 2009-2019 Plataformatec. http://plataformatec.com.br
1252
1251
 
1253
1252
  You are not granted rights or licenses to the trademarks of the Plataformatec, including without
1254
1253
  limitation the Simple Form name or logo.
@@ -129,9 +129,6 @@ SimpleForm.setup do |config|
129
129
  # change this configuration to true.
130
130
  config.browser_validations = false
131
131
 
132
- # Collection of methods to detect if a file type was given.
133
- # config.file_methods = [ :mounted_as, :file?, :public_filename, :attached? ]
134
-
135
132
  # Custom mappings for input types. This should be a hash containing a regexp
136
133
  # to match as key, and the input type that will be used when the field name
137
134
  # matches the regexp as value.
@@ -57,7 +57,7 @@ SimpleForm.setup do |config|
57
57
  b.optional :pattern
58
58
  b.optional :min_max
59
59
  b.optional :readonly
60
- b.use :label, class: 'form-control-label'
60
+ b.use :label
61
61
  b.use :input, class: 'form-control', error_class: 'is-invalid', valid_class: 'is-valid'
62
62
  b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback' }
63
63
  b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
@@ -76,7 +76,7 @@ SimpleForm.setup do |config|
76
76
  end
77
77
 
78
78
  # vertical input for radio buttons and check boxes
79
- config.wrappers :vertical_collection, item_wrapper_class: 'form-check', tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
79
+ config.wrappers :vertical_collection, item_wrapper_class: 'form-check', item_label_class: 'form-check-label', tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
80
80
  b.use :html5
81
81
  b.optional :readonly
82
82
  b.wrapper :legend_tag, tag: 'legend', class: 'col-form-label pt-0' do |ba|
@@ -88,7 +88,7 @@ SimpleForm.setup do |config|
88
88
  end
89
89
 
90
90
  # vertical input for inline radio buttons and check boxes
91
- config.wrappers :vertical_collection_inline, item_wrapper_class: 'form-check form-check-inline', tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
91
+ config.wrappers :vertical_collection_inline, item_wrapper_class: 'form-check form-check-inline', item_label_class: 'form-check-label', tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
92
92
  b.use :html5
93
93
  b.optional :readonly
94
94
  b.wrapper :legend_tag, tag: 'legend', class: 'col-form-label pt-0' do |ba|
@@ -108,7 +108,7 @@ SimpleForm.setup do |config|
108
108
  b.optional :readonly
109
109
  b.use :label
110
110
  b.use :input, class: 'form-control-file', error_class: 'is-invalid', valid_class: 'is-valid'
111
- b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
111
+ b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback' }
112
112
  b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
113
113
  end
114
114
 
@@ -116,7 +116,7 @@ SimpleForm.setup do |config|
116
116
  config.wrappers :vertical_multi_select, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
117
117
  b.use :html5
118
118
  b.optional :readonly
119
- b.use :label, class: 'form-control-label'
119
+ b.use :label
120
120
  b.wrapper tag: 'div', class: 'd-flex flex-row justify-content-between align-items-center' do |ba|
121
121
  ba.use :input, class: 'form-control mx-1', error_class: 'is-invalid', valid_class: 'is-valid'
122
122
  end
@@ -174,10 +174,10 @@ SimpleForm.setup do |config|
174
174
  end
175
175
 
176
176
  # horizontal input for radio buttons and check boxes
177
- config.wrappers :horizontal_collection, item_wrapper_class: 'form-check', tag: 'div', class: 'form-group row', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
177
+ config.wrappers :horizontal_collection, item_wrapper_class: 'form-check', item_label_class: 'form-check-label', tag: 'div', class: 'form-group row', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
178
178
  b.use :html5
179
179
  b.optional :readonly
180
- b.use :label, class: 'col-sm-3 form-control-label'
180
+ b.use :label, class: 'col-sm-3 col-form-label pt-0'
181
181
  b.wrapper :grid_wrapper, tag: 'div', class: 'col-sm-9' do |ba|
182
182
  ba.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid'
183
183
  ba.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
@@ -186,10 +186,10 @@ SimpleForm.setup do |config|
186
186
  end
187
187
 
188
188
  # horizontal input for inline radio buttons and check boxes
189
- config.wrappers :horizontal_collection_inline, item_wrapper_class: 'form-check form-check-inline', tag: 'div', class: 'form-group row', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
189
+ config.wrappers :horizontal_collection_inline, item_wrapper_class: 'form-check form-check-inline', item_label_class: 'form-check-label', tag: 'div', class: 'form-group row', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
190
190
  b.use :html5
191
191
  b.optional :readonly
192
- b.use :label, class: 'col-sm-3 form-control-label'
192
+ b.use :label, class: 'col-sm-3 col-form-label pt-0'
193
193
  b.wrapper :grid_wrapper, tag: 'div', class: 'col-sm-9' do |ba|
194
194
  ba.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid'
195
195
  ba.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
@@ -204,7 +204,7 @@ SimpleForm.setup do |config|
204
204
  b.optional :maxlength
205
205
  b.optional :minlength
206
206
  b.optional :readonly
207
- b.use :label, class: 'col-sm-3 form-control-label'
207
+ b.use :label, class: 'col-sm-3 col-form-label'
208
208
  b.wrapper :grid_wrapper, tag: 'div', class: 'col-sm-9' do |ba|
209
209
  ba.use :input, error_class: 'is-invalid', valid_class: 'is-valid'
210
210
  ba.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
@@ -216,7 +216,7 @@ SimpleForm.setup do |config|
216
216
  config.wrappers :horizontal_multi_select, tag: 'div', class: 'form-group row', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
217
217
  b.use :html5
218
218
  b.optional :readonly
219
- b.use :label, class: 'col-sm-3 control-label'
219
+ b.use :label, class: 'col-sm-3 col-form-label'
220
220
  b.wrapper :grid_wrapper, tag: 'div', class: 'col-sm-9' do |ba|
221
221
  ba.wrapper tag: 'div', class: 'd-flex flex-row justify-content-between align-items-center' do |bb|
222
222
  bb.use :input, class: 'form-control mx-1', error_class: 'is-invalid', valid_class: 'is-valid'
@@ -232,7 +232,7 @@ SimpleForm.setup do |config|
232
232
  b.use :placeholder
233
233
  b.optional :readonly
234
234
  b.optional :step
235
- b.use :label, class: 'col-sm-3 form-control-label'
235
+ b.use :label, class: 'col-sm-3 col-form-label'
236
236
  b.wrapper :grid_wrapper, tag: 'div', class: 'col-sm-9' do |ba|
237
237
  ba.use :input, class: 'form-control-range', error_class: 'is-invalid', valid_class: 'is-valid'
238
238
  ba.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
@@ -260,7 +260,7 @@ SimpleForm.setup do |config|
260
260
  end
261
261
 
262
262
  # inline input for boolean
263
- config.wrappers :inline_boolean, tag: 'span', class: 'form-check flex-wrap justify-content-start mr-sm-2', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
263
+ config.wrappers :inline_boolean, tag: 'span', class: 'form-check mb-2 mr-sm-2', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
264
264
  b.use :html5
265
265
  b.optional :readonly
266
266
  b.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid'
@@ -284,10 +284,11 @@ SimpleForm.setup do |config|
284
284
  end
285
285
  end
286
286
 
287
+ # custom input switch for boolean
287
288
  config.wrappers :custom_boolean_switch, tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
288
289
  b.use :html5
289
290
  b.optional :readonly
290
- b.wrapper :form_check_wrapper, tag: 'div', class: 'custom-control custom-checkbox-switch' do |bb|
291
+ b.wrapper :form_check_wrapper, tag: 'div', class: 'custom-control custom-switch' do |bb|
291
292
  bb.use :input, class: 'custom-control-input', error_class: 'is-invalid', valid_class: 'is-valid'
292
293
  bb.use :label, class: 'custom-control-label'
293
294
  bb.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback' }
@@ -296,7 +297,7 @@ SimpleForm.setup do |config|
296
297
  end
297
298
 
298
299
  # custom input for radio buttons and check boxes
299
- config.wrappers :custom_collection, item_wrapper_class: 'custom-control', tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
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|
300
301
  b.use :html5
301
302
  b.optional :readonly
302
303
  b.wrapper :legend_tag, tag: 'legend', class: 'col-form-label pt-0' do |ba|
@@ -308,7 +309,7 @@ SimpleForm.setup do |config|
308
309
  end
309
310
 
310
311
  # custom input for inline radio buttons and check boxes
311
- config.wrappers :custom_collection_inline, item_wrapper_class: 'custom-control custom-control-inline', tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
312
+ config.wrappers :custom_collection_inline, item_wrapper_class: 'custom-control custom-control-inline', item_label_class: 'custom-control-label', tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
312
313
  b.use :html5
313
314
  b.optional :readonly
314
315
  b.wrapper :legend_tag, tag: 'legend', class: 'col-form-label pt-0' do |ba|
@@ -326,7 +327,7 @@ SimpleForm.setup do |config|
326
327
  b.optional :maxlength
327
328
  b.optional :minlength
328
329
  b.optional :readonly
329
- b.use :label, class: 'form-control-label'
330
+ b.use :label
330
331
  b.wrapper :custom_file_wrapper, tag: 'div', class: 'custom-file' do |ba|
331
332
  ba.use :input, class: 'custom-file-input', error_class: 'is-invalid', valid_class: 'is-valid'
332
333
  ba.use :label, class: 'custom-file-label'
@@ -339,7 +340,7 @@ SimpleForm.setup do |config|
339
340
  config.wrappers :custom_multi_select, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
340
341
  b.use :html5
341
342
  b.optional :readonly
342
- b.use :label, class: 'form-control-label'
343
+ b.use :label
343
344
  b.wrapper tag: 'div', class: 'd-flex flex-row justify-content-between align-items-center' do |ba|
344
345
  ba.use :input, class: 'custom-select mx-1', error_class: 'is-invalid', valid_class: 'is-valid'
345
346
  end
@@ -353,7 +354,7 @@ SimpleForm.setup do |config|
353
354
  b.use :placeholder
354
355
  b.optional :readonly
355
356
  b.optional :step
356
- b.use :label, class: 'form-control-label'
357
+ b.use :label
357
358
  b.use :input, class: 'custom-range', error_class: 'is-invalid', valid_class: 'is-valid'
358
359
  b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
359
360
  b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
@@ -370,7 +371,7 @@ SimpleForm.setup do |config|
370
371
  # b.optional :pattern
371
372
  # b.optional :min_max
372
373
  # b.optional :readonly
373
- # b.use :label, class: 'form-control-label'
374
+ # b.use :label
374
375
  # b.wrapper :input_group_tag, tag: 'div', class: 'input-group' do |ba|
375
376
  # ba.optional :prepend
376
377
  # ba.use :input, class: 'form-control', error_class: 'is-invalid', valid_class: 'is-valid'
@@ -393,7 +394,7 @@ SimpleForm.setup do |config|
393
394
  b.optional :min_max
394
395
  b.optional :readonly
395
396
  b.use :input, class: 'form-control', error_class: 'is-invalid', valid_class: 'is-valid'
396
- b.use :label, class: 'form-control-label'
397
+ b.use :label
397
398
  b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback' }
398
399
  b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
399
400
  end
@@ -402,8 +403,8 @@ SimpleForm.setup do |config|
402
403
  config.wrappers :floating_labels_select, tag: 'div', class: 'form-label-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
403
404
  b.use :html5
404
405
  b.optional :readonly
405
- b.use :input, class: 'custom-select custom-select-lg', error_class: 'is-invalid', valid_class: 'is-valid'
406
- b.use :label, class: 'form-control-label'
406
+ b.use :input, class: 'custom-select', error_class: 'is-invalid', valid_class: 'is-valid'
407
+ b.use :label
407
408
  b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback' }
408
409
  b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
409
410
  end
@@ -38,6 +38,17 @@ to
38
38
  See https://github.com/plataformatec/simple_form/pull/997 for more information.
39
39
  WARN
40
40
 
41
+ FILE_METHODS_DEPRECATION_WARN = <<-WARN
42
+ [SIMPLE_FORM] SimpleForm.file_methods is deprecated and has no effect.
43
+
44
+ Since version 5, Simple Form now supports automatically discover of file inputs for the following Gems: activestorage, carrierwave, paperclip, refile and shrine.
45
+ If you are using a custom method that is not from one of the supported Gems, please change your forms to pass the input type explicitly:
46
+
47
+ <%= form.input :avatar, as: :file %>
48
+
49
+ See http://blog.plataformatec.com.br/2019/09/incorrect-access-control-in-simple-form-cve-2019-16676 for more information.
50
+ WARN
51
+
41
52
  @@configured = false
42
53
 
43
54
  def self.configured? #:nodoc:
@@ -120,10 +131,6 @@ See https://github.com/plataformatec/simple_form/pull/997 for more information.
120
131
  mattr_accessor :browser_validations
121
132
  @@browser_validations = true
122
133
 
123
- # Collection of methods to detect if a file type was given.
124
- mattr_accessor :file_methods
125
- @@file_methods = %i[mounted_as file? public_filename attached?]
126
-
127
134
  # Custom mappings for input types. This should be a hash containing a regexp
128
135
  # to match as key, and the input type that will be used when the field name
129
136
  # matches the regexp as value, such as { /count/ => :integer }.
@@ -265,6 +272,16 @@ See https://github.com/plataformatec/simple_form/pull/997 for more information.
265
272
  @@form_class = value
266
273
  end
267
274
 
275
+ def self.file_methods=(file_methods)
276
+ ActiveSupport::Deprecation.warn(FILE_METHODS_DEPRECATION_WARN, caller)
277
+ @@file_methods = file_methods
278
+ end
279
+
280
+ def self.file_methods
281
+ ActiveSupport::Deprecation.warn(FILE_METHODS_DEPRECATION_WARN, caller)
282
+ @@file_methods
283
+ end
284
+
268
285
  # Default way to setup Simple Form. Run rails generate simple_form:install
269
286
  # to create a fresh initializer with all configuration values.
270
287
  def self.setup
@@ -511,7 +511,7 @@ module SimpleForm
511
511
  when :has_one
512
512
  raise ArgumentError, ":has_one associations are not supported by f.association"
513
513
  else
514
- if options[:as] == :select
514
+ if options[:as] == :select || options[:as] == :grouped_select
515
515
  html_options = options[:input_html] ||= {}
516
516
  html_options[:multiple] = true unless html_options.key?(:multiple)
517
517
  end
@@ -572,9 +572,28 @@ module SimpleForm
572
572
  }.try(:last) if SimpleForm.input_mappings
573
573
  end
574
574
 
575
+ # Internal: Try to discover whether an attribute corresponds to a file or not.
576
+ #
577
+ # Most upload Gems add some kind of attributes to the ActiveRecord's model they are included in.
578
+ # This method tries to guess if an attribute belongs to some of these Gems by checking the presence
579
+ # of their methods using `#respond_to?`.
580
+ #
581
+ # Note: This does not support multiple file upload inputs, as this is very application-specific.
582
+ #
583
+ # The order here was choosen based on the popularity of Gems and for commodity - e.g. the method
584
+ # with the suffix `_url` is present in three Gems, so it's checked with priority:
585
+ #
586
+ # - `#{attribute_name}_attachment` - ActiveStorage >= `5.2` and Refile >= `0.2.0` <= `0.4.0`
587
+ # - `#{attribute_name}_url` - Shrine >= `0.9.0`, Refile >= `0.6.0` and CarrierWave >= `0.2.1`
588
+ # - `#{attribute_name}_attacher` - Refile >= `0.4.0` and Shrine >= `0.9.0`
589
+ # - `#{attribute_name}_file_name` - Paperclip ~> `2.0` (added for backwards compatibility)
590
+ #
591
+ # Returns a Boolean.
575
592
  def file_method?(attribute_name)
576
- file = @object.send(attribute_name) if @object.respond_to?(attribute_name)
577
- file && SimpleForm.file_methods.any? { |m| file.respond_to?(m) }
593
+ @object.respond_to?("#{attribute_name}_attachment") ||
594
+ @object.respond_to?("#{attribute_name}_url") ||
595
+ @object.respond_to?("#{attribute_name}_attacher") ||
596
+ @object.respond_to?("#{attribute_name}_file_name")
578
597
  end
579
598
 
580
599
  def find_attribute_column(attribute_name)
@@ -15,10 +15,6 @@ module SimpleForm
15
15
 
16
16
  protected
17
17
 
18
- def has_required?
19
- false
20
- end
21
-
22
18
  def skip_include_blank?
23
19
  super || input_priority.present?
24
20
  end
@@ -48,7 +48,9 @@ module SimpleForm
48
48
  private
49
49
 
50
50
  def render_component(builder)
51
- builder.radio_button + builder.label(class: "collection_radio_buttons")
51
+ label_class = "#{@options[:item_label_class]} collection_radio_buttons".strip
52
+
53
+ builder.radio_button + builder.label(class: label_class)
52
54
  end
53
55
  end
54
56
 
@@ -62,7 +64,9 @@ module SimpleForm
62
64
  private
63
65
 
64
66
  def render_component(builder)
65
- builder.check_box + builder.label(class: "collection_check_boxes")
67
+ label_class = "#{@options[:item_label_class]} collection_check_boxes".strip
68
+
69
+ builder.check_box + builder.label(class: label_class)
66
70
  end
67
71
  end
68
72
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module SimpleForm
3
- VERSION = "4.1.0".freeze
3
+ VERSION = "5.0.0".freeze
4
4
  end
@@ -45,8 +45,17 @@ class BuilderTest < ActionView::TestCase
45
45
 
46
46
  test "collection radio sanitizes collection values for labels correctly" do
47
47
  with_collection_radio_buttons @user, :name, ['$0.99', '$1.99'], :to_s, :to_s
48
- assert_select 'label.collection_radio_buttons[for=user_name_099]', '$0.99'
49
- assert_select 'label.collection_radio_buttons[for=user_name_199]', '$1.99'
48
+
49
+ # Rails 6 changed the way it sanitizes the values
50
+ # https://github.com/rails/rails/blob/6-0-stable/actionview/lib/action_view/helpers/tags/base.rb#L141
51
+ # https://github.com/rails/rails/blob/5-2-stable/actionview/lib/action_view/helpers/tags/base.rb#L141
52
+ if ActionView::VERSION::MAJOR == 5
53
+ assert_select 'label.collection_radio_buttons[for=user_name_099]', '$0.99'
54
+ assert_select 'label.collection_radio_buttons[for=user_name_199]', '$1.99'
55
+ else
56
+ assert_select 'label.collection_radio_buttons[for=user_name_0_99]', '$0.99'
57
+ assert_select 'label.collection_radio_buttons[for=user_name_1_99]', '$1.99'
58
+ end
50
59
  end
51
60
 
52
61
  test "collection radio checks the correct value to local variables" do
@@ -292,8 +301,17 @@ class BuilderTest < ActionView::TestCase
292
301
 
293
302
  test "collection check box sanitizes collection values for labels correctly" do
294
303
  with_collection_check_boxes @user, :name, ['$0.99', '$1.99'], :to_s, :to_s
295
- assert_select 'label.collection_check_boxes[for=user_name_099]', '$0.99'
296
- assert_select 'label.collection_check_boxes[for=user_name_199]', '$1.99'
304
+
305
+ # Rails 6 changed the way it sanitizes the values
306
+ # https://github.com/rails/rails/blob/6-0-stable/actionview/lib/action_view/helpers/tags/base.rb#L141
307
+ # https://github.com/rails/rails/blob/5-2-stable/actionview/lib/action_view/helpers/tags/base.rb#L141
308
+ if ActionView::VERSION::MAJOR == 5
309
+ assert_select 'label.collection_check_boxes[for=user_name_099]', '$0.99'
310
+ assert_select 'label.collection_check_boxes[for=user_name_199]', '$1.99'
311
+ else
312
+ assert_select 'label.collection_check_boxes[for=user_name_0_99]', '$0.99'
313
+ assert_select 'label.collection_check_boxes[for=user_name_1_99]', '$1.99'
314
+ end
297
315
  end
298
316
 
299
317
  test "collection check box checks the correct value to local variables" do
@@ -243,4 +243,10 @@ class AssociationTest < ActionView::TestCase
243
243
  assert_equal({ as: :check_boxes, collection_wrapper_tag: :ul, item_wrapper_tag: :li },
244
244
  options)
245
245
  end
246
+
247
+ test 'builder with group select considers multiple select by default' do
248
+ with_association_for @user, :tags, as: :grouped_select, group_method: :group_method
249
+
250
+ assert_select 'select[multiple="multiple"].grouped_select'
251
+ end
246
252
  end
@@ -239,31 +239,24 @@ class FormBuilderTest < ActionView::TestCase
239
239
  assert_select 'form select#user_updated_at_1i.datetime'
240
240
  end
241
241
 
242
- test 'builder generates file for file columns' do
243
- @user.avatar = MiniTest::Mock.new
244
- @user.avatar.expect(:public_filename, true)
245
- @user.avatar.expect(:!, false)
246
-
247
- with_form_for @user, :avatar
248
- assert_select 'form input#user_avatar.file'
242
+ test 'builder generates file input for ActiveStorage >= 5.2 and Refile >= 0.2.0 <= 0.4.0' do
243
+ with_form_for UserWithAttachment.build, :avatar
244
+ assert_select 'form input#user_with_attachment_avatar.file'
249
245
  end
250
246
 
251
- test 'builder generates file for activestorage entries' do
252
- @user.avatar = MiniTest::Mock.new
253
- @user.avatar.expect(:attached?, false)
254
- @user.avatar.expect(:!, false)
255
-
256
- with_form_for @user, :avatar
257
- assert_select 'form input#user_avatar.file'
247
+ test 'builder generates file input for Shrine >= 0.9.0, Refile >= 0.6.0 and CarrierWave >= 0.2.1' do
248
+ with_form_for UserWithAttachment.build, :cover
249
+ assert_select 'form input#user_with_attachment_cover.file'
258
250
  end
259
251
 
260
- test 'builder generates file for attributes that are real db columns but have file methods' do
261
- @user.home_picture = MiniTest::Mock.new
262
- @user.home_picture.expect(:mounted_as, true)
263
- @user.home_picture.expect(:!, false)
252
+ test 'builder generates file input for Refile >= 0.4.0 and Shrine >= 0.9.0' do
253
+ with_form_for UserWithAttachment.build, :profile_image
254
+ assert_select 'form input#user_with_attachment_profile_image.file'
255
+ end
264
256
 
265
- with_form_for @user, :home_picture
266
- assert_select 'form input#user_home_picture.file'
257
+ test 'builder generates file input for Paperclip ~> 2.0' do
258
+ with_form_for UserWithAttachment.build, :portrait
259
+ assert_select 'form input#user_with_attachment_portrait.file'
267
260
  end
268
261
 
269
262
  test 'build generates select if a collection is given' do
@@ -161,7 +161,7 @@ class WrapperTest < ActionView::TestCase
161
161
  test 'custom wrappers can have full error message on attributes' do
162
162
  swap_wrapper :default, custom_wrapper_with_full_error do
163
163
  with_form_for @user, :name
164
- assert_select 'span.error', "Name cannot be blank"
164
+ assert_select 'span.error', "Super User Name! cannot be blank"
165
165
  end
166
166
  end
167
167
 
@@ -316,4 +316,12 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
316
316
  assert_select 'span.checkbox > label', '200'
317
317
  end
318
318
  end
319
+
320
+ test 'input check boxes with inline style support label custom classes' do
321
+ swap SimpleForm, boolean_style: :inline do
322
+ with_input_for @user, :gender, :check_boxes, collection: %i[male female], item_label_class: 'beautiful-label'
323
+
324
+ assert_select 'label.beautiful-label', count: 2
325
+ end
326
+ end
319
327
  end
@@ -439,4 +439,12 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
439
439
  assert_select 'span.radio > label', '200'
440
440
  end
441
441
  end
442
+
443
+ test 'input check boxes with inline style support label custom classes' do
444
+ swap SimpleForm, boolean_style: :inline do
445
+ with_input_for @user, :gender, :radio_buttons, collection: %i[male female], item_label_class: 'beautiful-label'
446
+
447
+ assert_select 'label.beautiful-label', count: 2
448
+ end
449
+ end
442
450
  end
@@ -36,15 +36,15 @@ class PriorityInputTest < ActionView::TestCase
36
36
  assert_no_select 'select option[value=""]', /^$/
37
37
  end
38
38
 
39
- test 'priority input does not generate invalid required html attribute' do
39
+ test 'priority input does generate select element with required html attribute' do
40
40
  with_input_for @user, :country, :country
41
41
  assert_select 'select.required'
42
- assert_no_select 'select[required]'
42
+ assert_select 'select[required]'
43
43
  end
44
44
 
45
- test 'priority input does not generate invalid aria-required html attribute' do
45
+ test 'priority input does generate select element with aria-required html attribute' do
46
46
  with_input_for @user, :country, :country
47
47
  assert_select 'select.required'
48
- assert_no_select 'select[aria-required]'
48
+ assert_select 'select[aria-required]'
49
49
  end
50
50
  end
@@ -76,7 +76,11 @@ Friend = Struct.new(:id, :name) do
76
76
  end
77
77
  end
78
78
 
79
- class Tag < Company; end
79
+ class Tag < Company
80
+ def group_method
81
+ ["category-1"]
82
+ end
83
+ end
80
84
 
81
85
  TagGroup = Struct.new(:id, :name, :tags)
82
86
 
@@ -200,7 +204,7 @@ class User
200
204
 
201
205
  def self.human_attribute_name(attribute, options = {})
202
206
  case attribute
203
- when 'name'
207
+ when 'name', :name
204
208
  'Super User Name!'
205
209
  when 'description'
206
210
  'User Description!'
@@ -329,3 +333,21 @@ end
329
333
 
330
334
  class UserNumber1And2 < User
331
335
  end
336
+
337
+ class UserWithAttachment < User
338
+ def avatar_attachment
339
+ OpenStruct.new
340
+ end
341
+
342
+ def cover_url
343
+ "/uploads/cover.png"
344
+ end
345
+
346
+ def profile_image_attacher
347
+ OpenStruct.new
348
+ end
349
+
350
+ def portrait_file_name
351
+ "portrait.png"
352
+ end
353
+ end
@@ -1,15 +1,13 @@
1
1
  # frozen_string_literal: true
2
- require 'bundler/setup'
3
-
4
2
  require 'minitest/autorun'
5
3
 
6
4
  require 'active_model'
7
5
  require 'action_controller'
8
6
  require 'action_view'
7
+
9
8
  ActionView::RoutingUrlFor.send(:include, ActionDispatch::Routing::UrlFor)
10
9
 
11
10
  require 'action_view/template'
12
-
13
11
  require 'action_view/test_case'
14
12
 
15
13
  module Rails
@@ -41,10 +39,14 @@ if ActiveSupport::TestCase.respond_to?(:test_order=)
41
39
  ActiveSupport::TestCase.test_order = :random
42
40
  end
43
41
 
42
+ require "rails/test_unit/line_filtering"
43
+
44
44
  class ActionView::TestCase
45
45
  include MiscHelpers
46
46
  include SimpleForm::ActionViewExtensions::FormHelper
47
47
 
48
+ extend Rails::LineFiltering
49
+
48
50
  setup :set_controller
49
51
  setup :setup_users
50
52
 
@@ -89,4 +91,5 @@ class ActionView::TestCase
89
91
  alias :validating_user_path :user_path
90
92
  alias :validating_users_path :user_path
91
93
  alias :other_validating_user_path :user_path
94
+ alias :user_with_attachment_path :user_path
92
95
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_form
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - José Valim
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-11-22 00:00:00.000000000 Z
13
+ date: 2019-09-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activemodel
@@ -169,8 +169,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
169
  - !ruby/object:Gem::Version
170
170
  version: '0'
171
171
  requirements: []
172
- rubyforge_project: simple_form
173
- rubygems_version: 2.7.6
172
+ rubyforge_project:
173
+ rubygems_version: 2.7.3
174
174
  signing_key:
175
175
  specification_version: 4
176
176
  summary: Forms made easy!