simple_form 4.0.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +41 -0
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +12 -13
  5. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +0 -6
  6. data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +24 -23
  7. data/lib/simple_form/components/errors.rb +5 -1
  8. data/lib/simple_form/form_builder.rb +29 -10
  9. data/lib/simple_form/inputs/base.rb +4 -1
  10. data/lib/simple_form/inputs/boolean_input.rb +1 -0
  11. data/lib/simple_form/inputs/color_input.rb +14 -0
  12. data/lib/simple_form/inputs/priority_input.rb +0 -4
  13. data/lib/simple_form/inputs/string_input.rb +1 -1
  14. data/lib/simple_form/inputs.rb +1 -0
  15. data/lib/simple_form/tags.rb +6 -2
  16. data/lib/simple_form/version.rb +1 -1
  17. data/lib/simple_form.rb +21 -4
  18. data/test/action_view_extensions/builder_test.rb +22 -4
  19. data/test/form_builder/association_test.rb +6 -0
  20. data/test/form_builder/error_test.rb +6 -0
  21. data/test/form_builder/general_test.rb +19 -20
  22. data/test/form_builder/input_field_test.rb +3 -9
  23. data/test/form_builder/wrapper_test.rb +1 -1
  24. data/test/inputs/boolean_input_test.rb +8 -0
  25. data/test/inputs/collection_check_boxes_input_test.rb +8 -0
  26. data/test/inputs/collection_radio_buttons_input_test.rb +8 -0
  27. data/test/inputs/color_input_test.rb +10 -0
  28. data/test/inputs/datetime_input_test.rb +2 -12
  29. data/test/inputs/disabled_test.rb +13 -0
  30. data/test/inputs/discovery_test.rb +21 -0
  31. data/test/inputs/priority_input_test.rb +6 -14
  32. data/test/inputs/string_input_test.rb +8 -15
  33. data/test/support/discovery_inputs.rb +7 -0
  34. data/test/support/misc_helpers.rb +6 -0
  35. data/test/support/models.rb +25 -6
  36. data/test/test_helper.rb +6 -3
  37. metadata +40 -37
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: bdc43deadddaaf9bc4b3872855d677c5e560066d
4
- data.tar.gz: 1a58416a2a4977e825f25c345ba41abec78c85a9
2
+ SHA256:
3
+ metadata.gz: a1bfd4d5f14c750caf9e2fa6287033c0331473215737a96b4bcece8e6f84a7a9
4
+ data.tar.gz: 9c09b014e449f5b8823c062092b864e538c638fd418d782919a9c0a3cd50df78
5
5
  SHA512:
6
- metadata.gz: 9812df086c46e0abe897274ac1260cac8dccb7d906da88f75182efc741a4802931f0c5c8b556dfa1ab0793cf93fe9cd68909d69948cee1f43f26b7a807e3ae29
7
- data.tar.gz: dca2a8eaf706656f77f5294a18068521aa83a9ab2fbd1e269009e68751e9ea2d2811127d5daa017d137c5c9ec5c74b62bbfaaa3fb002211f6778d09cb19a066c
6
+ metadata.gz: 620056c8b34f6f93229b2ee0771adb0aa7d267fcc22b9d94c214f62287061930e9b0e35a648f47a890452cb8098bc57643a1dce7bbed3df3c2058546b58c5090
7
+ data.tar.gz: 4fa4e5a106b9065405fbba77b8a84ed99e86d84ea4a4435d0a459ee0196a020afbec0ec62fcd2c79f8885d771e48700409ae055ea4858d15b2b5ddd9c3fb5168
data/CHANGELOG.md CHANGED
@@ -1,5 +1,46 @@
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
+
26
+ ### Enhancements
27
+ * Guess input type more carefully. [@sringling](https://github.com/sringling)
28
+ * Allow custom error on forms without model. [@victorperez](https://github.com/victorperez)
29
+ * Do not support Ruby < 2.3 anymore. [@gssbzn](https://github.com/gssbzn)
30
+ * Add color input type. [@gssbzn](https://github.com/gssbzn)
31
+
32
+ ### Bug fix
33
+ * Improve disabled option to input_field. [@betelgeuse](https://github.com/betelgeuse)
34
+ * Memoize `input_html_classes` in `SimpleForm::Inputs::Base`. [@RigoTheDev](https://github.com/RigoTheDev)
35
+ * Fix column type citext HTML5 input type bug. [@brucew](https://github.com/brucew)
36
+ * Use form attribute in the nested boolean hidden field when it is given. [@feliperenan](https://github.com/feliperenan)
37
+
38
+ ## 4.0.1
39
+
40
+ ### Bug fix
41
+ * Do not support Rails 4 anymore. [@rafaelfranca](https://github.com/rafaelfranca)
42
+ * Add missing comma. [@vill](https://github.com/vill)
43
+
3
44
  ## 4.0.0
4
45
 
5
46
  ### Enhancements
data/MIT-LICENSE CHANGED
@@ -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.
@@ -87,9 +87,6 @@ SimpleForm.setup do |config|
87
87
  # CSS class to add for error notification helper.
88
88
  config.error_notification_class = 'error_notification'
89
89
 
90
- # ID to add for error notification helper.
91
- # config.error_notification_id = nil
92
-
93
90
  # Series of attempts to detect a default label method for collection.
94
91
  # config.collection_label_methods = [ :to_label, :name, :title, :to_s ]
95
92
 
@@ -132,9 +129,6 @@ SimpleForm.setup do |config|
132
129
  # change this configuration to true.
133
130
  config.browser_validations = false
134
131
 
135
- # Collection of methods to detect if a file type was given.
136
- # config.file_methods = [ :mounted_as, :file?, :public_filename :attached? ]
137
-
138
132
  # Custom mappings for input types. This should be a hash containing a regexp
139
133
  # to match as key, and the input type that will be used when the field name
140
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
@@ -11,7 +11,7 @@ module SimpleForm
11
11
  end
12
12
 
13
13
  def has_errors?
14
- object && object.respond_to?(:errors) && errors.present?
14
+ object_with_errors? || object.nil? && has_custom_error?
15
15
  end
16
16
 
17
17
  def has_value?
@@ -34,6 +34,10 @@ module SimpleForm
34
34
  has_custom_error? ? options[:error] : full_errors.send(error_method)
35
35
  end
36
36
 
37
+ def object_with_errors?
38
+ object && object.respond_to?(:errors) && errors.present?
39
+ end
40
+
37
41
  def error_method
38
42
  options[:error_method] || SimpleForm.error_method
39
43
  end
@@ -165,7 +165,7 @@ module SimpleForm
165
165
  components = (wrapper.components.map(&:namespace) & ATTRIBUTE_COMPONENTS)
166
166
 
167
167
  options = options.dup
168
- options[:input_html] = options.except(:as, :boolean_style, :collection, :label_method, :value_method, :prompt, *components)
168
+ options[:input_html] = options.except(:as, :boolean_style, :collection, :disabled, :label_method, :value_method, :prompt, *components)
169
169
  options = @defaults.deep_dup.deep_merge(options) if @defaults
170
170
 
171
171
  input = find_input(attribute_name, options)
@@ -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
@@ -552,12 +552,12 @@ module SimpleForm
552
552
  :datetime
553
553
  when :string, :citext, nil
554
554
  case attribute_name.to_s
555
- when /password/ then :password
556
- when /time_zone/ then :time_zone
557
- when /country/ then :country
558
- when /email/ then :email
559
- when /phone/ then :tel
560
- when /url/ then :url
555
+ when /(?:\b|\W|_)password(?:\b|\W|_)/ then :password
556
+ when /(?:\b|\W|_)time_zone(?:\b|\W|_)/ then :time_zone
557
+ when /(?:\b|\W|_)country(?:\b|\W|_)/ then :country
558
+ when /(?:\b|\W|_)email(?:\b|\W|_)/ then :email
559
+ when /(?:\b|\W|_)phone(?:\b|\W|_)/ then :tel
560
+ when /(?:\b|\W|_)url(?:\b|\W|_)/ then :url
561
561
  else
562
562
  file_method?(attribute_name) ? :file : (input_type || :string)
563
563
  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)
@@ -72,7 +72,10 @@ module SimpleForm
72
72
  @html_classes = SimpleForm.additional_classes_for(:input) { additional_classes }
73
73
 
74
74
  @input_html_classes = @html_classes.dup
75
- if SimpleForm.input_class && !input_html_classes.empty?
75
+
76
+ input_html_classes = self.input_html_classes
77
+
78
+ if SimpleForm.input_class && input_html_classes.any?
76
79
  input_html_classes << SimpleForm.input_class
77
80
  end
78
81
 
@@ -63,6 +63,7 @@ module SimpleForm
63
63
  return "" if !include_hidden? || !unchecked_value
64
64
  options = { value: unchecked_value, id: nil, disabled: input_html_options[:disabled] }
65
65
  options[:name] = input_html_options[:name] if input_html_options.key?(:name)
66
+ options[:form] = input_html_options[:form] if input_html_options.key?(:form)
66
67
 
67
68
  @builder.hidden_field(attribute_name, options)
68
69
  end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ module SimpleForm
3
+ module Inputs
4
+ class ColorInput < Base
5
+ def input(wrapper_options = nil)
6
+ input_html_options[:type] ||= "color" if html5?
7
+
8
+ merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
9
+
10
+ @builder.text_field(attribute_name, merged_input_options)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -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
@@ -18,7 +18,7 @@ module SimpleForm
18
18
  private
19
19
 
20
20
  def string?
21
- input_type == :string
21
+ input_type == :string || input_type == :citext
22
22
  end
23
23
  end
24
24
  end
@@ -10,6 +10,7 @@ module SimpleForm
10
10
  autoload :CollectionInput
11
11
  autoload :CollectionRadioButtonsInput
12
12
  autoload :CollectionSelectInput
13
+ autoload :ColorInput
13
14
  autoload :DateTimeInput
14
15
  autoload :FileInput
15
16
  autoload :GroupedCollectionSelectInput
@@ -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.0.0".freeze
3
+ VERSION = "5.0.0".freeze
4
4
  end
data/lib/simple_form.rb CHANGED
@@ -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
@@ -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
@@ -224,6 +224,12 @@ class ErrorTest < ActionView::TestCase
224
224
  assert_no_select 'span.error'
225
225
  end
226
226
 
227
+ test 'input with custom error works when form does not use a model' do
228
+ with_form_for :user, :active, error: "Super User Active! cannot be blank"
229
+
230
+ assert_select 'span.error'
231
+ end
232
+
227
233
  test 'input with custom error works when using full_error component' do
228
234
  swap_wrapper :default, custom_wrapper_with_full_error do
229
235
  error_text = "Super User Name! cannot be blank"