simple_form 5.3.1 → 5.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cfdcacda4f77b45f0a314651ceebcc8b55b7ad04292c947df7b8f7058b283b91
4
- data.tar.gz: 0cf232b39ab76dc175f729024d35f55551c10a1bb7d391d9feeb5b2252f0fc48
3
+ metadata.gz: 9ab83cf1fd374f5f1b1a26fb73e903b03f286fd32640db3c67e7cf270529e36d
4
+ data.tar.gz: 6b73d95e3515adcf607dbfa9a93b3556cf9219b8a32c6540ee98b822c3e75b1a
5
5
  SHA512:
6
- metadata.gz: c567585213251a013e64188da22598a980451d68fc96d8b9a7eb8f937b2b8d7fef6659d9213133728070c11d9e1ab8f647960cba60a9516b0805d6effcf07dac
7
- data.tar.gz: 6912ab15c194e3090b27b9331fd8f3db7402ba64e286c8165b816aa8ee7c7fea4c285b1e8df09ccfb2daaeb51393156df6369df6b4c52b13548c00e498c53494
6
+ metadata.gz: 5171360f4f381ba58c83a7d0f798770b7f9a90afd4eebd03a573ce2a48f352f3e9ebf1ec079152082fbe88a727b9f57f4cfc85b3ba5537f636a806b81aa298e4
7
+ data.tar.gz: 69a2e9865036691353286c66e785f11b1a0ba04acf2e9cf4ce701f35e54656db649c6f623b929d828553474cffece865109611690f730eeac1980646b51dcca4
data/CHANGELOG.md CHANGED
@@ -1,6 +1,17 @@
1
- ## Unreleased
1
+ ## 5.4.1
2
2
 
3
+ * Ruby 4.0 support (no changes required)
4
+ * Support procs on validators for minlength/maxlength, and improve validators logic across the board to match Rails [#1859](https://github.com/heartcombo/simple_form/pull/1859)
3
5
 
6
+ ## 5.4.0
7
+
8
+ * Add support for Ruby 3.4 and Rails 7.2/8.0/8.1. (no changes required)
9
+ * Drop support for Rails < 7 and Ruby < 2.7.
10
+ * Add `weekday` input. [#1846](https://github.com/heartcombo/simple_form/pull/1846)
11
+ * Remove redundant `aria-required` attribute for required fields. [#1823](https://github.com/heartcombo/simple_form/pull/1823)
12
+ * Integrate `:rich_text_area` with placeholders [#1842](https://github.com/heartcombo/simple_form/pull/1842)
13
+ * Fix encrypted attributes improperly casted (later fixed in Rails) [#1836](https://github.com/heartcombo/simple_form/pull/1836)
14
+ * Pass `base` object to `human_attribute_name` in labels [#1812](https://github.com/heartcombo/simple_form/pull/1812)
4
15
 
5
16
  ## 5.3.1
6
17
 
@@ -109,7 +120,7 @@ See http://blog.plataformatec.com.br/2019/09/incorrect-access-control-in-simple-
109
120
  ### Bug fix
110
121
  * Fix horizontal form label position, from right to text-right. [@cavpollo](https://github.com/cavpollo)
111
122
  * Add base error display alongside existing errors. [@bluefalcon26](https://github.com/bluefalcon26)
112
- * Silent deprication warning for placeholder_text. [@moofkit](https://github.com/moofkit)
123
+ * Silent deprecation warning for placeholder_text. [@moofkit](https://github.com/moofkit)
113
124
  * Use custom i18n scope for label required html. [@tvdeyen](https://github.com/tvdeyen)
114
125
 
115
126
  ## 3.5.1
@@ -231,7 +242,7 @@ See http://blog.plataformatec.com.br/2019/09/incorrect-access-control-in-simple-
231
242
 
232
243
  ### bug fix
233
244
  * Fix `full_error` when the attribute is an association. [@mvdamme](https://github.com/jorge-d)
234
- * Fix suppport to `:namespace` and `:index` options for nested check boxes and radio buttons when the attribute is an association.
245
+ * Fix support to `:namespace` and `:index` options for nested check boxes and radio buttons when the attribute is an association.
235
246
  * Collection input that uses automatic collection translation properly sets checked values.
236
247
  Closes [#971](https://github.com/heartcombo/simple_form/issues/971) [@nashby](https://github.com/nashby)
237
248
  * Collection input generates `required` attribute if it has `prompt` option. [@nashby](https://github.com/nashby)
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2020-2024 Rafael França, Carlos Antônio da Silva
1
+ Copyright (c) 2020-CURRENT Rafael França, Carlos Antonio da Silva
2
2
  Copyright (c) 2009-2019 Plataformatec
3
3
 
4
4
  Permission is hereby granted, free of charge, to any person obtaining
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  ![Simple Form Logo](https://raw.github.com/heartcombo/simple_form/main/simple_form.png)
2
2
 
3
+ [![Gem Version](https://fury-badge.herokuapp.com/rb/simple_form.png)](http://badge.fury.io/rb/simple_form)
4
+
3
5
  Rails forms made easy.
4
6
 
5
7
  **Simple Form** aims to be as flexible as possible while helping you with powerful components to create
@@ -621,11 +623,13 @@ Mapping | Generated HTML Element | Database Column Type
621
623
  `datetime` | `datetime select` | `datetime/timestamp`
622
624
  `date` | `date select` | `date`
623
625
  `time` | `time select` | `time`
626
+ `weekday` | `select` (weekdays as options) | -
624
627
  `select` | `select` | `belongs_to`/`has_many`/`has_and_belongs_to_many` associations
625
628
  `radio_buttons` | collection of `input[type=radio]` | `belongs_to` associations
626
629
  `check_boxes` | collection of `input[type=checkbox]` | `has_many`/`has_and_belongs_to_many` associations
627
630
  `country` | `select` (countries as options) | `string` with `name =~ /country/`
628
631
  `time_zone` | `select` (timezones as options) | `string` with `name =~ /time_zone/`
632
+ `rich_text_area`| `trix-editor` | -
629
633
 
630
634
  ## Custom inputs
631
635
 
@@ -1187,7 +1191,7 @@ by passing the html5 option:
1187
1191
  <%= f.input :expires_at, as: :date, html5: true %>
1188
1192
  ```
1189
1193
 
1190
- ### Using non Active Record objects
1194
+ ## Using non Active Record objects
1191
1195
 
1192
1196
  There are few ways to build forms with objects that don't inherit from Active Record, as
1193
1197
  follows:
@@ -1236,6 +1240,45 @@ class User
1236
1240
  end
1237
1241
  ```
1238
1242
 
1243
+ To have SimpleForm infer the attributes' types, you can provide
1244
+ `#has_attribute?` and `#type_for_attribute` methods.
1245
+ The later should return an object that responds to `#type`
1246
+ with the attribute type. This is useful for generating
1247
+ the correct input types (eg: checkboxes for booleans).
1248
+
1249
+ ```ruby
1250
+ class User < Struct.new(:id, :name, :age, :registered)
1251
+ def to_model
1252
+ self
1253
+ end
1254
+
1255
+ def model_name
1256
+ OpenStruct.new(param_key: "user")
1257
+ end
1258
+
1259
+ def to_key
1260
+ id
1261
+ end
1262
+
1263
+ def persisted?
1264
+ id.present?
1265
+ end
1266
+
1267
+ def has_attribute?(attr_name)
1268
+ %w(id name age registered).include?(attr_name.to_s)
1269
+ end
1270
+
1271
+ def type_for_attribute(attr_name)
1272
+ case attr_name.to_s
1273
+ when "id" then OpenStruct.new(type: :integer)
1274
+ when "name" then OpenStruct.new(type: :string)
1275
+ when "age" then OpenStruct.new(type: :integer)
1276
+ when "registered" then OpenStruct.new(type: :boolean)
1277
+ end
1278
+ end
1279
+ end
1280
+ ```
1281
+
1239
1282
  If your object doesn't implement those methods, you must make explicit it when you are
1240
1283
  building the form
1241
1284
 
@@ -1280,19 +1323,12 @@ sending us a pull request.
1280
1323
 
1281
1324
  https://github.com/heartcombo/simple_form/issues
1282
1325
 
1283
- If you have discovered a security related bug, please do NOT use the GitHub issue tracker. Send an e-mail to heartcombo@googlegroups.com.
1284
-
1285
- ## Maintainers
1286
-
1287
- * Carlos Antonio da Silva (https://github.com/carlosantoniodasilva)
1288
- * Rafael Mendonça França (https://github.com/rafaelfranca)
1289
- * Felipe Renan (https://github.com/feliperenan)
1290
-
1291
- [![Gem Version](https://fury-badge.herokuapp.com/rb/simple_form.png)](http://badge.fury.io/rb/simple_form)
1292
- [![Inline docs](http://inch-ci.org/github/heartcombo/simple_form.png)](http://inch-ci.org/github/heartcombo/simple_form)
1326
+ If you have discovered a security related bug, please do NOT use the GitHub issue tracker. Send an e-mail to heartcombo.oss@gmail.com.
1293
1327
 
1294
1328
  ## License
1295
1329
 
1296
- MIT License. Copyright 2020-2024 Rafael França, Carlos Antônio da Silva. Copyright 2009-2019 Plataformatec.
1330
+ MIT License.
1331
+ Copyright 2020-CURRENT Rafael França, Carlos Antonio da Silva.
1332
+ Copyright 2009-2019 Plataformatec.
1297
1333
 
1298
1334
  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/).
@@ -10,10 +10,7 @@ module SimpleForm
10
10
  @html5 = true
11
11
 
12
12
  input_html_options[:required] = input_html_required_option
13
- input_html_options[:'aria-required'] = input_html_aria_required_option
14
-
15
13
  input_html_options[:'aria-invalid'] = has_errors? || nil
16
-
17
14
  nil
18
15
  end
19
16
 
@@ -25,10 +22,6 @@ module SimpleForm
25
22
  !options[:required].nil? ? required_field? : has_required?
26
23
  end
27
24
 
28
- def input_html_aria_required_option
29
- !options[:required].nil? ? (required_field? || nil) : (has_required? || nil)
30
- end
31
-
32
25
  def has_required?
33
26
  # We need to check browser_validations because
34
27
  # some browsers are still checking required even
@@ -74,7 +74,7 @@ module SimpleForm
74
74
  if SimpleForm.translate_labels && (translated_label = translate_from_namespace(:labels))
75
75
  translated_label
76
76
  elsif object.class.respond_to?(:human_attribute_name)
77
- object.class.human_attribute_name(reflection_or_attribute_name.to_s)
77
+ object.class.human_attribute_name(reflection_or_attribute_name.to_s, { base: object })
78
78
  else
79
79
  attribute_name.to_s.humanize
80
80
  end
@@ -26,7 +26,8 @@ module SimpleForm
26
26
 
27
27
  def maximum_length_value_from(length_validator)
28
28
  if length_validator
29
- length_validator.options[:is] || length_validator.options[:maximum]
29
+ value = length_validator.options[:is] || length_validator.options[:maximum]
30
+ resolve_validator_value(value)
30
31
  end
31
32
  end
32
33
  end
@@ -19,33 +19,23 @@ module SimpleForm
19
19
 
20
20
  def minimum_value(validator_options)
21
21
  if integer? && validator_options.key?(:greater_than)
22
- evaluate_numericality_validator_option(validator_options[:greater_than]) + 1
22
+ resolve_validator_value(validator_options[:greater_than]) + 1
23
23
  else
24
- evaluate_numericality_validator_option(validator_options[:greater_than_or_equal_to])
24
+ resolve_validator_value(validator_options[:greater_than_or_equal_to])
25
25
  end
26
26
  end
27
27
 
28
28
  def maximum_value(validator_options)
29
29
  if integer? && validator_options.key?(:less_than)
30
- evaluate_numericality_validator_option(validator_options[:less_than]) - 1
30
+ resolve_validator_value(validator_options[:less_than]) - 1
31
31
  else
32
- evaluate_numericality_validator_option(validator_options[:less_than_or_equal_to])
32
+ resolve_validator_value(validator_options[:less_than_or_equal_to])
33
33
  end
34
34
  end
35
35
 
36
36
  def find_numericality_validator
37
37
  find_validator(:numericality)
38
38
  end
39
-
40
- def evaluate_numericality_validator_option(option)
41
- if option.is_a?(Numeric)
42
- option
43
- elsif option.is_a?(Symbol)
44
- object.send(option)
45
- elsif option.respond_to?(:call)
46
- option.call(object)
47
- end
48
- end
49
39
  end
50
40
  end
51
41
  end
@@ -26,7 +26,8 @@ module SimpleForm
26
26
 
27
27
  def minimum_length_value_from(length_validator)
28
28
  if length_validator
29
- length_validator.options[:is] || length_validator.options[:minimum]
29
+ value = length_validator.options[:is] || length_validator.options[:minimum]
30
+ resolve_validator_value(value)
30
31
  end
31
32
  end
32
33
  end
@@ -15,21 +15,13 @@ module SimpleForm
15
15
  if pattern.is_a?(String)
16
16
  pattern
17
17
  elsif (pattern_validator = find_pattern_validator) && (with = pattern_validator.options[:with])
18
- evaluate_format_validator_option(with).source
18
+ resolve_validator_value(with).source
19
19
  end
20
20
  end
21
21
 
22
22
  def find_pattern_validator
23
23
  find_validator(:format)
24
24
  end
25
-
26
- def evaluate_format_validator_option(option)
27
- if option.respond_to?(:call)
28
- option.call(object)
29
- else
30
- option
31
- end
32
- end
33
25
  end
34
26
  end
35
27
  end
@@ -274,7 +274,7 @@ module SimpleForm
274
274
  options = options.dup
275
275
 
276
276
  options[:error_prefix] ||= if object.class.respond_to?(:human_attribute_name)
277
- object.class.human_attribute_name(attribute_name.to_s)
277
+ object.class.human_attribute_name(attribute_name.to_s, { base: object })
278
278
  else
279
279
  attribute_name.to_s.humanize
280
280
  end
@@ -599,7 +599,11 @@ module SimpleForm
599
599
 
600
600
  def find_attribute_column(attribute_name)
601
601
  if @object.respond_to?(:type_for_attribute) && @object.has_attribute?(attribute_name)
602
- @object.type_for_attribute(attribute_name.to_s)
602
+ detected_type = @object.type_for_attribute(attribute_name.to_s)
603
+
604
+ # Some attributes like ActiveRecord::Encryption::EncryptedAttribute are detected
605
+ # as different type, in that case we need to use the original type
606
+ detected_type.respond_to?(:cast_type) ? detected_type.cast_type : detected_type
603
607
  elsif @object.respond_to?(:column_for_attribute) && @object.has_attribute?(attribute_name)
604
608
  @object.column_for_attribute(attribute_name)
605
609
  end
@@ -40,6 +40,27 @@ module SimpleForm
40
40
  def find_validator(kind)
41
41
  attribute_validators.find { |v| v.kind == kind } if has_validators?
42
42
  end
43
+
44
+ # Implements `ActiveModel::Validations::ResolveValue`, introduced by Rails 7.1.
45
+ # https://github.com/rails/rails/blob/v7.1.0/activemodel/lib/active_model/validations/resolve_value.rb
46
+ def resolve_validator_value(value)
47
+ case value
48
+ when Proc
49
+ if value.arity == 0
50
+ value.call
51
+ else
52
+ value.call(object)
53
+ end
54
+ when Symbol
55
+ object.send(value)
56
+ else
57
+ if value.respond_to?(:call)
58
+ value.call(object)
59
+ else
60
+ value
61
+ end
62
+ end
63
+ end
43
64
  end
44
65
  end
45
66
  end
@@ -2,6 +2,8 @@
2
2
  module SimpleForm
3
3
  module Inputs
4
4
  class RichTextAreaInput < Base
5
+ enable :placeholder
6
+
5
7
  def input(wrapper_options = nil)
6
8
  merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
7
9
 
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ module SimpleForm
3
+ module Inputs
4
+ class WeekdayInput < CollectionSelectInput
5
+ enable :placeholder
6
+
7
+ def input(wrapper_options = nil)
8
+ merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
9
+
10
+ @builder.weekday_select(attribute_name, input_options, merged_input_options)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -22,5 +22,6 @@ module SimpleForm
22
22
  autoload :RichTextAreaInput
23
23
  autoload :StringInput
24
24
  autoload :TextInput
25
+ autoload :WeekdayInput
25
26
  end
26
27
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module SimpleForm
3
- VERSION = "5.3.1".freeze
3
+ VERSION = "5.4.1".freeze
4
4
  end
data/lib/simple_form.rb CHANGED
@@ -73,11 +73,11 @@ See http://blog.plataformatec.com.br/2019/09/incorrect-access-control-in-simple-
73
73
  mattr_accessor :error_notification_class
74
74
  @@error_notification_class = :error_notification
75
75
 
76
- # Series of attemps to detect a default label method for collection.
76
+ # Series of attempts to detect a default label method for collection.
77
77
  mattr_accessor :collection_label_methods
78
78
  @@collection_label_methods = %i[to_label name title to_s]
79
79
 
80
- # Series of attemps to detect a default value method for collection.
80
+ # Series of attempts to detect a default value method for collection.
81
81
  mattr_accessor :collection_value_methods
82
82
  @@collection_value_methods = %i[id to_s]
83
83
 
@@ -178,7 +178,7 @@ See http://blog.plataformatec.com.br/2019/09/incorrect-access-control-in-simple-
178
178
  mattr_accessor :cache_discovery
179
179
  @@cache_discovery = defined?(Rails.env) && !Rails.env.development?
180
180
 
181
- # Adds a class to each generated button, mostly for compatiblity.
181
+ # Adds a class to each generated button, mostly for compatibility.
182
182
  mattr_accessor :button_class
183
183
  @@button_class = 'button'
184
184
 
metadata CHANGED
@@ -1,16 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_form
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.3.1
4
+ version: 5.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - José Valim
8
- - Carlos Antônio
8
+ - Carlos Antonio
9
9
  - Rafael França
10
- autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2024-05-24 00:00:00.000000000 Z
12
+ date: 1980-01-02 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: activemodel
@@ -18,30 +17,86 @@ dependencies:
18
17
  requirements:
19
18
  - - ">="
20
19
  - !ruby/object:Gem::Version
21
- version: '5.2'
20
+ version: '7.0'
22
21
  type: :runtime
23
22
  prerelease: false
24
23
  version_requirements: !ruby/object:Gem::Requirement
25
24
  requirements:
26
25
  - - ">="
27
26
  - !ruby/object:Gem::Version
28
- version: '5.2'
27
+ version: '7.0'
29
28
  - !ruby/object:Gem::Dependency
30
29
  name: actionpack
31
30
  requirement: !ruby/object:Gem::Requirement
32
31
  requirements:
33
32
  - - ">="
34
33
  - !ruby/object:Gem::Version
35
- version: '5.2'
34
+ version: '7.0'
36
35
  type: :runtime
37
36
  prerelease: false
38
37
  version_requirements: !ruby/object:Gem::Requirement
39
38
  requirements:
40
39
  - - ">="
41
40
  - !ruby/object:Gem::Version
42
- version: '5.2'
41
+ version: '7.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: country_select
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: minitest
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "<"
61
+ - !ruby/object:Gem::Version
62
+ version: '6'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "<"
68
+ - !ruby/object:Gem::Version
69
+ version: '6'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rake
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rdoc
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
43
98
  description: Forms made easy!
44
- email: heartcombo@googlegroups.com
99
+ email: heartcombo.oss@gmail.com
45
100
  executables: []
46
101
  extensions: []
47
102
  extra_rdoc_files: []
@@ -102,6 +157,7 @@ files:
102
157
  - lib/simple_form/inputs/rich_text_area_input.rb
103
158
  - lib/simple_form/inputs/string_input.rb
104
159
  - lib/simple_form/inputs/text_input.rb
160
+ - lib/simple_form/inputs/weekday_input.rb
105
161
  - lib/simple_form/map_type.rb
106
162
  - lib/simple_form/railtie.rb
107
163
  - lib/simple_form/tags.rb
@@ -122,7 +178,6 @@ metadata:
122
178
  source_code_uri: https://github.com/heartcombo/simple_form
123
179
  bug_tracker_uri: https://github.com/heartcombo/simple_form/issues
124
180
  wiki_uri: https://github.com/heartcombo/simple_form/wiki
125
- post_install_message:
126
181
  rdoc_options: []
127
182
  require_paths:
128
183
  - lib
@@ -130,15 +185,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
130
185
  requirements:
131
186
  - - ">="
132
187
  - !ruby/object:Gem::Version
133
- version: 2.5.0
188
+ version: 2.7.0
134
189
  required_rubygems_version: !ruby/object:Gem::Requirement
135
190
  requirements:
136
191
  - - ">="
137
192
  - !ruby/object:Gem::Version
138
193
  version: '0'
139
194
  requirements: []
140
- rubygems_version: 3.3.27
141
- signing_key:
195
+ rubygems_version: 4.0.3
142
196
  specification_version: 4
143
197
  summary: Forms made easy!
144
198
  test_files: []