simple_form 3.5.0 → 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 +17 -0
- data/README.md +38 -28
- 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 +1 -0
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +1 -0
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +2 -1
- data/lib/simple_form.rb +8 -6
- 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.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 +2 -1
- 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/error_notification.rb +1 -0
- data/lib/simple_form/form_builder.rb +9 -3
- data/lib/simple_form/helpers.rb +1 -0
- 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/i18n_cache.rb +1 -0
- data/lib/simple_form/inputs.rb +1 -0
- data/lib/simple_form/inputs/base.rb +2 -1
- data/lib/simple_form/inputs/block_input.rb +1 -0
- data/lib/simple_form/inputs/boolean_input.rb +3 -2
- data/lib/simple_form/inputs/collection_check_boxes_input.rb +2 -1
- data/lib/simple_form/inputs/collection_input.rb +3 -2
- 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 +1 -0
- 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 +1 -0
- data/lib/simple_form/inputs/text_input.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.rb +1 -0
- 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/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 +10 -3
- data/test/form_builder/hint_test.rb +6 -0
- data/test/form_builder/input_field_test.rb +2 -1
- 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 +9 -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 +2 -1
- data/test/inputs/text_input_test.rb +1 -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 +4 -0
- data/test/support/models.rb +36 -12
- data/test/test_helper.rb +2 -0
- metadata +3 -3
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,22 @@
|
|
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
|
+
|
3
20
|
## 3.5.0
|
4
21
|
|
5
22
|
* Updated gem dependency to support Rails 5.1.x.
|
data/README.md
CHANGED
@@ -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
|
|
@@ -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
|
# Don't forget to edit this file to adapt it to your needs (specially
|
@@ -46,7 +47,7 @@ SimpleForm.setup do |config|
|
|
46
47
|
b.optional :readonly
|
47
48
|
|
48
49
|
b.wrapper :container_wrapper, tag: 'div', class: 'small-offset-3 small-9 columns' do |ba|
|
49
|
-
ba.wrapper :
|
50
|
+
ba.wrapper tag: 'label', class: 'checkbox' do |bb|
|
50
51
|
bb.use :input
|
51
52
|
bb.use :label_text
|
52
53
|
end
|
data/lib/simple_form.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'action_view'
|
3
|
+
require 'action_pack'
|
2
4
|
require 'simple_form/action_view_extensions/form_helper'
|
3
5
|
require 'simple_form/action_view_extensions/builder'
|
4
6
|
require 'active_support/core_ext/hash/slice'
|
@@ -58,11 +60,11 @@ See https://github.com/plataformatec/simple_form/pull/997 for more information.
|
|
58
60
|
|
59
61
|
# Series of attemps to detect a default label method for collection.
|
60
62
|
mattr_accessor :collection_label_methods
|
61
|
-
@@collection_label_methods = [
|
63
|
+
@@collection_label_methods = %i[to_label name title to_s]
|
62
64
|
|
63
65
|
# Series of attemps to detect a default value method for collection.
|
64
66
|
mattr_accessor :collection_value_methods
|
65
|
-
@@collection_value_methods = [
|
67
|
+
@@collection_value_methods = %i[id to_s]
|
66
68
|
|
67
69
|
# You can wrap a collection of radio/check boxes in a pre-defined tag, defaulting to none.
|
68
70
|
mattr_accessor :collection_wrapper_tag
|
@@ -84,7 +86,7 @@ See https://github.com/plataformatec/simple_form/pull/997 for more information.
|
|
84
86
|
|
85
87
|
# How the label text should be generated altogether with the required text.
|
86
88
|
mattr_accessor :label_text
|
87
|
-
@@label_text =
|
89
|
+
@@label_text = ->(label, required, explicit_label) { "#{required} #{label}" }
|
88
90
|
|
89
91
|
# You can define the class to be used on all labels. Defaults to none.
|
90
92
|
mattr_accessor :label_class
|
@@ -108,7 +110,7 @@ See https://github.com/plataformatec/simple_form/pull/997 for more information.
|
|
108
110
|
|
109
111
|
# You can define which elements should obtain additional classes.
|
110
112
|
mattr_accessor :generate_additional_classes_for
|
111
|
-
@@generate_additional_classes_for = [
|
113
|
+
@@generate_additional_classes_for = %i[wrapper label input]
|
112
114
|
|
113
115
|
# Whether attributes are required by default or not.
|
114
116
|
mattr_accessor :required_by_default
|
@@ -120,7 +122,7 @@ See https://github.com/plataformatec/simple_form/pull/997 for more information.
|
|
120
122
|
|
121
123
|
# Collection of methods to detect if a file type was given.
|
122
124
|
mattr_accessor :file_methods
|
123
|
-
@@file_methods = [
|
125
|
+
@@file_methods = %i[mounted_as file? public_filename]
|
124
126
|
|
125
127
|
# Custom mappings for input types. This should be a hash containing a regexp
|
126
128
|
# to match as key, and the input type that will be used when the field name
|
@@ -163,7 +165,7 @@ See https://github.com/plataformatec/simple_form/pull/997 for more information.
|
|
163
165
|
|
164
166
|
# Cache SimpleForm inputs discovery.
|
165
167
|
mattr_accessor :cache_discovery
|
166
|
-
@@cache_discovery = defined?(Rails) && !Rails.env.development?
|
168
|
+
@@cache_discovery = defined?(Rails.env) && !Rails.env.development?
|
167
169
|
|
168
170
|
# Adds a class to each generated button, mostly for compatiblity.
|
169
171
|
mattr_accessor :button_class
|
@@ -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
|
@@ -1,9 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module SimpleForm
|
2
3
|
module Components
|
3
4
|
# Needs to be enabled in order to do automatic lookups.
|
4
5
|
module Minlength
|
5
6
|
def minlength(wrapper_options = nil)
|
6
|
-
input_html_options[:minlength] ||= minimum_length_from_validation
|
7
|
+
input_html_options[:minlength] ||= minimum_length_from_validation
|
7
8
|
nil
|
8
9
|
end
|
9
10
|
|
@@ -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
|
|
data/lib/simple_form/helpers.rb
CHANGED
@@ -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/inputs.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'
|
@@ -95,7 +96,7 @@ module SimpleForm
|
|
95
96
|
end
|
96
97
|
|
97
98
|
def input_class
|
98
|
-
"#{lookup_model_names.join(
|
99
|
+
"#{lookup_model_names.join('_')}_#{reflection_or_attribute_name}"
|
99
100
|
end
|
100
101
|
|
101
102
|
private
|