simple_form 3.3.1 → 3.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of simple_form might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +28 -0
- data/README.md +43 -33
- data/lib/generators/simple_form/install_generator.rb +1 -0
- data/lib/generators/simple_form/templates/_form.html.erb +1 -0
- data/lib/generators/simple_form/templates/_form.html.haml +1 -0
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +5 -0
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +6 -0
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +7 -3
- data/lib/simple_form/action_view_extensions/builder.rb +1 -0
- data/lib/simple_form/action_view_extensions/form_helper.rb +1 -0
- data/lib/simple_form/components/errors.rb +2 -1
- data/lib/simple_form/components/hints.rb +1 -0
- data/lib/simple_form/components/html5.rb +1 -0
- data/lib/simple_form/components/label_input.rb +2 -1
- data/lib/simple_form/components/labels.rb +2 -1
- data/lib/simple_form/components/maxlength.rb +1 -0
- data/lib/simple_form/components/min_max.rb +1 -0
- data/lib/simple_form/components/minlength.rb +48 -0
- data/lib/simple_form/components/pattern.rb +1 -0
- data/lib/simple_form/components/placeholders.rb +1 -0
- data/lib/simple_form/components/readonly.rb +1 -0
- data/lib/simple_form/components.rb +2 -0
- data/lib/simple_form/error_notification.rb +1 -0
- data/lib/simple_form/form_builder.rb +9 -3
- data/lib/simple_form/helpers/autofocus.rb +1 -0
- data/lib/simple_form/helpers/disabled.rb +1 -0
- data/lib/simple_form/helpers/readonly.rb +1 -0
- data/lib/simple_form/helpers/required.rb +1 -0
- data/lib/simple_form/helpers/validators.rb +2 -1
- data/lib/simple_form/helpers.rb +1 -0
- data/lib/simple_form/i18n_cache.rb +1 -0
- data/lib/simple_form/inputs/base.rb +4 -2
- data/lib/simple_form/inputs/block_input.rb +1 -0
- data/lib/simple_form/inputs/boolean_input.rb +9 -4
- data/lib/simple_form/inputs/collection_check_boxes_input.rb +2 -1
- data/lib/simple_form/inputs/collection_input.rb +7 -5
- data/lib/simple_form/inputs/collection_radio_buttons_input.rb +2 -1
- data/lib/simple_form/inputs/collection_select_input.rb +1 -0
- data/lib/simple_form/inputs/date_time_input.rb +1 -0
- data/lib/simple_form/inputs/file_input.rb +1 -0
- data/lib/simple_form/inputs/grouped_collection_select_input.rb +1 -0
- data/lib/simple_form/inputs/hidden_input.rb +1 -0
- data/lib/simple_form/inputs/numeric_input.rb +1 -0
- data/lib/simple_form/inputs/password_input.rb +2 -1
- data/lib/simple_form/inputs/priority_input.rb +1 -0
- data/lib/simple_form/inputs/range_input.rb +1 -0
- data/lib/simple_form/inputs/string_input.rb +2 -1
- data/lib/simple_form/inputs/text_input.rb +2 -1
- data/lib/simple_form/inputs.rb +1 -0
- data/lib/simple_form/map_type.rb +1 -0
- data/lib/simple_form/railtie.rb +1 -0
- data/lib/simple_form/tags.rb +1 -0
- data/lib/simple_form/version.rb +2 -1
- data/lib/simple_form/wrappers/builder.rb +1 -0
- data/lib/simple_form/wrappers/leaf.rb +2 -1
- data/lib/simple_form/wrappers/many.rb +1 -0
- data/lib/simple_form/wrappers/root.rb +1 -0
- data/lib/simple_form/wrappers/single.rb +2 -1
- data/lib/simple_form/wrappers.rb +1 -0
- data/lib/simple_form.rb +9 -6
- data/test/action_view_extensions/builder_test.rb +6 -5
- data/test/action_view_extensions/form_helper_test.rb +3 -2
- data/test/components/label_test.rb +5 -4
- data/test/form_builder/association_test.rb +27 -2
- data/test/form_builder/button_test.rb +1 -0
- data/test/form_builder/error_notification_test.rb +1 -0
- data/test/form_builder/error_test.rb +6 -0
- data/test/form_builder/general_test.rb +27 -3
- data/test/form_builder/hint_test.rb +6 -0
- data/test/form_builder/input_field_test.rb +17 -2
- data/test/form_builder/label_test.rb +9 -3
- data/test/form_builder/wrapper_test.rb +3 -2
- data/test/generators/simple_form_generator_test.rb +4 -3
- data/test/inputs/boolean_input_test.rb +19 -0
- data/test/inputs/collection_check_boxes_input_test.rb +30 -14
- data/test/inputs/collection_radio_buttons_input_test.rb +40 -24
- data/test/inputs/collection_select_input_test.rb +40 -39
- data/test/inputs/datetime_input_test.rb +5 -4
- data/test/inputs/disabled_test.rb +1 -0
- data/test/inputs/discovery_test.rb +1 -0
- data/test/inputs/file_input_test.rb +1 -0
- data/test/inputs/general_test.rb +3 -2
- data/test/inputs/grouped_collection_select_input_test.rb +11 -10
- data/test/inputs/hidden_input_test.rb +1 -0
- data/test/inputs/numeric_input_test.rb +2 -1
- data/test/inputs/priority_input_test.rb +1 -0
- data/test/inputs/readonly_test.rb +1 -0
- data/test/inputs/required_test.rb +1 -0
- data/test/inputs/string_input_test.rb +17 -1
- data/test/inputs/text_input_test.rb +6 -0
- data/test/simple_form_test.rb +1 -0
- data/test/support/discovery_inputs.rb +1 -0
- data/test/support/misc_helpers.rb +2 -1
- data/test/support/mock_controller.rb +7 -1
- data/test/support/models.rb +47 -14
- data/test/test_helper.rb +4 -0
- metadata +8 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 26d8e98f7207ee39c87221a646468a32291c982b
|
|
4
|
+
data.tar.gz: c3706e88eef3b4804381d8dbafd343819dbea517
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ee943633a1817a276e27b2aa55a9767169bf75791e17d0fe236f10c057f9442187ca0f6914da62e070a5418ec06c9d31dd61c2f662ee4c99fe52cec02ec1edd0
|
|
7
|
+
data.tar.gz: f5019c5c6b057a008d5c1403d030798f3bdf2393b42410afa1cdc3e8feecd4c79e4a721a3a1fd976f147460ca497a199f9092834d4d26fb32d76c1cadbab2454
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
## Unreleased
|
|
2
2
|
|
|
3
|
+
## 3.5.1
|
|
4
|
+
|
|
5
|
+
### Enhancements
|
|
6
|
+
* Exclude hidden field when unchecked_value: false. [@fschwahn](https://github.com/fschwahn)
|
|
7
|
+
* Add frozen_string_literal magic comment to several files. [@oniofchaos](https://github.com/oniofchaos)
|
|
8
|
+
* Try convert @object to model in case we got decorated object [@timurvafin](https://github.com/timurvafin)
|
|
9
|
+
* Code cleanup [@Fornacula](https://github.com/Fornacula)
|
|
10
|
+
|
|
11
|
+
### Bug fix
|
|
12
|
+
* Fix error when the scope from association has parameter. [@feliperenan](https://github.com/feliperenan)
|
|
13
|
+
* Only call `where` on associations when they respond to it. [@anicholson](https://github.com/anicholson)
|
|
14
|
+
* require 'action_pack' before using it. [@etagwerker](https://github.com/etagwerker)
|
|
15
|
+
* Check if Rails.env is defined. [@etagwerker](https://github.com/etagwerker)
|
|
16
|
+
* Fix minlength. [@mameier](https://github.com/mameier)
|
|
17
|
+
* Make errors_on_attribute return [] when not present. [@redrick](https://github.com/redrick)
|
|
18
|
+
* Fix boolean inputs in nested style for label non-string. [@feliperenan](https://github.com/feliperenan)
|
|
19
|
+
|
|
20
|
+
## 3.5.0
|
|
21
|
+
|
|
22
|
+
* Updated gem dependency to support Rails 5.1.x.
|
|
23
|
+
|
|
24
|
+
## 3.4.0
|
|
25
|
+
|
|
26
|
+
* Removed Ruby 2.4.0 `Integer` unification deprecation warning.
|
|
27
|
+
* Removed EOL Ruby 1.9.3 from the build matrix.
|
|
28
|
+
* Added `minlength` component.
|
|
29
|
+
* `boolean_label_class` can be set on a per-input basis.
|
|
30
|
+
|
|
3
31
|
## 3.3.1
|
|
4
32
|
|
|
5
33
|
### Bug fix
|
data/README.md
CHANGED
|
@@ -113,7 +113,7 @@ an error, or even a placeholder. For boolean inputs, you can add an inline label
|
|
|
113
113
|
<% end %>
|
|
114
114
|
```
|
|
115
115
|
|
|
116
|
-
In some cases you may want to disable labels, hints or
|
|
116
|
+
In some cases you may want to disable labels, hints or errors. Or you may want to configure the html
|
|
117
117
|
of any of them:
|
|
118
118
|
|
|
119
119
|
```erb
|
|
@@ -164,7 +164,7 @@ any html attribute to that wrapper as well using the `:wrapper_html` option, lik
|
|
|
164
164
|
|
|
165
165
|
Required fields are marked with an * prepended to their labels.
|
|
166
166
|
|
|
167
|
-
By default all inputs are required. When the form object includes `ActiveModel::Validations`
|
|
167
|
+
By default all inputs are required. When the form object includes `ActiveModel::Validations`
|
|
168
168
|
(which, for example, happens with Active Record models), fields are required only when there is `presence` validation.
|
|
169
169
|
Otherwise, **Simple Form** will mark fields as optional. For performance reasons, this
|
|
170
170
|
detection is skipped on validations that make use of conditional options, such as `:if` and `:unless`.
|
|
@@ -214,7 +214,7 @@ the wrapper as well:
|
|
|
214
214
|
<% end %>
|
|
215
215
|
```
|
|
216
216
|
|
|
217
|
-
**Simple Form**
|
|
217
|
+
**Simple Form** inputs accept the same options as their corresponding input type helper in Rails:
|
|
218
218
|
|
|
219
219
|
```erb
|
|
220
220
|
<%= simple_form_for @user do |f| %>
|
|
@@ -325,8 +325,18 @@ Collection inputs accept two other options beside collections:
|
|
|
325
325
|
Those methods are useful to manipulate the given collection. Both of these options also accept
|
|
326
326
|
lambda/procs in case you want to calculate the value or label in a special way eg. custom
|
|
327
327
|
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.
|
|
329
|
-
|
|
328
|
+
and use `:to_label` as a `:label_method` first if it is found.
|
|
329
|
+
|
|
330
|
+
By default, **Simple Form** will use the first item from an array as the label and the second one as the value.
|
|
331
|
+
If you want to change this behavior you must make it explicit, like this:
|
|
332
|
+
|
|
333
|
+
```erb
|
|
334
|
+
<%= simple_form_for @user do |f| %>
|
|
335
|
+
<%= f.input :gender, as: :radio_buttons, collection: [['0', 'female'], ['1', 'male']], label_method: :second, value_method: :first %>
|
|
336
|
+
<% end %>
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
All other options given are sent straight to the underlying helper. For example, you can give prompt as:
|
|
330
340
|
|
|
331
341
|
```ruby
|
|
332
342
|
f.input :age, collection: 18..60, prompt: "Select your age", selected: 21
|
|
@@ -541,31 +551,31 @@ The following table shows the html element you will get for each attribute
|
|
|
541
551
|
according to its database definition. These defaults can be changed by
|
|
542
552
|
specifying the helper method in the column `Mapping` as the `as:` option.
|
|
543
553
|
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
554
|
+
Mapping | Generated HTML Element | Database Column Type
|
|
555
|
+
--------------- |--------------------------------------|---------------------
|
|
556
|
+
`boolean` | `input[type=checkbox]` | `boolean`
|
|
557
|
+
`string` | `input[type=text]` | `string`
|
|
558
|
+
`email` | `input[type=email]` | `string` with `name =~ /email/`
|
|
559
|
+
`url` | `input[type=url]` | `string` with `name =~ /url/`
|
|
560
|
+
`tel` | `input[type=tel]` | `string` with `name =~ /phone/`
|
|
561
|
+
`password` | `input[type=password]` | `string` with `name =~ /password/`
|
|
562
|
+
`search` | `input[type=search]` | -
|
|
563
|
+
`uuid` | `input[type=text]` | `uuid`
|
|
564
|
+
`text` | `textarea` | `text`
|
|
565
|
+
`file` | `input[type=file]` | `string` responding to file methods
|
|
566
|
+
`hidden` | `input[type=hidden]` | -
|
|
567
|
+
`integer` | `input[type=number]` | `integer`
|
|
568
|
+
`float` | `input[type=number]` | `float`
|
|
569
|
+
`decimal` | `input[type=number]` | `decimal`
|
|
570
|
+
`range` | `input[type=range]` | -
|
|
571
|
+
`datetime` | `datetime select` | `datetime/timestamp`
|
|
572
|
+
`date` | `date select` | `date`
|
|
573
|
+
`time` | `time select` | `time`
|
|
574
|
+
`select` | `select` | `belongs_to`/`has_many`/`has_and_belongs_to_many` associations
|
|
575
|
+
`radio_buttons` | collection of `input[type=radio]` | `belongs_to` associations
|
|
576
|
+
`check_boxes` | collection of `input[type=checkbox]` | `has_many`/`has_and_belongs_to_many` associations
|
|
577
|
+
`country` | `select` (countries as options) | `string` with `name =~ /country/`
|
|
578
|
+
`time_zone` | `select` (timezones as options) | `string` with `name =~ /time_zone/`
|
|
569
579
|
|
|
570
580
|
## Custom inputs
|
|
571
581
|
|
|
@@ -812,7 +822,7 @@ object itself. Thus, similarly, if a form for an `Admin::User` object is defined
|
|
|
812
822
|
`simple_form_for @admin_user, as: :some_user`, **Simple Form** will look for translations
|
|
813
823
|
under `some_user` instead of `admin_user`.
|
|
814
824
|
|
|
815
|
-
When
|
|
825
|
+
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
826
|
|
|
817
827
|
```yaml
|
|
818
828
|
en:
|
|
@@ -1057,7 +1067,7 @@ http://rubydoc.info/github/plataformatec/simple_form/master/frames
|
|
|
1057
1067
|
### Bug reports
|
|
1058
1068
|
|
|
1059
1069
|
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
|
|
1070
|
+
possible to help us in fixing the potential bug. We also encourage you to help even more by forking and
|
|
1061
1071
|
sending us a pull request.
|
|
1062
1072
|
|
|
1063
1073
|
https://github.com/plataformatec/simple_form/issues
|
|
@@ -1076,7 +1086,7 @@ https://github.com/plataformatec/simple_form/issues
|
|
|
1076
1086
|
|
|
1077
1087
|
## License
|
|
1078
1088
|
|
|
1079
|
-
MIT License. Copyright 2009-
|
|
1089
|
+
MIT License. Copyright 2009-2018 Plataformatec. http://plataformatec.com.br
|
|
1080
1090
|
|
|
1081
1091
|
You are not granted rights or licenses to the trademarks of the Plataformatec, including without
|
|
1082
1092
|
limitation the Simple Form name or logo.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
# Use this setup block to configure all options available in SimpleForm.
|
|
2
3
|
SimpleForm.setup do |config|
|
|
3
4
|
# Wrappers are used by the form builder to generate a
|
|
@@ -28,8 +29,12 @@ SimpleForm.setup do |config|
|
|
|
28
29
|
# extensions by default, you can change `b.optional` to `b.use`.
|
|
29
30
|
|
|
30
31
|
# Calculates maxlength from length validations for string inputs
|
|
32
|
+
# and/or database column lengths
|
|
31
33
|
b.optional :maxlength
|
|
32
34
|
|
|
35
|
+
# Calculate minlength from length validations for string inputs
|
|
36
|
+
b.optional :minlength
|
|
37
|
+
|
|
33
38
|
# Calculates pattern from format validations for string inputs
|
|
34
39
|
b.optional :pattern
|
|
35
40
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
# Use this setup block to configure all options available in SimpleForm.
|
|
2
3
|
SimpleForm.setup do |config|
|
|
3
4
|
config.error_notification_class = 'alert alert-danger'
|
|
@@ -8,6 +9,7 @@ SimpleForm.setup do |config|
|
|
|
8
9
|
b.use :html5
|
|
9
10
|
b.use :placeholder
|
|
10
11
|
b.optional :maxlength
|
|
12
|
+
b.optional :minlength
|
|
11
13
|
b.optional :pattern
|
|
12
14
|
b.optional :min_max
|
|
13
15
|
b.optional :readonly
|
|
@@ -22,6 +24,7 @@ SimpleForm.setup do |config|
|
|
|
22
24
|
b.use :html5
|
|
23
25
|
b.use :placeholder
|
|
24
26
|
b.optional :maxlength
|
|
27
|
+
b.optional :minlength
|
|
25
28
|
b.optional :readonly
|
|
26
29
|
b.use :label, class: 'control-label'
|
|
27
30
|
|
|
@@ -55,6 +58,7 @@ SimpleForm.setup do |config|
|
|
|
55
58
|
b.use :html5
|
|
56
59
|
b.use :placeholder
|
|
57
60
|
b.optional :maxlength
|
|
61
|
+
b.optional :minlength
|
|
58
62
|
b.optional :pattern
|
|
59
63
|
b.optional :min_max
|
|
60
64
|
b.optional :readonly
|
|
@@ -71,6 +75,7 @@ SimpleForm.setup do |config|
|
|
|
71
75
|
b.use :html5
|
|
72
76
|
b.use :placeholder
|
|
73
77
|
b.optional :maxlength
|
|
78
|
+
b.optional :minlength
|
|
74
79
|
b.optional :readonly
|
|
75
80
|
b.use :label, class: 'col-sm-3 control-label'
|
|
76
81
|
|
|
@@ -112,6 +117,7 @@ SimpleForm.setup do |config|
|
|
|
112
117
|
b.use :html5
|
|
113
118
|
b.use :placeholder
|
|
114
119
|
b.optional :maxlength
|
|
120
|
+
b.optional :minlength
|
|
115
121
|
b.optional :pattern
|
|
116
122
|
b.optional :min_max
|
|
117
123
|
b.optional :readonly
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
# Use this setup block to configure all options available in SimpleForm.
|
|
2
3
|
SimpleForm.setup do |config|
|
|
3
4
|
# Don't forget to edit this file to adapt it to your needs (specially
|
|
4
5
|
# all the grid-related classes)
|
|
5
6
|
#
|
|
6
7
|
# Please note that hints are commented out by default since Foundation
|
|
7
|
-
#
|
|
8
|
+
# doesn't provide styles for hints. You will need to provide your own CSS styles for hints.
|
|
8
9
|
# Uncomment them to enable hints.
|
|
9
10
|
|
|
10
11
|
config.wrappers :vertical_form, class: :input, hint_class: :field_with_hint, error_class: :error do |b|
|
|
11
12
|
b.use :html5
|
|
12
13
|
b.use :placeholder
|
|
13
14
|
b.optional :maxlength
|
|
15
|
+
b.optional :minlength
|
|
14
16
|
b.optional :pattern
|
|
15
17
|
b.optional :min_max
|
|
16
18
|
b.optional :readonly
|
|
@@ -24,6 +26,7 @@ SimpleForm.setup do |config|
|
|
|
24
26
|
b.use :html5
|
|
25
27
|
b.use :placeholder
|
|
26
28
|
b.optional :maxlength
|
|
29
|
+
b.optional :minlength
|
|
27
30
|
b.optional :pattern
|
|
28
31
|
b.optional :min_max
|
|
29
32
|
b.optional :readonly
|
|
@@ -44,7 +47,7 @@ SimpleForm.setup do |config|
|
|
|
44
47
|
b.optional :readonly
|
|
45
48
|
|
|
46
49
|
b.wrapper :container_wrapper, tag: 'div', class: 'small-offset-3 small-9 columns' do |ba|
|
|
47
|
-
ba.wrapper :
|
|
50
|
+
ba.wrapper tag: 'label', class: 'checkbox' do |bb|
|
|
48
51
|
bb.use :input
|
|
49
52
|
bb.use :label_text
|
|
50
53
|
end
|
|
@@ -65,6 +68,7 @@ SimpleForm.setup do |config|
|
|
|
65
68
|
b.use :html5
|
|
66
69
|
b.use :placeholder
|
|
67
70
|
b.optional :maxlength
|
|
71
|
+
b.optional :minlength
|
|
68
72
|
b.optional :pattern
|
|
69
73
|
b.optional :min_max
|
|
70
74
|
b.optional :readonly
|
|
@@ -95,7 +99,7 @@ SimpleForm.setup do |config|
|
|
|
95
99
|
config.button_class = 'button'
|
|
96
100
|
|
|
97
101
|
# Set this to div to make the checkbox and radio properly work
|
|
98
|
-
# otherwise simple_form adds a label tag instead of a div
|
|
102
|
+
# otherwise simple_form adds a label tag instead of a div around
|
|
99
103
|
# the nested label
|
|
100
104
|
config.item_wrapper_tag = :div
|
|
101
105
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
module SimpleForm
|
|
2
3
|
module Components
|
|
3
4
|
module Errors
|
|
@@ -38,7 +39,7 @@ module SimpleForm
|
|
|
38
39
|
end
|
|
39
40
|
|
|
40
41
|
def errors_on_attribute
|
|
41
|
-
object.errors[attribute_name]
|
|
42
|
+
object.errors[attribute_name] || []
|
|
42
43
|
end
|
|
43
44
|
|
|
44
45
|
def full_errors_on_attribute
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
module SimpleForm
|
|
2
3
|
module Components
|
|
3
4
|
module LabelInput
|
|
@@ -20,7 +21,7 @@ module SimpleForm
|
|
|
20
21
|
def deprecated_component(namespace, wrapper_options)
|
|
21
22
|
method = method(namespace)
|
|
22
23
|
|
|
23
|
-
if method.arity
|
|
24
|
+
if method.arity.zero?
|
|
24
25
|
ActiveSupport::Deprecation.warn(SimpleForm::CUSTOM_INPUT_DEPRECATION_WARN % { name: namespace })
|
|
25
26
|
|
|
26
27
|
method.call
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
module SimpleForm
|
|
2
3
|
module Components
|
|
3
4
|
module Labels
|
|
@@ -7,7 +8,7 @@ module SimpleForm
|
|
|
7
8
|
def translate_required_html
|
|
8
9
|
i18n_cache :translate_required_html do
|
|
9
10
|
I18n.t(:"simple_form.required.html", default:
|
|
10
|
-
%
|
|
11
|
+
%(<abbr title="#{translate_required_text}">#{translate_required_mark}</abbr>)
|
|
11
12
|
)
|
|
12
13
|
end
|
|
13
14
|
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module SimpleForm
|
|
3
|
+
module Components
|
|
4
|
+
# Needs to be enabled in order to do automatic lookups.
|
|
5
|
+
module Minlength
|
|
6
|
+
def minlength(wrapper_options = nil)
|
|
7
|
+
input_html_options[:minlength] ||= minimum_length_from_validation
|
|
8
|
+
nil
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
private
|
|
12
|
+
|
|
13
|
+
def minimum_length_from_validation
|
|
14
|
+
minlength = options[:minlength]
|
|
15
|
+
if minlength.is_a?(String) || minlength.is_a?(Integer)
|
|
16
|
+
minlength
|
|
17
|
+
else
|
|
18
|
+
length_validator = find_length_validator
|
|
19
|
+
minimum_length_value_from(length_validator)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def find_length_validator
|
|
24
|
+
find_validator(:length)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def has_tokenizer?(length_validator)
|
|
28
|
+
length_validator.options[:tokenizer]
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Use validation with tokenizer if version of Rails is less than 5,
|
|
32
|
+
# if not validate without the tokenizer, if version is greater than Rails 4.
|
|
33
|
+
if ActionPack::VERSION::STRING < '5'
|
|
34
|
+
def minimum_length_value_from(length_validator)
|
|
35
|
+
if length_validator && !has_tokenizer?(length_validator)
|
|
36
|
+
length_validator.options[:is] || length_validator.options[:minimum]
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
elsif ActionPack::VERSION::STRING >= '5'
|
|
40
|
+
def minimum_length_value_from(length_validator)
|
|
41
|
+
if length_validator
|
|
42
|
+
length_validator.options[:is] || length_validator.options[:minimum]
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
module SimpleForm
|
|
2
3
|
# Components are a special type of helpers that can work on their own.
|
|
3
4
|
# For example, by using a component, it will automatically change the
|
|
@@ -15,6 +16,7 @@ module SimpleForm
|
|
|
15
16
|
autoload :Labels
|
|
16
17
|
autoload :MinMax
|
|
17
18
|
autoload :Maxlength
|
|
19
|
+
autoload :Minlength
|
|
18
20
|
autoload :Pattern
|
|
19
21
|
autoload :Placeholders
|
|
20
22
|
autoload :Readonly
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
require 'active_support/core_ext/object/deep_dup'
|
|
2
3
|
require 'simple_form/map_type'
|
|
3
4
|
require 'simple_form/tags'
|
|
@@ -12,7 +13,7 @@ module SimpleForm
|
|
|
12
13
|
'update' => 'edit'
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
ATTRIBUTE_COMPONENTS = [
|
|
16
|
+
ATTRIBUTE_COMPONENTS = %i[html5 min_max maxlength minlength placeholder pattern readonly]
|
|
16
17
|
|
|
17
18
|
extend MapType
|
|
18
19
|
include SimpleForm::Inputs
|
|
@@ -38,6 +39,7 @@ module SimpleForm
|
|
|
38
39
|
|
|
39
40
|
def initialize(*) #:nodoc:
|
|
40
41
|
super
|
|
42
|
+
@object = convert_to_model(@object)
|
|
41
43
|
@defaults = options[:defaults]
|
|
42
44
|
@wrapper = SimpleForm.wrapper(options[:wrapper] || SimpleForm.default_wrapper)
|
|
43
45
|
end
|
|
@@ -461,13 +463,17 @@ module SimpleForm
|
|
|
461
463
|
relation = reflection.klass.all
|
|
462
464
|
|
|
463
465
|
if reflection.respond_to?(:scope) && reflection.scope
|
|
464
|
-
|
|
466
|
+
if reflection.scope.parameters.any?
|
|
467
|
+
relation = reflection.klass.instance_exec(object, &reflection.scope)
|
|
468
|
+
else
|
|
469
|
+
relation = reflection.klass.instance_exec(&reflection.scope)
|
|
470
|
+
end
|
|
465
471
|
else
|
|
466
472
|
order = reflection.options[:order]
|
|
467
473
|
conditions = reflection.options[:conditions]
|
|
468
474
|
conditions = object.instance_exec(&conditions) if conditions.respond_to?(:call)
|
|
469
475
|
|
|
470
|
-
relation = relation.where(conditions)
|
|
476
|
+
relation = relation.where(conditions) if relation.respond_to?(:where)
|
|
471
477
|
relation = relation.order(order) if relation.respond_to?(:order)
|
|
472
478
|
end
|
|
473
479
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
module SimpleForm
|
|
2
3
|
module Helpers
|
|
3
4
|
module Validators
|
|
@@ -24,7 +25,7 @@ module SimpleForm
|
|
|
24
25
|
end
|
|
25
26
|
|
|
26
27
|
def action_validator_match?(validator)
|
|
27
|
-
return true
|
|
28
|
+
return true unless validator.options.include?(:on)
|
|
28
29
|
|
|
29
30
|
case validator.options[:on]
|
|
30
31
|
when :save
|
data/lib/simple_form/helpers.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
require 'simple_form/i18n_cache'
|
|
2
3
|
require 'active_support/core_ext/string/output_safety'
|
|
3
4
|
require 'action_view/helpers'
|
|
@@ -21,6 +22,7 @@ module SimpleForm
|
|
|
21
22
|
include SimpleForm::Components::HTML5
|
|
22
23
|
include SimpleForm::Components::LabelInput
|
|
23
24
|
include SimpleForm::Components::Maxlength
|
|
25
|
+
include SimpleForm::Components::Minlength
|
|
24
26
|
include SimpleForm::Components::MinMax
|
|
25
27
|
include SimpleForm::Components::Pattern
|
|
26
28
|
include SimpleForm::Components::Placeholders
|
|
@@ -50,7 +52,7 @@ module SimpleForm
|
|
|
50
52
|
enable :hint
|
|
51
53
|
|
|
52
54
|
# Usually disabled, needs to be enabled explicitly passing true as option.
|
|
53
|
-
disable :maxlength, :placeholder, :pattern, :min_max
|
|
55
|
+
disable :maxlength, :minlength, :placeholder, :pattern, :min_max
|
|
54
56
|
|
|
55
57
|
def initialize(builder, attribute_name, column, input_type, options = {})
|
|
56
58
|
super
|
|
@@ -94,7 +96,7 @@ module SimpleForm
|
|
|
94
96
|
end
|
|
95
97
|
|
|
96
98
|
def input_class
|
|
97
|
-
"#{lookup_model_names.join(
|
|
99
|
+
"#{lookup_model_names.join('_')}_#{reflection_or_attribute_name}"
|
|
98
100
|
end
|
|
99
101
|
|
|
100
102
|
private
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
module SimpleForm
|
|
2
3
|
module Inputs
|
|
3
4
|
class BooleanInput < Base
|
|
@@ -6,7 +7,7 @@ module SimpleForm
|
|
|
6
7
|
|
|
7
8
|
if nested_boolean_style?
|
|
8
9
|
build_hidden_field_for_checkbox +
|
|
9
|
-
template.label_tag(nil, class:
|
|
10
|
+
template.label_tag(nil, class: boolean_label_class) {
|
|
10
11
|
build_check_box_without_hidden_field(merged_input_options) +
|
|
11
12
|
inline_label
|
|
12
13
|
}
|
|
@@ -21,7 +22,7 @@ module SimpleForm
|
|
|
21
22
|
elsif nested_boolean_style?
|
|
22
23
|
html_options = label_html_options.dup
|
|
23
24
|
html_options[:class] ||= []
|
|
24
|
-
html_options[:class].push(
|
|
25
|
+
html_options[:class].push(boolean_label_class) if boolean_label_class
|
|
25
26
|
|
|
26
27
|
merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
|
|
27
28
|
|
|
@@ -36,6 +37,10 @@ module SimpleForm
|
|
|
36
37
|
|
|
37
38
|
private
|
|
38
39
|
|
|
40
|
+
def boolean_label_class
|
|
41
|
+
options[:boolean_label_class] || SimpleForm.boolean_label_class
|
|
42
|
+
end
|
|
43
|
+
|
|
39
44
|
# Build a checkbox tag using default unchecked value. This allows us to
|
|
40
45
|
# reuse the method for nested boolean style, but with no unchecked value,
|
|
41
46
|
# which won't generate the hidden checkbox. This is the default functionality
|
|
@@ -55,9 +60,9 @@ module SimpleForm
|
|
|
55
60
|
# we need the hidden field to be *outside* the label (otherwise it
|
|
56
61
|
# generates invalid html - html5 only).
|
|
57
62
|
def build_hidden_field_for_checkbox
|
|
58
|
-
return ""
|
|
63
|
+
return "" if !include_hidden? || !unchecked_value
|
|
59
64
|
options = { value: unchecked_value, id: nil, disabled: input_html_options[:disabled] }
|
|
60
|
-
options[:name] = input_html_options[:name] if input_html_options.
|
|
65
|
+
options[:name] = input_html_options[:name] if input_html_options.key?(:name)
|
|
61
66
|
|
|
62
67
|
@builder.hidden_field(attribute_name, options)
|
|
63
68
|
end
|