simple_form 5.0.0 → 5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +33 -8
- data/MIT-LICENSE +2 -1
- data/README.md +37 -40
- data/lib/generators/simple_form/templates/README +2 -3
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +1 -1
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +2 -2
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +1 -1
- data/lib/simple_form.rb +1 -1
- data/lib/simple_form/components/labels.rb +3 -5
- data/lib/simple_form/components/maxlength.rb +0 -4
- data/lib/simple_form/components/minlength.rb +0 -4
- data/lib/simple_form/form_builder.rb +5 -4
- data/lib/simple_form/inputs.rb +1 -0
- data/lib/simple_form/inputs/base.rb +0 -3
- data/lib/simple_form/inputs/collection_check_boxes_input.rb +1 -1
- data/lib/simple_form/inputs/collection_input.rb +3 -5
- data/lib/simple_form/inputs/rich_text_area_input.rb +12 -0
- data/lib/simple_form/version.rb +1 -1
- data/lib/simple_form/wrappers/root.rb +8 -3
- data/test/components/label_test.rb +0 -4
- data/test/form_builder/general_test.rb +6 -1
- data/test/form_builder/label_test.rb +1 -1
- data/test/form_builder/wrapper_test.rb +7 -0
- data/test/inputs/collection_check_boxes_input_test.rb +0 -4
- data/test/inputs/collection_radio_buttons_input_test.rb +0 -4
- data/test/inputs/collection_select_input_test.rb +6 -4
- data/test/inputs/rich_text_area_input_test.rb +15 -0
- data/test/support/misc_helpers.rb +2 -2
- data/test/support/models.rb +5 -1
- data/test/test_helper.rb +1 -1
- metadata +16 -15
- data/lib/simple_form/i18n_cache.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8260fa0dbaf1a82ae7b8a5c120c4f26ba4e2f0c03a9821241bf6d2d193962384
|
4
|
+
data.tar.gz: f1ef61699c7246302e31eb405c734816491b1698419bc810643b71c54d7ffb2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31be8f22b6fbe417be6051466e6370c8d54e4667df16c1506a84580df69376daae06af454bb46e21b8b86e61fed6efaf954f45c876005f2b33dde00ad3ca8374
|
7
|
+
data.tar.gz: 756ef0c153e13b61a6d6823f3ea9f615ee507e329effce3c31ca477b85de86c6b0aa7bb645802be3c405281b621777191b1c34efba2cdeceb9035c2dfbb9ce82
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,29 @@
|
|
1
|
-
##
|
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`.
|
2
27
|
|
3
28
|
## 5.0.0
|
4
29
|
|
@@ -107,7 +132,7 @@ See http://blog.plataformatec.com.br/2019/09/incorrect-access-control-in-simple-
|
|
107
132
|
|
108
133
|
### bug fix
|
109
134
|
* Fix `merge_wrapper_options` to correctly merge options with duplicated keys. [@herminiotorres](https://github.com/herminiotorres)
|
110
|
-
Closes [#1278](https://github.com/
|
135
|
+
Closes [#1278](https://github.com/heartcombo/simple_form/issues/1278).
|
111
136
|
|
112
137
|
## 3.2.1
|
113
138
|
|
@@ -169,11 +194,11 @@ See http://blog.plataformatec.com.br/2019/09/incorrect-access-control-in-simple-
|
|
169
194
|
* Add `boolean_label_class` config.
|
170
195
|
* Add `:html` option to include additional attributes on custom wrappers [@remofritzsche](https://github.com/remofritzsche) and [@ulissesalmeida](https://github.com/ulissesalmeida)
|
171
196
|
* Make possible to use the Wrappers API to define attributes for the components.
|
172
|
-
See https://github.com/
|
197
|
+
See https://github.com/heartcombo/simple_form/pull/997 for more information.
|
173
198
|
* Put a whitespace before the `inline_label` options of boolean input if it is present.
|
174
199
|
* Add support to configure the `label_text` proc at the wrapper level. [@NOX73](https://github.com/NOX73)
|
175
200
|
* `label_text` proc now receive three arguments (label, request, and if the label was explicit). [@timscott](https://github.com/timscott)
|
176
|
-
* Add I18n support to `:include_blank` and `:prompt` when `:translate` is used as value. [@haines](https://github.com/
|
201
|
+
* Add I18n support to `:include_blank` and `:prompt` when `:translate` is used as value. [@haines](https://github.com/heartcombo/simple_form/pull/616)
|
177
202
|
* Add support to define custom error messages for the attributes.
|
178
203
|
* Add support to change the I18n scope to be used in Simple Form. [@nielsbuus](https://github.com/nielsbuus)
|
179
204
|
* The default form class can now be overridden with `html: { :class }`. [@rmm5t](https://github.com/rmm5t)
|
@@ -182,16 +207,16 @@ See http://blog.plataformatec.com.br/2019/09/incorrect-access-control-in-simple-
|
|
182
207
|
* Fix `full_error` when the attribute is an association. [@mvdamme](https://github.com/jorge-d)
|
183
208
|
* Fix suppport to `:namespace` and `:index` options for nested check boxes and radio buttons when the attribute is an association.
|
184
209
|
* Collection input that uses automatic collection translation properly sets checked values.
|
185
|
-
Closes [#971](https://github.com/
|
210
|
+
Closes [#971](https://github.com/heartcombo/simple_form/issues/971) [@nashby](https://github.com/nashby)
|
186
211
|
* Collection input generates `required` attribute if it has `prompt` option. [@nashby](https://github.com/nashby)
|
187
212
|
* Grouped collection uses the first non-empty object to detect label and value methods.
|
188
213
|
|
189
214
|
## deprecation
|
190
215
|
* Methods on custom inputs now accept a required argument with the wrapper options.
|
191
|
-
See https://github.com/
|
216
|
+
See https://github.com/heartcombo/simple_form/pull/997 for more information.
|
192
217
|
* SimpleForm.form_class is deprecated in favor of SimpleForm.default_form_class.
|
193
218
|
Future versions of Simple Form will not generate `simple_form` class for the form
|
194
219
|
element.
|
195
|
-
See https://github.com/
|
220
|
+
See https://github.com/heartcombo/simple_form/pull/1109 for more information.
|
196
221
|
|
197
|
-
Please check [v3.0](https://github.com/
|
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)
|
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/
|
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
|
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
|
|
@@ -118,7 +115,7 @@ 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 %>
|
@@ -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/
|
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:
|
@@ -288,7 +285,7 @@ end
|
|
288
285
|
</form>
|
289
286
|
```
|
290
287
|
|
291
|
-
To view the actual RDocs for this, check them out here - http://rubydoc.info/github/
|
288
|
+
To view the actual RDocs for this, check them out here - http://rubydoc.info/github/heartcombo/simple_form/master/SimpleForm/FormBuilder:input_field
|
292
289
|
|
293
290
|
### Collections
|
294
291
|
|
@@ -318,7 +315,7 @@ Collection inputs accept two other options beside collections:
|
|
318
315
|
Those methods are useful to manipulate the given collection. Both of these options also accept
|
319
316
|
lambda/procs in case you want to calculate the value or label in a special way eg. custom
|
320
317
|
translation. You can also define a `to_label` method on your model as **Simple Form** will search for
|
321
|
-
and use `:to_label` as a `:label_method` first if it is found.
|
318
|
+
and use `:to_label` as a `:label_method` first if it is found.
|
322
319
|
|
323
320
|
By default, **Simple Form** will use the first item from an array as the label and the second one as the value.
|
324
321
|
If you want to change this behavior you must make it explicit, like this:
|
@@ -541,7 +538,7 @@ end
|
|
541
538
|
To add a CSS class to the label item, you can use the `item_label_class` option:
|
542
539
|
|
543
540
|
```ruby
|
544
|
-
f.collection_check_boxes :role_ids, Role.all, :id, :name, item_label_class: 'my-custom-class'
|
541
|
+
f.collection_check_boxes :role_ids, Role.all, :id, :name, item_label_class: 'my-custom-class'
|
545
542
|
```
|
546
543
|
|
547
544
|
## Available input types and defaults for each column type
|
@@ -561,6 +558,7 @@ Mapping | Generated HTML Element | Database Column Type
|
|
561
558
|
`password` | `input[type=password]` | `string` with `name =~ /password/`
|
562
559
|
`search` | `input[type=search]` | -
|
563
560
|
`uuid` | `input[type=text]` | `uuid`
|
561
|
+
`color` | `input[type=color]` | `string`
|
564
562
|
`text` | `textarea` | `text`
|
565
563
|
`hstore` | `textarea` | `hstore`
|
566
564
|
`json` | `textarea` | `json`
|
@@ -991,7 +989,7 @@ when the content is present.
|
|
991
989
|
|
992
990
|
## Custom Components
|
993
991
|
|
994
|
-
When you use custom wrappers, you might also be looking for a way to add custom components to your
|
992
|
+
When you use custom wrappers, you might also be looking for a way to add custom components to your
|
995
993
|
wrapper. The default components are:
|
996
994
|
|
997
995
|
```ruby
|
@@ -1142,7 +1140,7 @@ by passing the html5 option:
|
|
1142
1140
|
|
1143
1141
|
### Using non Active Record objects
|
1144
1142
|
|
1145
|
-
There are few ways to build forms with objects that don't inherit from Active Record, as
|
1143
|
+
There are few ways to build forms with objects that don't inherit from Active Record, as
|
1146
1144
|
follows:
|
1147
1145
|
|
1148
1146
|
You can include the module `ActiveModel::Model`.
|
@@ -1155,14 +1153,14 @@ class User
|
|
1155
1153
|
end
|
1156
1154
|
```
|
1157
1155
|
|
1158
|
-
If you are using Presenters or Decorators that inherit from `SimpleDelegator` you can delegate
|
1156
|
+
If you are using Presenters or Decorators that inherit from `SimpleDelegator` you can delegate
|
1159
1157
|
it to the model.
|
1160
1158
|
|
1161
1159
|
```ruby
|
1162
1160
|
class UserPresenter < SimpleDelegator
|
1163
1161
|
# Without that, Simple Form will consider the user model as the object.
|
1164
|
-
def to_model
|
1165
|
-
self
|
1162
|
+
def to_model
|
1163
|
+
self
|
1166
1164
|
end
|
1167
1165
|
end
|
1168
1166
|
```
|
@@ -1170,7 +1168,7 @@ end
|
|
1170
1168
|
You can define all methods required by the helpers.
|
1171
1169
|
|
1172
1170
|
```ruby
|
1173
|
-
class User
|
1171
|
+
class User
|
1174
1172
|
extend ActiveModel::Naming
|
1175
1173
|
|
1176
1174
|
attr_accessor :id, :name
|
@@ -1179,25 +1177,25 @@ class User
|
|
1179
1177
|
self
|
1180
1178
|
end
|
1181
1179
|
|
1182
|
-
def to_key
|
1183
|
-
id
|
1180
|
+
def to_key
|
1181
|
+
id
|
1184
1182
|
end
|
1185
1183
|
|
1186
|
-
def persisted?
|
1187
|
-
false
|
1184
|
+
def persisted?
|
1185
|
+
false
|
1188
1186
|
end
|
1189
1187
|
end
|
1190
1188
|
```
|
1191
1189
|
|
1192
|
-
If your object doesn't implement those methods, you must make explicit it when you are
|
1190
|
+
If your object doesn't implement those methods, you must make explicit it when you are
|
1193
1191
|
building the form
|
1194
1192
|
|
1195
1193
|
```ruby
|
1196
|
-
class User
|
1194
|
+
class User
|
1197
1195
|
attr_accessor :id, :name
|
1198
1196
|
|
1199
1197
|
# The only method required to use the f.submit helper.
|
1200
|
-
def persisted?
|
1198
|
+
def persisted?
|
1201
1199
|
false
|
1202
1200
|
end
|
1203
1201
|
end
|
@@ -1205,25 +1203,25 @@ end
|
|
1205
1203
|
|
1206
1204
|
```erb
|
1207
1205
|
<%= simple_form_for(@user, as: :user, method: :post, url: users_path) do |f| %>
|
1208
|
-
<%= f.input :name %>
|
1206
|
+
<%= f.input :name %>
|
1209
1207
|
<%= f.submit 'New user' %>
|
1210
1208
|
<% end %>
|
1211
1209
|
```
|
1212
1210
|
|
1213
1211
|
## Information
|
1214
1212
|
|
1215
|
-
###
|
1213
|
+
### RDocs
|
1216
1214
|
|
1217
|
-
|
1218
|
-
Issues tracker:
|
1215
|
+
You can view the **Simple Form** documentation in RDoc format here:
|
1219
1216
|
|
1220
|
-
http://
|
1217
|
+
http://rubydoc.info/github/heartcombo/simple_form/master/frames
|
1221
1218
|
|
1222
|
-
###
|
1219
|
+
### Supported Ruby / Rails versions
|
1223
1220
|
|
1224
|
-
|
1221
|
+
We intend to maintain support for all Ruby / Rails versions that haven't reached end-of-life.
|
1225
1222
|
|
1226
|
-
|
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.
|
1227
1225
|
|
1228
1226
|
### Bug reports
|
1229
1227
|
|
@@ -1231,23 +1229,22 @@ If you discover any bugs, feel free to create an issue on GitHub. Please add as
|
|
1231
1229
|
possible to help us in fixing the potential bug. We also encourage you to help even more by forking and
|
1232
1230
|
sending us a pull request.
|
1233
1231
|
|
1234
|
-
https://github.com/
|
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.
|
1235
1235
|
|
1236
1236
|
## Maintainers
|
1237
1237
|
|
1238
|
-
* José Valim (https://github.com/josevalim)
|
1239
1238
|
* Carlos Antonio da Silva (https://github.com/carlosantoniodasilva)
|
1240
1239
|
* Rafael Mendonça França (https://github.com/rafaelfranca)
|
1241
|
-
*
|
1240
|
+
* Felipe Renan (https://github.com/feliperenan)
|
1242
1241
|
|
1243
1242
|
[![Gem Version](https://fury-badge.herokuapp.com/rb/simple_form.png)](http://badge.fury.io/rb/simple_form)
|
1244
|
-
[![
|
1245
|
-
[![
|
1246
|
-
[![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)
|
1247
1245
|
|
1248
1246
|
## License
|
1249
1247
|
|
1250
|
-
MIT License. Copyright 2009-2019 Plataformatec.
|
1248
|
+
MIT License. Copyright 2020 Rafael França, Carlos Antônio da Silva. Copyright 2009-2019 Plataformatec.
|
1251
1249
|
|
1252
|
-
|
1253
|
-
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/).
|
@@ -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
|
-
|
7
|
-
class, '.form-inline', as the following:
|
6
|
+
For usage examples and documentation, see:
|
8
7
|
|
9
|
-
|
8
|
+
http://simple-form-bootstrap.plataformatec.com.br/
|
10
9
|
|
11
10
|
===============================================================================
|
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# Uncomment this and change the path if necessary to include your own
|
4
4
|
# components.
|
5
|
-
# See https://github.com/
|
5
|
+
# See https://github.com/heartcombo/simple_form#custom-components to know
|
6
6
|
# more about custom components.
|
7
7
|
# Dir[Rails.root.join('lib/components/**/*.rb')].each { |f| require f }
|
8
8
|
#
|
@@ -4,11 +4,11 @@
|
|
4
4
|
# This generator is maintained by the community around simple_form-bootstrap:
|
5
5
|
# https://github.com/rafaelfranca/simple_form-bootstrap
|
6
6
|
# All future development, tests, and organization should happen there.
|
7
|
-
# Background history: https://github.com/
|
7
|
+
# Background history: https://github.com/heartcombo/simple_form/issues/1561
|
8
8
|
|
9
9
|
# Uncomment this and change the path if necessary to include your own
|
10
10
|
# components.
|
11
|
-
# See https://github.com/
|
11
|
+
# See https://github.com/heartcombo/simple_form#custom-components
|
12
12
|
# to know more about custom components.
|
13
13
|
# Dir[Rails.root.join('lib/components/**/*.rb')].each { |f| require f }
|
14
14
|
|
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# Uncomment this and change the path if necessary to include your own
|
4
4
|
# components.
|
5
|
-
# See https://github.com/
|
5
|
+
# See https://github.com/heartcombo/simple_form#custom-components to know
|
6
6
|
# more about custom components.
|
7
7
|
# Dir[Rails.root.join('lib/components/**/*.rb')].each { |f| require f }
|
8
8
|
#
|
data/lib/simple_form.rb
CHANGED
@@ -6,11 +6,9 @@ module SimpleForm
|
|
6
6
|
|
7
7
|
module ClassMethods #:nodoc:
|
8
8
|
def translate_required_html
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
)
|
13
|
-
end
|
9
|
+
I18n.t(:"required.html", scope: i18n_scope, default:
|
10
|
+
%(<abbr title="#{translate_required_text}">#{translate_required_mark}</abbr>)
|
11
|
+
)
|
14
12
|
end
|
15
13
|
|
16
14
|
def translate_required_text
|
@@ -24,10 +24,6 @@ module SimpleForm
|
|
24
24
|
find_validator(:length)
|
25
25
|
end
|
26
26
|
|
27
|
-
def has_tokenizer?(length_validator)
|
28
|
-
length_validator.options[:tokenizer]
|
29
|
-
end
|
30
|
-
|
31
27
|
def maximum_length_value_from(length_validator)
|
32
28
|
if length_validator
|
33
29
|
length_validator.options[:is] || length_validator.options[:maximum]
|
@@ -24,10 +24,6 @@ module SimpleForm
|
|
24
24
|
find_validator(:length)
|
25
25
|
end
|
26
26
|
|
27
|
-
def has_tokenizer?(length_validator)
|
28
|
-
length_validator.options[:tokenizer]
|
29
|
-
end
|
30
|
-
|
31
27
|
def minimum_length_value_from(length_validator)
|
32
28
|
if length_validator
|
33
29
|
length_validator.options[:is] || length_validator.options[:minimum]
|
@@ -26,6 +26,7 @@ module SimpleForm
|
|
26
26
|
map_type :range, to: SimpleForm::Inputs::RangeInput
|
27
27
|
map_type :check_boxes, to: SimpleForm::Inputs::CollectionCheckBoxesInput
|
28
28
|
map_type :radio_buttons, to: SimpleForm::Inputs::CollectionRadioButtonsInput
|
29
|
+
map_type :rich_text_area, to: SimpleForm::Inputs::RichTextAreaInput
|
29
30
|
map_type :select, to: SimpleForm::Inputs::CollectionSelectInput
|
30
31
|
map_type :grouped_select, to: SimpleForm::Inputs::GroupedCollectionSelectInput
|
31
32
|
map_type :date, :time, :datetime, to: SimpleForm::Inputs::DateTimeInput
|
@@ -580,18 +581,18 @@ module SimpleForm
|
|
580
581
|
#
|
581
582
|
# Note: This does not support multiple file upload inputs, as this is very application-specific.
|
582
583
|
#
|
583
|
-
# The order here was
|
584
|
-
# with the suffix `_url` is present in three Gems, so it's checked with priority:
|
584
|
+
# The order here was chosen based on the popularity of Gems:
|
585
585
|
#
|
586
586
|
# - `#{attribute_name}_attachment` - ActiveStorage >= `5.2` and Refile >= `0.2.0` <= `0.4.0`
|
587
|
-
# -
|
587
|
+
# - `remote_#{attribute_name}_url` - Refile >= `0.3.0` and CarrierWave >= `0.2.2`
|
588
588
|
# - `#{attribute_name}_attacher` - Refile >= `0.4.0` and Shrine >= `0.9.0`
|
589
589
|
# - `#{attribute_name}_file_name` - Paperclip ~> `2.0` (added for backwards compatibility)
|
590
590
|
#
|
591
591
|
# Returns a Boolean.
|
592
592
|
def file_method?(attribute_name)
|
593
593
|
@object.respond_to?("#{attribute_name}_attachment") ||
|
594
|
-
@object.respond_to?("#{attribute_name}
|
594
|
+
@object.respond_to?("#{attribute_name}_attachments") ||
|
595
|
+
@object.respond_to?("remote_#{attribute_name}_url") ||
|
595
596
|
@object.respond_to?("#{attribute_name}_attacher") ||
|
596
597
|
@object.respond_to?("#{attribute_name}_file_name")
|
597
598
|
end
|
data/lib/simple_form/inputs.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require 'simple_form/i18n_cache'
|
3
2
|
require 'active_support/core_ext/string/output_safety'
|
4
3
|
require 'action_view/helpers'
|
5
4
|
|
@@ -9,8 +8,6 @@ module SimpleForm
|
|
9
8
|
include ERB::Util
|
10
9
|
include ActionView::Helpers::TranslationHelper
|
11
10
|
|
12
|
-
extend I18nCache
|
13
|
-
|
14
11
|
include SimpleForm::Helpers::Autofocus
|
15
12
|
include SimpleForm::Helpers::Disabled
|
16
13
|
include SimpleForm::Helpers::Readonly
|
@@ -5,7 +5,7 @@ module SimpleForm
|
|
5
5
|
protected
|
6
6
|
|
7
7
|
# Checkbox components do not use the required html tag.
|
8
|
-
# More info: https://github.com/
|
8
|
+
# More info: https://github.com/heartcombo/simple_form/issues/340#issuecomment-2871956
|
9
9
|
def has_required?
|
10
10
|
false
|
11
11
|
end
|
@@ -10,10 +10,8 @@ module SimpleForm
|
|
10
10
|
# Texts can be translated using i18n in "simple_form.yes" and
|
11
11
|
# "simple_form.no" keys. See the example locale file.
|
12
12
|
def self.boolean_collection
|
13
|
-
|
14
|
-
[
|
15
|
-
[I18n.t(:"simple_form.no", default: 'No'), false] ]
|
16
|
-
end
|
13
|
+
[ [I18n.t(:"simple_form.yes", default: 'Yes'), true],
|
14
|
+
[I18n.t(:"simple_form.no", default: 'No'), false] ]
|
17
15
|
end
|
18
16
|
|
19
17
|
def input(wrapper_options = nil)
|
@@ -41,7 +39,7 @@ module SimpleForm
|
|
41
39
|
end
|
42
40
|
|
43
41
|
def has_required?
|
44
|
-
super && (input_options[:include_blank] || input_options[:prompt] || multiple?)
|
42
|
+
super && (input_options[:include_blank] || input_options[:prompt].present? || multiple?)
|
45
43
|
end
|
46
44
|
|
47
45
|
# Check if :include_blank must be included by default.
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module SimpleForm
|
3
|
+
module Inputs
|
4
|
+
class RichTextAreaInput < Base
|
5
|
+
def input(wrapper_options = nil)
|
6
|
+
merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
|
7
|
+
|
8
|
+
@builder.rich_text_area(attribute_name, merged_input_options)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/simple_form/version.rb
CHANGED
@@ -28,11 +28,16 @@ module SimpleForm
|
|
28
28
|
css += SimpleForm.additional_classes_for(:wrapper) do
|
29
29
|
input.additional_classes + [input.input_class]
|
30
30
|
end
|
31
|
-
css << (
|
32
|
-
css << (
|
33
|
-
css << (
|
31
|
+
css << html_class(:error_class, options) { input.has_errors? }
|
32
|
+
css << html_class(:hint_class, options) { input.has_hint? }
|
33
|
+
css << html_class(:valid_class, options) { input.valid? }
|
34
34
|
css.compact
|
35
35
|
end
|
36
|
+
|
37
|
+
def html_class(key, options)
|
38
|
+
css = (options[:"wrapper_#{key}"] || @defaults[key])
|
39
|
+
css if css && yield
|
40
|
+
end
|
36
41
|
end
|
37
42
|
end
|
38
43
|
end
|
@@ -4,10 +4,6 @@ require 'test_helper'
|
|
4
4
|
|
5
5
|
# Isolated tests for label without triggering f.label.
|
6
6
|
class IsolatedLabelTest < ActionView::TestCase
|
7
|
-
setup do
|
8
|
-
SimpleForm::Inputs::Base.reset_i18n_cache :translate_required_html
|
9
|
-
end
|
10
|
-
|
11
7
|
def with_label_for(object, attribute_name, type, options = {})
|
12
8
|
with_concat_form_for(object) do |f|
|
13
9
|
options[:reflection] = Association.new(Company, :company, {}) if options.delete(:setup_association)
|
@@ -244,7 +244,12 @@ class FormBuilderTest < ActionView::TestCase
|
|
244
244
|
assert_select 'form input#user_with_attachment_avatar.file'
|
245
245
|
end
|
246
246
|
|
247
|
-
test 'builder generates file input for
|
247
|
+
test 'builder generates file input for ActiveStorage::Attached::Many' do
|
248
|
+
with_form_for UserWithAttachment.build, :avatars
|
249
|
+
assert_select 'form input#user_with_attachment_avatars.file'
|
250
|
+
end
|
251
|
+
|
252
|
+
test 'builder generates file input for Refile >= 0.3.0 and CarrierWave >= 0.2.2' do
|
248
253
|
with_form_for UserWithAttachment.build, :cover
|
249
254
|
assert_select 'form input#user_with_attachment_cover.file'
|
250
255
|
end
|
@@ -19,7 +19,7 @@ class LabelTest < ActionView::TestCase
|
|
19
19
|
assert_select 'label.string[for=user_name]', /Name/
|
20
20
|
end
|
21
21
|
|
22
|
-
test 'builder generates a label for the boolean
|
22
|
+
test 'builder generates a label for the boolean attribute' do
|
23
23
|
with_label_for @user, :name, as: :boolean
|
24
24
|
assert_select 'label.boolean[for=user_name]', /Name/
|
25
25
|
assert_no_select 'label[as=boolean]'
|
@@ -59,6 +59,13 @@ class WrapperTest < ActionView::TestCase
|
|
59
59
|
assert_no_select 'input.is-invalid'
|
60
60
|
end
|
61
61
|
|
62
|
+
test 'wrapper does not determine if valid class is needed when it is set to nil' do
|
63
|
+
@user.instance_eval { undef errors }
|
64
|
+
with_form_for @user, :name, wrapper: custom_wrapper_with_input_valid_class(valid_class: nil)
|
65
|
+
|
66
|
+
assert_no_select 'div.field_without_errors'
|
67
|
+
end
|
68
|
+
|
62
69
|
test 'wrapper adds hint class for attribute with a hint' do
|
63
70
|
with_form_for @user, :name, hint: 'hint'
|
64
71
|
assert_select 'div.field_with_hint'
|
@@ -3,10 +3,6 @@
|
|
3
3
|
require 'test_helper'
|
4
4
|
|
5
5
|
class CollectionCheckBoxesInputTest < ActionView::TestCase
|
6
|
-
setup do
|
7
|
-
SimpleForm::Inputs::CollectionCheckBoxesInput.reset_i18n_cache :boolean_collection
|
8
|
-
end
|
9
|
-
|
10
6
|
test 'input check boxes does not include for attribute by default' do
|
11
7
|
with_input_for @user, :gender, :check_boxes, collection: %i[male female]
|
12
8
|
assert_select 'label'
|
@@ -3,10 +3,6 @@
|
|
3
3
|
require 'test_helper'
|
4
4
|
|
5
5
|
class CollectionRadioButtonsInputTest < ActionView::TestCase
|
6
|
-
setup do
|
7
|
-
SimpleForm::Inputs::CollectionRadioButtonsInput.reset_i18n_cache :boolean_collection
|
8
|
-
end
|
9
|
-
|
10
6
|
test 'input generates boolean radio buttons by default for radio types' do
|
11
7
|
with_input_for @user, :active, :radio_buttons
|
12
8
|
assert_select 'input[type=radio][value=true].radio_buttons#user_active_true'
|
@@ -3,10 +3,6 @@
|
|
3
3
|
require 'test_helper'
|
4
4
|
|
5
5
|
class CollectionSelectInputTest < ActionView::TestCase
|
6
|
-
setup do
|
7
|
-
SimpleForm::Inputs::CollectionSelectInput.reset_i18n_cache :boolean_collection
|
8
|
-
end
|
9
|
-
|
10
6
|
test 'input generates a boolean select with options by default for select types' do
|
11
7
|
with_input_for @user, :active, :select
|
12
8
|
assert_select 'select.select#user_active'
|
@@ -284,6 +280,12 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
284
280
|
assert_select 'select[required]'
|
285
281
|
end
|
286
282
|
|
283
|
+
test "collection input generated aria-label should contain 'true'" do
|
284
|
+
with_input_for @user, :age, :select, collection: 18..30, prompt: "Please select foo"
|
285
|
+
assert_select 'select.required'
|
286
|
+
assert_select 'select[aria-required=true]'
|
287
|
+
end
|
288
|
+
|
287
289
|
test 'collection input with select type does not generate required html attribute without blank option' do
|
288
290
|
with_input_for @user, :name, :select, include_blank: false, collection: %w[Jose Carlos]
|
289
291
|
assert_select 'select.required'
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# encoding: UTF-8
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class RichTextAreaInputTest < ActionView::TestCase
|
6
|
+
test 'input generates a text area for text attributes' do
|
7
|
+
with_input_for @user, :description, :text
|
8
|
+
assert_select 'textarea.text#user_description'
|
9
|
+
end
|
10
|
+
|
11
|
+
test 'input generates a text area for text attributes that accept placeholder' do
|
12
|
+
with_input_for @user, :description, :text, placeholder: 'Put in some text'
|
13
|
+
assert_select 'textarea.text[placeholder="Put in some text"]'
|
14
|
+
end
|
15
|
+
end
|
@@ -213,8 +213,8 @@ module MiscHelpers
|
|
213
213
|
end
|
214
214
|
end
|
215
215
|
|
216
|
-
def custom_wrapper_with_input_valid_class
|
217
|
-
SimpleForm.build tag: :div, class: "custom_wrapper", valid_class:
|
216
|
+
def custom_wrapper_with_input_valid_class(valid_class: :field_without_errors)
|
217
|
+
SimpleForm.build tag: :div, class: "custom_wrapper", valid_class: valid_class do |b|
|
218
218
|
b.use :label
|
219
219
|
b.use :input, class: 'inline-class', valid_class: 'is-valid'
|
220
220
|
end
|
data/test/support/models.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -60,7 +60,7 @@ class ActionView::TestCase
|
|
60
60
|
|
61
61
|
@validating_user = ValidatingUser.build({
|
62
62
|
name: 'Tester McTesterson',
|
63
|
-
description: 'A test user of the most
|
63
|
+
description: 'A test user of the most distinguished caliber',
|
64
64
|
home_picture: 'Home picture',
|
65
65
|
age: 19,
|
66
66
|
amount: 15,
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- José Valim
|
8
8
|
- Carlos Antônio
|
9
9
|
- Rafael França
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2021-02-09 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activemodel
|
@@ -18,30 +18,30 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ">="
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '5.
|
21
|
+
version: '5.2'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
26
|
- - ">="
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version: '5.
|
28
|
+
version: '5.2'
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: actionpack
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
33
|
- - ">="
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version: '5.
|
35
|
+
version: '5.2'
|
36
36
|
type: :runtime
|
37
37
|
prerelease: false
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
40
|
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: '5.
|
42
|
+
version: '5.2'
|
43
43
|
description: Forms made easy!
|
44
|
-
email:
|
44
|
+
email: heartcombo@googlegroups.com
|
45
45
|
executables: []
|
46
46
|
extensions: []
|
47
47
|
extra_rdoc_files: []
|
@@ -82,7 +82,6 @@ files:
|
|
82
82
|
- lib/simple_form/helpers/readonly.rb
|
83
83
|
- lib/simple_form/helpers/required.rb
|
84
84
|
- lib/simple_form/helpers/validators.rb
|
85
|
-
- lib/simple_form/i18n_cache.rb
|
86
85
|
- lib/simple_form/inputs.rb
|
87
86
|
- lib/simple_form/inputs/base.rb
|
88
87
|
- lib/simple_form/inputs/block_input.rb
|
@@ -100,6 +99,7 @@ files:
|
|
100
99
|
- lib/simple_form/inputs/password_input.rb
|
101
100
|
- lib/simple_form/inputs/priority_input.rb
|
102
101
|
- lib/simple_form/inputs/range_input.rb
|
102
|
+
- lib/simple_form/inputs/rich_text_area_input.rb
|
103
103
|
- lib/simple_form/inputs/string_input.rb
|
104
104
|
- lib/simple_form/inputs/text_input.rb
|
105
105
|
- lib/simple_form/map_type.rb
|
@@ -142,6 +142,7 @@ files:
|
|
142
142
|
- test/inputs/priority_input_test.rb
|
143
143
|
- test/inputs/readonly_test.rb
|
144
144
|
- test/inputs/required_test.rb
|
145
|
+
- test/inputs/rich_text_area_input_test.rb
|
145
146
|
- test/inputs/string_input_test.rb
|
146
147
|
- test/inputs/text_input_test.rb
|
147
148
|
- test/simple_form_test.rb
|
@@ -150,11 +151,11 @@ files:
|
|
150
151
|
- test/support/mock_controller.rb
|
151
152
|
- test/support/models.rb
|
152
153
|
- test/test_helper.rb
|
153
|
-
homepage: https://github.com/
|
154
|
+
homepage: https://github.com/heartcombo/simple_form
|
154
155
|
licenses:
|
155
156
|
- MIT
|
156
157
|
metadata: {}
|
157
|
-
post_install_message:
|
158
|
+
post_install_message:
|
158
159
|
rdoc_options: []
|
159
160
|
require_paths:
|
160
161
|
- lib
|
@@ -162,16 +163,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
162
163
|
requirements:
|
163
164
|
- - ">="
|
164
165
|
- !ruby/object:Gem::Version
|
165
|
-
version:
|
166
|
+
version: 2.5.0
|
166
167
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
168
|
requirements:
|
168
169
|
- - ">="
|
169
170
|
- !ruby/object:Gem::Version
|
170
171
|
version: '0'
|
171
172
|
requirements: []
|
172
|
-
|
173
|
-
|
174
|
-
signing_key:
|
173
|
+
rubygems_version: 3.2.6
|
174
|
+
signing_key:
|
175
175
|
specification_version: 4
|
176
176
|
summary: Forms made easy!
|
177
177
|
test_files:
|
@@ -197,6 +197,7 @@ test_files:
|
|
197
197
|
- test/simple_form_test.rb
|
198
198
|
- test/inputs/string_input_test.rb
|
199
199
|
- test/inputs/numeric_input_test.rb
|
200
|
+
- test/inputs/rich_text_area_input_test.rb
|
200
201
|
- test/inputs/readonly_test.rb
|
201
202
|
- test/inputs/grouped_collection_select_input_test.rb
|
202
203
|
- test/inputs/text_input_test.rb
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module SimpleForm
|
3
|
-
# A lot of configuration values are retrived from I18n,
|
4
|
-
# like boolean collection, required string. This module provides
|
5
|
-
# caching facility to speed up form construction.
|
6
|
-
module I18nCache
|
7
|
-
def i18n_cache(key)
|
8
|
-
get_i18n_cache(key)[I18n.locale] ||= yield.freeze
|
9
|
-
end
|
10
|
-
|
11
|
-
def get_i18n_cache(key)
|
12
|
-
if class_variable_defined?(:"@@#{key}")
|
13
|
-
class_variable_get(:"@@#{key}")
|
14
|
-
else
|
15
|
-
reset_i18n_cache(key)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def reset_i18n_cache(key)
|
20
|
-
class_variable_set(:"@@#{key}", {})
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|