simple_form 3.4.0 → 5.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +118 -8
  3. data/MIT-LICENSE +2 -1
  4. data/README.md +235 -67
  5. data/lib/generators/simple_form/install_generator.rb +1 -0
  6. data/lib/generators/simple_form/templates/README +2 -3
  7. data/lib/generators/simple_form/templates/_form.html.erb +2 -0
  8. data/lib/generators/simple_form/templates/_form.html.haml +2 -0
  9. data/lib/generators/simple_form/templates/_form.html.slim +1 -0
  10. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +14 -7
  11. data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +360 -74
  12. data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +20 -8
  13. data/lib/simple_form/action_view_extensions/builder.rb +1 -0
  14. data/lib/simple_form/action_view_extensions/form_helper.rb +1 -0
  15. data/lib/simple_form/components/errors.rb +15 -2
  16. data/lib/simple_form/components/hints.rb +1 -0
  17. data/lib/simple_form/components/html5.rb +1 -0
  18. data/lib/simple_form/components/label_input.rb +2 -1
  19. data/lib/simple_form/components/labels.rb +12 -7
  20. data/lib/simple_form/components/maxlength.rb +4 -17
  21. data/lib/simple_form/components/min_max.rb +1 -0
  22. data/lib/simple_form/components/minlength.rb +5 -18
  23. data/lib/simple_form/components/pattern.rb +1 -0
  24. data/lib/simple_form/components/placeholders.rb +2 -1
  25. data/lib/simple_form/components/readonly.rb +1 -0
  26. data/lib/simple_form/components.rb +1 -0
  27. data/lib/simple_form/error_notification.rb +1 -0
  28. data/lib/simple_form/form_builder.rb +104 -29
  29. data/lib/simple_form/helpers/autofocus.rb +1 -0
  30. data/lib/simple_form/helpers/disabled.rb +1 -0
  31. data/lib/simple_form/helpers/readonly.rb +1 -0
  32. data/lib/simple_form/helpers/required.rb +1 -0
  33. data/lib/simple_form/helpers/validators.rb +2 -1
  34. data/lib/simple_form/helpers.rb +1 -0
  35. data/lib/simple_form/inputs/base.rb +24 -5
  36. data/lib/simple_form/inputs/block_input.rb +1 -0
  37. data/lib/simple_form/inputs/boolean_input.rb +4 -2
  38. data/lib/simple_form/inputs/collection_check_boxes_input.rb +3 -2
  39. data/lib/simple_form/inputs/collection_input.rb +6 -7
  40. data/lib/simple_form/inputs/collection_radio_buttons_input.rb +2 -1
  41. data/lib/simple_form/inputs/collection_select_input.rb +1 -0
  42. data/lib/simple_form/inputs/color_input.rb +14 -0
  43. data/lib/simple_form/inputs/date_time_input.rb +1 -0
  44. data/lib/simple_form/inputs/file_input.rb +1 -0
  45. data/lib/simple_form/inputs/grouped_collection_select_input.rb +1 -0
  46. data/lib/simple_form/inputs/hidden_input.rb +1 -0
  47. data/lib/simple_form/inputs/numeric_input.rb +1 -0
  48. data/lib/simple_form/inputs/password_input.rb +1 -0
  49. data/lib/simple_form/inputs/priority_input.rb +1 -4
  50. data/lib/simple_form/inputs/range_input.rb +1 -0
  51. data/lib/simple_form/inputs/rich_text_area_input.rb +12 -0
  52. data/lib/simple_form/inputs/string_input.rb +2 -1
  53. data/lib/simple_form/inputs/text_input.rb +1 -0
  54. data/lib/simple_form/inputs.rb +3 -0
  55. data/lib/simple_form/map_type.rb +1 -0
  56. data/lib/simple_form/railtie.rb +1 -0
  57. data/lib/simple_form/tags.rb +7 -2
  58. data/lib/simple_form/version.rb +2 -1
  59. data/lib/simple_form/wrappers/builder.rb +1 -0
  60. data/lib/simple_form/wrappers/leaf.rb +2 -1
  61. data/lib/simple_form/wrappers/many.rb +1 -0
  62. data/lib/simple_form/wrappers/root.rb +9 -2
  63. data/lib/simple_form/wrappers/single.rb +2 -1
  64. data/lib/simple_form/wrappers.rb +1 -0
  65. data/lib/simple_form.rb +79 -11
  66. data/test/action_view_extensions/builder_test.rb +28 -9
  67. data/test/action_view_extensions/form_helper_test.rb +3 -2
  68. data/test/components/custom_components_test.rb +62 -0
  69. data/test/components/label_test.rb +33 -8
  70. data/test/form_builder/association_test.rb +33 -2
  71. data/test/form_builder/button_test.rb +1 -0
  72. data/test/form_builder/error_notification_test.rb +1 -0
  73. data/test/form_builder/error_test.rb +12 -0
  74. data/test/form_builder/general_test.rb +75 -13
  75. data/test/form_builder/hint_test.rb +6 -0
  76. data/test/form_builder/input_field_test.rb +30 -10
  77. data/test/form_builder/label_test.rb +10 -4
  78. data/test/form_builder/wrapper_test.rb +32 -5
  79. data/test/generators/simple_form_generator_test.rb +4 -3
  80. data/test/inputs/boolean_input_test.rb +17 -0
  81. data/test/inputs/collection_check_boxes_input_test.rb +38 -18
  82. data/test/inputs/collection_radio_buttons_input_test.rb +48 -28
  83. data/test/inputs/collection_select_input_test.rb +46 -43
  84. data/test/inputs/color_input_test.rb +10 -0
  85. data/test/inputs/datetime_input_test.rb +7 -16
  86. data/test/inputs/disabled_test.rb +14 -0
  87. data/test/inputs/discovery_test.rb +22 -0
  88. data/test/inputs/file_input_test.rb +1 -0
  89. data/test/inputs/general_test.rb +3 -2
  90. data/test/inputs/grouped_collection_select_input_test.rb +11 -10
  91. data/test/inputs/hidden_input_test.rb +1 -0
  92. data/test/inputs/numeric_input_test.rb +2 -1
  93. data/test/inputs/priority_input_test.rb +7 -14
  94. data/test/inputs/readonly_test.rb +1 -0
  95. data/test/inputs/required_test.rb +1 -0
  96. data/test/inputs/rich_text_area_input_test.rb +15 -0
  97. data/test/inputs/string_input_test.rb +10 -16
  98. data/test/inputs/text_input_test.rb +1 -0
  99. data/test/simple_form_test.rb +1 -0
  100. data/test/support/discovery_inputs.rb +8 -0
  101. data/test/support/misc_helpers.rb +22 -1
  102. data/test/support/mock_controller.rb +7 -1
  103. data/test/support/models.rb +80 -18
  104. data/test/test_helper.rb +9 -4
  105. metadata +49 -55
  106. data/lib/simple_form/i18n_cache.rb +0 -22
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 534c9396c2be271ccbb32518e9e5026b5ff523e1
4
- data.tar.gz: bb8085d4a664110a941f6cd7e732db16f9eef1ec
2
+ SHA256:
3
+ metadata.gz: 8260fa0dbaf1a82ae7b8a5c120c4f26ba4e2f0c03a9821241bf6d2d193962384
4
+ data.tar.gz: f1ef61699c7246302e31eb405c734816491b1698419bc810643b71c54d7ffb2d
5
5
  SHA512:
6
- metadata.gz: d8e81c8af57b65150d3b9a53433c9d9adb3c5d64fa00ae70b1263a33ce05173d2dc65775ab66e91507d1db452e0f59cb254c0b5eb1ca905ec4b95bbc4eb98282
7
- data.tar.gz: 249e0e56f352267ab529db921125ac214d6baeb17153278cba26c61951ce31867cf9d94b4188dab9e50457d2e23d6aebabacf29e475b31c8f7c85c382ab318f2
6
+ metadata.gz: 31be8f22b6fbe417be6051466e6370c8d54e4667df16c1506a84580df69376daae06af454bb46e21b8b86e61fed6efaf954f45c876005f2b33dde00ad3ca8374
7
+ data.tar.gz: 756ef0c153e13b61a6d6823f3ea9f615ee507e329effce3c31ca477b85de86c6b0aa7bb645802be3c405281b621777191b1c34efba2cdeceb9035c2dfbb9ce82
data/CHANGELOG.md CHANGED
@@ -1,4 +1,114 @@
1
- ## Unreleased
1
+ ## 5.1.0
2
+
3
+ * Remove `I18nCache` module entirely. It was added complexity for very little gain in some translations, and caused extra trouble upgrading to Ruby 3. If you need that level of caching consider looking into I18n caching as a whole.
4
+ * Add support for Ruby 3.0, drop support for Ruby < 2.5.
5
+ * Add support for Rails 6.1, drop support for Rails < 5.2.
6
+ * Move CI to GitHub Actions.
7
+
8
+ ## 5.0.3
9
+
10
+ ### Bug fix
11
+ * Fix for ActiveStorage::Attached::Many. [@enriquez](https://github.com/enriquez)
12
+
13
+ ## 5.0.2
14
+
15
+ ### Enhancements
16
+ * Remove instruction to use form-inline class. [@goalaleo](https://github.com/goalaleo)
17
+ * Added RichTextAreaInput for ActionText. [itsterry](https://github.com/itsterry)
18
+ * Skip valid_class check if no class defined. [TALlama](https://github.com/TALlama)
19
+
20
+ ### Bug fix
21
+ * Fix 'aria-required' field generated by prompt. [@CarlosAlbertoSantos](https://github.com/CarlosAlbertoSantos)
22
+
23
+ ## 5.0.1
24
+
25
+ ### Bug fix
26
+ * Replace `_url` with `remote_url` when trying to guess file inputs [@tegon](https://github.com/tegon). This has the side-effect of changing carrierwave's support from `0.2.1` to `0.2.2`.
27
+
28
+ ## 5.0.0
29
+
30
+ ### Enhancements
31
+ * Set multiple attribute for grouped selects also. [@ollym](https://github.com/ollym)
32
+ * Removes or renames label classes. [Abduvakilov](https://github.com/Abduvakilov)
33
+ * Support to label custom classes for inline collections. [@feliperenan](https://github.com/feliperenan)
34
+ * Update bootstrap generator template to match v4.3.x. [@m5o](https://github.com/m5o)
35
+ * Allow "required" attribute in generated select elements of PriorityInput. [@mcountis](https://github.com/mcountis)
36
+
37
+ ### Bug fix
38
+ * Do not call `#send` in form object to check whether the attribute is a file input. [@tegon](https://github.com/tegon)
39
+
40
+ ## Deprecations
41
+ * 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:
42
+
43
+ ```erb
44
+ <%= form.input :avatar, as: :file %>
45
+ ```
46
+
47
+ See http://blog.plataformatec.com.br/2019/09/incorrect-access-control-in-simple-form-cve-2019-16676 for more information.
48
+
49
+ ## 4.1.0
50
+
51
+ ### Enhancements
52
+ * Guess input type more carefully. [@sringling](https://github.com/sringling)
53
+ * Allow custom error on forms without model. [@victorperez](https://github.com/victorperez)
54
+ * Do not support Ruby < 2.3 anymore. [@gssbzn](https://github.com/gssbzn)
55
+ * Add color input type. [@gssbzn](https://github.com/gssbzn)
56
+
57
+ ### Bug fix
58
+ * Improve disabled option to input_field. [@betelgeuse](https://github.com/betelgeuse)
59
+ * Memoize `input_html_classes` in `SimpleForm::Inputs::Base`. [@RigoTheDev](https://github.com/RigoTheDev)
60
+ * Fix column type citext HTML5 input type bug. [@brucew](https://github.com/brucew)
61
+ * Use form attribute in the nested boolean hidden field when it is given. [@feliperenan](https://github.com/feliperenan)
62
+
63
+ ## 4.0.1
64
+
65
+ ### Bug fix
66
+ * Do not support Rails 4 anymore. [@rafaelfranca](https://github.com/rafaelfranca)
67
+ * Add missing comma. [@vill](https://github.com/vill)
68
+
69
+ ## 4.0.0
70
+
71
+ ### Enhancements
72
+ * Add bootstrap v4.1 generator template. [@m5o](https://github.com/m5o)
73
+ * Add Rails 5.2 support. [@gobijan](https://github.com/gobijan)
74
+ * Add API to register custom components.[@feliperenan](https://github.com/feliperenan)
75
+ * Allow custom errors classes to inputs.[@feliperenan](https://github.com/feliperenan)
76
+ * Remove support from Rails 4.0, 4.1 and 4.2. [@feliperenan](https://github.com/feliperenan)
77
+ * Add support for citext, hstore, json & jsonb column types. [@swrobel](https://github.com/swrobel)
78
+ * Add :valid_class on input wrapper when value is present and valid [@aeberlin](https://github.com/aeberlin), [@m5o](https://github.com/m5o)
79
+ * Allow :valid_class to inputs when value is present and valid. [@m5o](https://github.com/m5o)
80
+ * Allow validation classes on input_field. [@feliperenan](https://github.com/feliperenan)
81
+ * Add basic ActiveStorage support. [@murb](https://github.com/murb)
82
+
83
+ ### Bug fix
84
+ * Fix horizontal form label position, from right to text-right. [@cavpollo](https://github.com/cavpollo)
85
+ * Add base error display alongside existing errors. [@bluefalcon26](https://github.com/bluefalcon26)
86
+ * Silent deprication warning for placeholder_text. [@moofkit](https://github.com/moofkit)
87
+ * Use custom i18n scope for label required html. [@tvdeyen](https://github.com/tvdeyen)
88
+
89
+ ## 3.5.1
90
+
91
+ ### Enhancements
92
+ * Exclude hidden field when unchecked_value: false. [@fschwahn](https://github.com/fschwahn)
93
+ * Add frozen_string_literal magic comment to several files. [@oniofchaos](https://github.com/oniofchaos)
94
+ * Try convert @object to model in case we got decorated object [@timurvafin](https://github.com/timurvafin)
95
+ - From now, if you are using some object that inherits from `SimpleDelegator`, you must implement
96
+ `def to_model; self; end`. Otherwise, *Simple Form* will convert the decorated object to the model
97
+ since `SimpleDelegator` will delegate it to the model.
98
+ * Code cleanup [@Fornacula](https://github.com/Fornacula)
99
+
100
+ ### Bug fix
101
+ * Fix error when the scope from association has parameter. [@feliperenan](https://github.com/feliperenan)
102
+ * Only call `where` on associations when they respond to it. [@anicholson](https://github.com/anicholson)
103
+ * require 'action_pack' before using it. [@etagwerker](https://github.com/etagwerker)
104
+ * Check if Rails.env is defined. [@etagwerker](https://github.com/etagwerker)
105
+ * Fix minlength. [@mameier](https://github.com/mameier)
106
+ * Make errors_on_attribute return [] when not present. [@redrick](https://github.com/redrick)
107
+ * Fix boolean inputs in nested style for label non-string. [@feliperenan](https://github.com/feliperenan)
108
+
109
+ ## 3.5.0
110
+
111
+ * Updated gem dependency to support Rails 5.1.x.
2
112
 
3
113
  ## 3.4.0
4
114
 
@@ -22,7 +132,7 @@
22
132
 
23
133
  ### bug fix
24
134
  * Fix `merge_wrapper_options` to correctly merge options with duplicated keys. [@herminiotorres](https://github.com/herminiotorres)
25
- Closes [#1278](https://github.com/plataformatec/simple_form/issues/1278).
135
+ Closes [#1278](https://github.com/heartcombo/simple_form/issues/1278).
26
136
 
27
137
  ## 3.2.1
28
138
 
@@ -84,11 +194,11 @@
84
194
  * Add `boolean_label_class` config.
85
195
  * Add `:html` option to include additional attributes on custom wrappers [@remofritzsche](https://github.com/remofritzsche) and [@ulissesalmeida](https://github.com/ulissesalmeida)
86
196
  * Make possible to use the Wrappers API to define attributes for the components.
87
- See https://github.com/plataformatec/simple_form/pull/997 for more information.
197
+ See https://github.com/heartcombo/simple_form/pull/997 for more information.
88
198
  * Put a whitespace before the `inline_label` options of boolean input if it is present.
89
199
  * Add support to configure the `label_text` proc at the wrapper level. [@NOX73](https://github.com/NOX73)
90
200
  * `label_text` proc now receive three arguments (label, request, and if the label was explicit). [@timscott](https://github.com/timscott)
91
- * Add I18n support to `:include_blank` and `:prompt` when `:translate` is used as value. [@haines](https://github.com/plataformatec/simple_form/pull/616)
201
+ * Add I18n support to `:include_blank` and `:prompt` when `:translate` is used as value. [@haines](https://github.com/heartcombo/simple_form/pull/616)
92
202
  * Add support to define custom error messages for the attributes.
93
203
  * Add support to change the I18n scope to be used in Simple Form. [@nielsbuus](https://github.com/nielsbuus)
94
204
  * The default form class can now be overridden with `html: { :class }`. [@rmm5t](https://github.com/rmm5t)
@@ -97,16 +207,16 @@
97
207
  * Fix `full_error` when the attribute is an association. [@mvdamme](https://github.com/jorge-d)
98
208
  * Fix suppport to `:namespace` and `:index` options for nested check boxes and radio buttons when the attribute is an association.
99
209
  * Collection input that uses automatic collection translation properly sets checked values.
100
- Closes [#971](https://github.com/plataformatec/simple_form/issues/971) [@nashby](https://github.com/nashby)
210
+ Closes [#971](https://github.com/heartcombo/simple_form/issues/971) [@nashby](https://github.com/nashby)
101
211
  * Collection input generates `required` attribute if it has `prompt` option. [@nashby](https://github.com/nashby)
102
212
  * Grouped collection uses the first non-empty object to detect label and value methods.
103
213
 
104
214
  ## deprecation
105
215
  * Methods on custom inputs now accept a required argument with the wrapper options.
106
- See https://github.com/plataformatec/simple_form/pull/997 for more information.
216
+ See https://github.com/heartcombo/simple_form/pull/997 for more information.
107
217
  * SimpleForm.form_class is deprecated in favor of SimpleForm.default_form_class.
108
218
  Future versions of Simple Form will not generate `simple_form` class for the form
109
219
  element.
110
- See https://github.com/plataformatec/simple_form/pull/1109 for more information.
220
+ See https://github.com/heartcombo/simple_form/pull/1109 for more information.
111
221
 
112
- Please check [v3.0](https://github.com/plataformatec/simple_form/blob/v3.0/CHANGELOG.md) for previous changes.
222
+ Please check [v3.0](https://github.com/heartcombo/simple_form/blob/v3.0/CHANGELOG.md) for previous changes.
data/MIT-LICENSE CHANGED
@@ -1,4 +1,5 @@
1
- Copyright (c) 2009-2016 Plataformatec http://plataformatec.com.br/
1
+ Copyright (c) 2020 Rafael França, Carlos Antônio da Silva
2
+ Copyright (c) 2009-2019 Plataformatec
2
3
 
3
4
  Permission is hereby granted, free of charge, to any person obtaining
4
5
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,6 +1,4 @@
1
- ![Simple Form Logo](https://raw.github.com/plataformatec/simple_form/master/simple_form.png)
2
-
3
- By [Plataformatec](http://plataformatec.com.br/).
1
+ ![Simple Form Logo](https://raw.github.com/heartcombo/simple_form/master/simple_form.png)
4
2
 
5
3
  Rails forms made easy.
6
4
 
@@ -9,8 +7,7 @@ your forms. The basic goal of **Simple Form** is to not touch your way of defini
9
7
  you find the better design for your eyes. Most of the DSL was inherited from Formtastic,
10
8
  which we are thankful for and should make you feel right at home.
11
9
 
12
- INFO: This README is [also available in a friendly navigable format](http://simple-form.plataformatec.com.br/)
13
- and refers to **Simple Form** 3.1. For older releases, check the related branch for your version.
10
+ INFO: This README refers to **Simple Form** 5.0. For older releases, check the related branch for your version.
14
11
 
15
12
  ## Installation
16
13
 
@@ -113,12 +110,12 @@ an error, or even a placeholder. For boolean inputs, you can add an inline label
113
110
  <% end %>
114
111
  ```
115
112
 
116
- In some cases you may want to disable labels, hints or error. Or you may want to configure the html
113
+ In some cases you may want to disable labels, hints or errors. Or you may want to configure the html
117
114
  of any of them:
118
115
 
119
116
  ```erb
120
117
  <%= simple_form_for @user do |f| %>
121
- <%= f.input :username, label_html: { class: 'my_class' } %>
118
+ <%= f.input :username, label_html: { class: 'my_class' }, hint_html: { class: 'hint_class' } %>
122
119
  <%= f.input :password, hint: false, error_html: { id: 'password_error'} %>
123
120
  <%= f.input :password_confirmation, label: false %>
124
121
  <%= f.button :submit %>
@@ -164,7 +161,7 @@ any html attribute to that wrapper as well using the `:wrapper_html` option, lik
164
161
 
165
162
  Required fields are marked with an * prepended to their labels.
166
163
 
167
- By default all inputs are required. When the form object includes `ActiveModel::Validations`
164
+ By default all inputs are required. When the form object includes `ActiveModel::Validations`
168
165
  (which, for example, happens with Active Record models), fields are required only when there is `presence` validation.
169
166
  Otherwise, **Simple Form** will mark fields as optional. For performance reasons, this
170
167
  detection is skipped on validations that make use of conditional options, such as `:if` and `:unless`.
@@ -184,7 +181,7 @@ By default, **Simple Form** will look at the column type in the database and use
184
181
  appropriate input for the column. For example, a column created with type
185
182
  `:text` in the database will use a `textarea` input by default. See the section
186
183
  [Available input types and defaults for each column
187
- type](https://github.com/plataformatec/simple_form#available-input-types-and-defaults-for-each-column-type)
184
+ type](https://github.com/heartcombo/simple_form#available-input-types-and-defaults-for-each-column-type)
188
185
  for a complete list of defaults.
189
186
 
190
187
  **Simple Form** also lets you overwrite the default input type it creates:
@@ -214,7 +211,7 @@ the wrapper as well:
214
211
  <% end %>
215
212
  ```
216
213
 
217
- **Simple Form** accepts same options as their corresponding input type helper in Rails:
214
+ **Simple Form** inputs accept the same options as their corresponding input type helper in Rails:
218
215
 
219
216
  ```erb
220
217
  <%= simple_form_for @user do |f| %>
@@ -288,14 +285,7 @@ end
288
285
  </form>
289
286
  ```
290
287
 
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
- To view the actual RDocs for this, check them out here - http://rubydoc.info/github/plataformatec/simple_form/master/SimpleForm/FormBuilder:input_field
288
+ To view the actual RDocs for this, check them out here - http://rubydoc.info/github/heartcombo/simple_form/master/SimpleForm/FormBuilder:input_field
299
289
 
300
290
  ### Collections
301
291
 
@@ -325,8 +315,18 @@ Collection inputs accept two other options beside collections:
325
315
  Those methods are useful to manipulate the given collection. Both of these options also accept
326
316
  lambda/procs in case you want to calculate the value or label in a special way eg. custom
327
317
  translation. You can also define a `to_label` method on your model as **Simple Form** will search for
328
- and use `:to_label` as a `:label_method` first if it is found. All other options given are sent
329
- straight to the underlying helper. For example, you can give prompt as:
318
+ and use `:to_label` as a `:label_method` first if it is found.
319
+
320
+ By default, **Simple Form** will use the first item from an array as the label and the second one as the value.
321
+ If you want to change this behavior you must make it explicit, like this:
322
+
323
+ ```erb
324
+ <%= simple_form_for @user do |f| %>
325
+ <%= f.input :gender, as: :radio_buttons, collection: [['0', 'female'], ['1', 'male']], label_method: :second, value_method: :first %>
326
+ <% end %>
327
+ ```
328
+
329
+ All other options given are sent straight to the underlying helper. For example, you can give prompt as:
330
330
 
331
331
  ```ruby
332
332
  f.input :age, collection: 18..60, prompt: "Select your age", selected: 21
@@ -497,7 +497,7 @@ Creates a collection of radio inputs with labels associated (same API as `collec
497
497
 
498
498
  ```ruby
499
499
  form_for @user do |f|
500
- f.collection_radio_buttons :options, [[true, 'Yes'] ,[false, 'No']], :first, :last
500
+ f.collection_radio_buttons :options, [[true, 'Yes'], [false, 'No']], :first, :last
501
501
  end
502
502
  ```
503
503
 
@@ -514,7 +514,7 @@ Creates a collection of checkboxes with labels associated (same API as `collecti
514
514
 
515
515
  ```ruby
516
516
  form_for @user do |f|
517
- f.collection_check_boxes :options, [[true, 'Yes'] ,[false, 'No']], :first, :last
517
+ f.collection_check_boxes :options, [[true, 'Yes'], [false, 'No']], :first, :last
518
518
  end
519
519
  ```
520
520
 
@@ -535,37 +535,48 @@ form_for @user do |f|
535
535
  end
536
536
  ```
537
537
 
538
+ To add a CSS class to the label item, you can use the `item_label_class` option:
539
+
540
+ ```ruby
541
+ f.collection_check_boxes :role_ids, Role.all, :id, :name, item_label_class: 'my-custom-class'
542
+ ```
543
+
538
544
  ## Available input types and defaults for each column type
539
545
 
540
546
  The following table shows the html element you will get for each attribute
541
547
  according to its database definition. These defaults can be changed by
542
548
  specifying the helper method in the column `Mapping` as the `as:` option.
543
549
 
544
- Mapping | Generated HTML Element | Database Column Type
545
- --------------- |:-------------------------------------|:--------------------
546
- `boolean` | `input[type=checkbox]` | `boolean`
547
- `string` | `input[type=text]` | `string`
548
- `email` | `input[type=email]` | `string` with `name =~ /email/`
549
- `url` | `input[type=url]` | `string` with `name =~ /url/`
550
- `tel` | `input[type=tel]` | `string` with `name =~ /phone/`
551
- `password` | `input[type=password]` | `string` with `name =~ /password/`
552
- `search` | `input[type=search]` | -
553
- `uuid` | `input[type=text]` | `uuid`
554
- `text` | `textarea` | `text`
555
- `file` | `input[type=file]` | `string` responding to file methods
556
- `hidden` | `input[type=hidden]` | -
557
- `integer` | `input[type=number]` | `integer`
558
- `float` | `input[type=number]` | `float`
559
- `decimal` | `input[type=number]` | `decimal`
560
- `range` | `input[type=range]` | -
561
- `datetime` | `datetime select` | `datetime/timestamp`
562
- `date` | `date select` | `date`
563
- `time` | `time select` | `time`
564
- `select` | `select` | `belongs_to`/`has_many`/`has_and_belongs_to_many` associations
565
- `radio_buttons` | collection of `input[type=radio]` | `belongs_to` associations
566
- `check_boxes` | collection of `input[type=checkbox]` | `has_many`/`has_and_belongs_to_many` associations
567
- `country` | `select` (countries as options) | `string` with `name =~ /country/`
568
- `time_zone` | `select` (timezones as options) | `string` with `name =~ /time_zone/`
550
+ Mapping | Generated HTML Element | Database Column Type
551
+ --------------- |--------------------------------------|---------------------
552
+ `boolean` | `input[type=checkbox]` | `boolean`
553
+ `string` | `input[type=text]` | `string`
554
+ `citext` | `input[type=text]` | `citext`
555
+ `email` | `input[type=email]` | `string` with `name =~ /email/`
556
+ `url` | `input[type=url]` | `string` with `name =~ /url/`
557
+ `tel` | `input[type=tel]` | `string` with `name =~ /phone/`
558
+ `password` | `input[type=password]` | `string` with `name =~ /password/`
559
+ `search` | `input[type=search]` | -
560
+ `uuid` | `input[type=text]` | `uuid`
561
+ `color` | `input[type=color]` | `string`
562
+ `text` | `textarea` | `text`
563
+ `hstore` | `textarea` | `hstore`
564
+ `json` | `textarea` | `json`
565
+ `jsonb` | `textarea` | `jsonb`
566
+ `file` | `input[type=file]` | `string` responding to file methods
567
+ `hidden` | `input[type=hidden]` | -
568
+ `integer` | `input[type=number]` | `integer`
569
+ `float` | `input[type=number]` | `float`
570
+ `decimal` | `input[type=number]` | `decimal`
571
+ `range` | `input[type=range]` | -
572
+ `datetime` | `datetime select` | `datetime/timestamp`
573
+ `date` | `date select` | `date`
574
+ `time` | `time select` | `time`
575
+ `select` | `select` | `belongs_to`/`has_many`/`has_and_belongs_to_many` associations
576
+ `radio_buttons` | collection of `input[type=radio]` | `belongs_to` associations
577
+ `check_boxes` | collection of `input[type=checkbox]` | `has_many`/`has_and_belongs_to_many` associations
578
+ `country` | `select` (countries as options) | `string` with `name =~ /country/`
579
+ `time_zone` | `select` (timezones as options) | `string` with `name =~ /time_zone/`
569
580
 
570
581
  ## Custom inputs
571
582
 
@@ -812,7 +823,7 @@ object itself. Thus, similarly, if a form for an `Admin::User` object is defined
812
823
  `simple_form_for @admin_user, as: :some_user`, **Simple Form** will look for translations
813
824
  under `some_user` instead of `admin_user`.
814
825
 
815
- When translate `simple_fields_for` attributes be sure to use the same name you pass to it, e.g. `simple_fields_for :posts` should be placed under `posts` not `post`:
826
+ When translating `simple_fields_for` attributes be sure to use the same name you pass to it, e.g. `simple_fields_for :posts` should be placed under `posts` not `post`:
816
827
 
817
828
  ```yaml
818
829
  en:
@@ -842,7 +853,8 @@ The syntax looks like this:
842
853
 
843
854
  ```ruby
844
855
  config.wrappers tag: :div, class: :input,
845
- error_class: :field_with_errors do |b|
856
+ error_class: :field_with_errors,
857
+ valid_class: :field_without_errors do |b|
846
858
 
847
859
  # Form extensions
848
860
  b.use :html5
@@ -891,11 +903,12 @@ You can customize _Form components_ passing options to them:
891
903
 
892
904
  ```ruby
893
905
  config.wrappers do |b|
894
- b.use :label_input, class: 'label-input-class'
906
+ b.use :label_input, class: 'label-input-class', error_class: 'is-invalid', valid_class: 'is-valid'
895
907
  end
896
908
  ```
897
909
 
898
- This you set the input and label class to `'label-input-class'`.
910
+ This sets the input and label classes to `'label-input-class'` and will set the class `'is-invalid'`
911
+ if the input has errors and `'is-valid'` if the input is valid.
899
912
 
900
913
  If you want to customize the custom _Form components_ on demand you can give it a name like this:
901
914
 
@@ -974,6 +987,92 @@ when the content is present.
974
987
  end
975
988
  ```
976
989
 
990
+ ## Custom Components
991
+
992
+ When you use custom wrappers, you might also be looking for a way to add custom components to your
993
+ wrapper. The default components are:
994
+
995
+ ```ruby
996
+ :label # The <label> tag alone
997
+ :input # The <input> tag alone
998
+ :label_input # The <label> and the <input> tags
999
+ :hint # The hint for the input
1000
+ :error # The error for the input
1001
+ ```
1002
+
1003
+ A custom component might be interesting for you if your views look something like this:
1004
+
1005
+ ```erb
1006
+ <%= simple_form_for @blog do |f| %>
1007
+ <div class="row">
1008
+ <div class="span1 number">
1009
+ 1
1010
+ </div>
1011
+ <div class="span8">
1012
+ <%= f.input :title %>
1013
+ </div>
1014
+ </div>
1015
+ <div class="row">
1016
+ <div class="span1 number">
1017
+ 2
1018
+ </div>
1019
+ <div class="span8">
1020
+ <%= f.input :body, as: :text %>
1021
+ </div>
1022
+ </div>
1023
+ <% end %>
1024
+ ```
1025
+
1026
+ A cleaner method to create your views would be:
1027
+
1028
+ ```erb
1029
+ <%= simple_form_for @blog, wrapper: :with_numbers do |f| %>
1030
+ <%= f.input :title, number: 1 %>
1031
+ <%= f.input :body, as: :text, number: 2 %>
1032
+ <% end %>
1033
+ ```
1034
+
1035
+ To use the number option on the input, first, tells to Simple Form the place where the components
1036
+ will be:
1037
+
1038
+ ``` ruby
1039
+ # config/initializers/simple_form.rb
1040
+ Dir[Rails.root.join('lib/components/**/*.rb')].each { |f| require f }
1041
+ ```
1042
+
1043
+ Create a new component within the path specified above:
1044
+
1045
+ ```ruby
1046
+ # lib/components/numbers_component.rb
1047
+ module NumbersComponent
1048
+ # To avoid deprecation warning, you need to make the wrapper_options explicit
1049
+ # even when they won't be used.
1050
+ def number(wrapper_options = nil)
1051
+ @number ||= begin
1052
+ options[:number].to_s.html_safe if options[:number].present?
1053
+ end
1054
+ end
1055
+ end
1056
+
1057
+ SimpleForm.include_component(NumbersComponent)
1058
+ ```
1059
+
1060
+ Finally, add a new wrapper to the config/initializers/simple_form.rb file:
1061
+
1062
+ ```ruby
1063
+ config.wrappers :with_numbers, tag: 'div', class: 'row', error_class: 'error' do |b|
1064
+ b.use :html5
1065
+ b.use :number, wrap_with: { tag: 'div', class: 'span1 number'}
1066
+ b.wrapper tag: 'div', class: 'span8' do |ba|
1067
+ ba.use :placeholder
1068
+ ba.use :label
1069
+ ba.use :input
1070
+ ba.use :error, wrap_with: { tag: 'span', class: 'help-inline' }
1071
+ ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
1072
+ end
1073
+ end
1074
+ ```
1075
+
977
1076
  ## HTML 5 Notice
978
1077
 
979
1078
  By default, **Simple Form** will generate input field types and attributes that are supported in HTML5,
@@ -1039,44 +1138,113 @@ by passing the html5 option:
1039
1138
  <%= f.input :expires_at, as: :date, html5: true %>
1040
1139
  ```
1041
1140
 
1042
- ## Information
1141
+ ### Using non Active Record objects
1142
+
1143
+ There are few ways to build forms with objects that don't inherit from Active Record, as
1144
+ follows:
1145
+
1146
+ You can include the module `ActiveModel::Model`.
1147
+
1148
+ ```ruby
1149
+ class User
1150
+ include ActiveModel::Model
1151
+
1152
+ attr_accessor :id, :name
1153
+ end
1154
+ ```
1155
+
1156
+ If you are using Presenters or Decorators that inherit from `SimpleDelegator` you can delegate
1157
+ it to the model.
1158
+
1159
+ ```ruby
1160
+ class UserPresenter < SimpleDelegator
1161
+ # Without that, Simple Form will consider the user model as the object.
1162
+ def to_model
1163
+ self
1164
+ end
1165
+ end
1166
+ ```
1167
+
1168
+ You can define all methods required by the helpers.
1043
1169
 
1044
- ### Google Group
1170
+ ```ruby
1171
+ class User
1172
+ extend ActiveModel::Naming
1045
1173
 
1046
- If you have any questions, comments, or concerns please use the Google Group instead of the GitHub
1047
- Issues tracker:
1174
+ attr_accessor :id, :name
1048
1175
 
1049
- http://groups.google.com/group/plataformatec-simpleform
1176
+ def to_model
1177
+ self
1178
+ end
1179
+
1180
+ def to_key
1181
+ id
1182
+ end
1183
+
1184
+ def persisted?
1185
+ false
1186
+ end
1187
+ end
1188
+ ```
1189
+
1190
+ If your object doesn't implement those methods, you must make explicit it when you are
1191
+ building the form
1192
+
1193
+ ```ruby
1194
+ class User
1195
+ attr_accessor :id, :name
1196
+
1197
+ # The only method required to use the f.submit helper.
1198
+ def persisted?
1199
+ false
1200
+ end
1201
+ end
1202
+ ```
1203
+
1204
+ ```erb
1205
+ <%= simple_form_for(@user, as: :user, method: :post, url: users_path) do |f| %>
1206
+ <%= f.input :name %>
1207
+ <%= f.submit 'New user' %>
1208
+ <% end %>
1209
+ ```
1210
+
1211
+ ## Information
1050
1212
 
1051
1213
  ### RDocs
1052
1214
 
1053
1215
  You can view the **Simple Form** documentation in RDoc format here:
1054
1216
 
1055
- http://rubydoc.info/github/plataformatec/simple_form/master/frames
1217
+ http://rubydoc.info/github/heartcombo/simple_form/master/frames
1218
+
1219
+ ### Supported Ruby / Rails versions
1220
+
1221
+ We intend to maintain support for all Ruby / Rails versions that haven't reached end-of-life.
1222
+
1223
+ For more information about specific versions please check [Ruby](https://www.ruby-lang.org/en/downloads/branches/)
1224
+ and [Rails](https://guides.rubyonrails.org/maintenance_policy.html) maintenance policies, and our test matrix.
1056
1225
 
1057
1226
  ### Bug reports
1058
1227
 
1059
1228
  If you discover any bugs, feel free to create an issue on GitHub. Please add as much information as
1060
- possible to help us fixing the possible bug. We also encourage you to help even more by forking and
1229
+ possible to help us in fixing the potential bug. We also encourage you to help even more by forking and
1061
1230
  sending us a pull request.
1062
1231
 
1063
- https://github.com/plataformatec/simple_form/issues
1232
+ https://github.com/heartcombo/simple_form/issues
1233
+
1234
+ If you have discovered a security related bug, please do NOT use the GitHub issue tracker. Send an e-mail to heartcombo@googlegroups.com.
1064
1235
 
1065
1236
  ## Maintainers
1066
1237
 
1067
- * José Valim (https://github.com/josevalim)
1068
1238
  * Carlos Antonio da Silva (https://github.com/carlosantoniodasilva)
1069
1239
  * Rafael Mendonça França (https://github.com/rafaelfranca)
1070
- * Vasiliy Ermolovich (https://github.com/nashby)
1240
+ * Felipe Renan (https://github.com/feliperenan)
1071
1241
 
1072
1242
  [![Gem Version](https://fury-badge.herokuapp.com/rb/simple_form.png)](http://badge.fury.io/rb/simple_form)
1073
- [![Build Status](https://api.travis-ci.org/plataformatec/simple_form.svg?branch=master)](http://travis-ci.org/plataformatec/simple_form)
1074
- [![Code Climate](https://codeclimate.com/github/plataformatec/simple_form.png)](https://codeclimate.com/github/plataformatec/simple_form)
1075
- [![Inline docs](http://inch-ci.org/github/plataformatec/simple_form.png)](http://inch-ci.org/github/plataformatec/simple_form)
1243
+ [![Code Climate](https://codeclimate.com/github/heartcombo/simple_form.png)](https://codeclimate.com/github/heartcombo/simple_form)
1244
+ [![Inline docs](http://inch-ci.org/github/heartcombo/simple_form.png)](http://inch-ci.org/github/heartcombo/simple_form)
1076
1245
 
1077
1246
  ## License
1078
1247
 
1079
- MIT License. Copyright 2009-2016 Plataformatec. http://plataformatec.com.br
1248
+ MIT License. Copyright 2020 Rafael França, Carlos Antônio da Silva. Copyright 2009-2019 Plataformatec.
1080
1249
 
1081
- You are not granted rights or licenses to the trademarks of the Plataformatec, including without
1082
- limitation the Simple Form name or logo.
1250
+ The Simple Form logo is licensed under [Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License](https://creativecommons.org/licenses/by-nc-nd/4.0/).
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module SimpleForm
2
3
  module Generators
3
4
  class InstallGenerator < Rails::Generators::Base
@@ -3,9 +3,8 @@
3
3
  Be sure to have a copy of the Bootstrap stylesheet available on your
4
4
  application, you can get it on http://getbootstrap.com/.
5
5
 
6
- Inside your views, use the 'simple_form_for' with one of the Bootstrap form
7
- classes, '.form-horizontal' or '.form-inline', as the following:
6
+ For usage examples and documentation, see:
8
7
 
9
- = simple_form_for(@user, html: { class: 'form-horizontal' }) do |form|
8
+ http://simple-form-bootstrap.plataformatec.com.br/
10
9
 
11
10
  ===============================================================================
@@ -1,5 +1,7 @@
1
+ <%# frozen_string_literal: true %>
1
2
  <%%= simple_form_for(@<%= singular_table_name %>) do |f| %>
2
3
  <%%= f.error_notification %>
4
+ <%%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %>
3
5
 
4
6
  <div class="form-inputs">
5
7
  <%- attributes.each do |attribute| -%>