simple_form 5.1.0 → 5.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8260fa0dbaf1a82ae7b8a5c120c4f26ba4e2f0c03a9821241bf6d2d193962384
4
- data.tar.gz: f1ef61699c7246302e31eb405c734816491b1698419bc810643b71c54d7ffb2d
3
+ metadata.gz: 5ad9e2ec1c9f339ea03d225a1dc971adea0fb60efc571cd40655b7738eff273f
4
+ data.tar.gz: 937cee947cb4432fea02ff967879356442721bed0e01cb0c4fa3e9f50626a2cb
5
5
  SHA512:
6
- metadata.gz: 31be8f22b6fbe417be6051466e6370c8d54e4667df16c1506a84580df69376daae06af454bb46e21b8b86e61fed6efaf954f45c876005f2b33dde00ad3ca8374
7
- data.tar.gz: 756ef0c153e13b61a6d6823f3ea9f615ee507e329effce3c31ca477b85de86c6b0aa7bb645802be3c405281b621777191b1c34efba2cdeceb9035c2dfbb9ce82
6
+ metadata.gz: cf3e4b076014b076ff2168a0a1d236e21fbdf631ea0198d9e6a3b86eff908de1068f8a0f972fa7f4f9990ca3e3f7ae1d63a762b53f9975cebbd71e4f1a5a233e
7
+ data.tar.gz: a0a12ac9760afd5ade06c4a26942adbe515570947b0ae1eb7889fb0d626e2e57b177e82e32a02346ec0fe23591ce74cd609f669892df0d9969ae8b858562ec91
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## Unreleased
2
+
3
+
4
+ ## 5.2.0
5
+
6
+ * Add support for Rails 7.0 and Ruby 3.1/3.2 (no changes required)
7
+ * Fix escaping issue on boolean input with `include_hidden: false` and custom wrapper.
8
+ * Update Bootstrap install generator version 5. [@mhw](https://github.com/mhw)
9
+ * Accept proc as `group_method` for grouped collection select
10
+ * Honor `include_hidden` option on inline boolean inputs [@yboulkaid](https://github.com/yboulkaid)
11
+ * Fix deprecation error when using country_select input.
12
+
1
13
  ## 5.1.0
2
14
 
3
15
  * 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.
data/README.md CHANGED
@@ -9,6 +9,43 @@ which we are thankful for and should make you feel right at home.
9
9
 
10
10
  INFO: This README refers to **Simple Form** 5.0. For older releases, check the related branch for your version.
11
11
 
12
+ <!-- START doctoc generated TOC please keep comment here to allow auto update -->
13
+ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
14
+ ## Table of Contents
15
+
16
+ - [Installation](#installation)
17
+ - [Bootstrap](#bootstrap-5)
18
+ - [Zurb Foundation 5](#zurb-foundation-5)
19
+ - [Country Select](#country-select)
20
+ - [Usage](#usage)
21
+ - [Stripping away all wrapper divs](#stripping-away-all-wrapper-divs)
22
+ - [Collections](#collections)
23
+ - [Priority](#priority)
24
+ - [Associations](#associations)
25
+ - [Buttons](#buttons)
26
+ - [Wrapping Rails Form Helpers](#wrapping-rails-form-helpers)
27
+ - [Extra helpers](#extra-helpers)
28
+ - [Simple Fields For](#simple-fields-for)
29
+ - [Collection Radio Buttons](#collection-radio-buttons)
30
+ - [Collection Check Boxes](#collection-check-boxes)
31
+ - [Available input types and defaults for each column type](#available-input-types-and-defaults-for-each-column-type)
32
+ - [Custom inputs](#custom-inputs)
33
+ - [Custom form builder](#custom-form-builder)
34
+ - [I18n](#i18n)
35
+ - [Configuration](#configuration)
36
+ - [The wrappers API](#the-wrappers-api)
37
+ - [Custom Components](#custom-components)
38
+ - [HTML 5 Notice](#html-5-notice)
39
+ - [Using non Active Record objects](#using-non-active-record-objects)
40
+ - [Information](#information)
41
+ - [RDocs](#rdocs)
42
+ - [Supported Ruby / Rails versions](#supported-ruby--rails-versions)
43
+ - [Bug reports](#bug-reports)
44
+ - [Maintainers](#maintainers)
45
+ - [License](#license)
46
+
47
+ <!-- END doctoc generated TOC please keep comment here to allow auto update -->
48
+
12
49
  ## Installation
13
50
 
14
51
  Add it to your Gemfile:
@@ -29,21 +66,23 @@ Run the generator:
29
66
  rails generate simple_form:install
30
67
  ```
31
68
 
32
- ### Bootstrap
69
+ ### Bootstrap 5
33
70
 
34
- **Simple Form** can be easily integrated to the [Bootstrap](http://getbootstrap.com/).
35
- To do that you have to use the `bootstrap` option in the install generator, like this:
71
+ **Simple Form** can be easily integrated with [Bootstrap 5](http://getbootstrap.com/).
72
+ Use the `bootstrap` option in the install generator, like this:
36
73
 
37
74
  ```console
38
75
  rails generate simple_form:install --bootstrap
39
76
  ```
40
77
 
78
+ This will add an initializer that configures **Simple Form** wrappers for
79
+ Bootstrap 5's [form controls](https://getbootstrap.com/docs/5.0/forms/overview/).
41
80
  You have to be sure that you added a copy of the [Bootstrap](http://getbootstrap.com/)
42
81
  assets on your application.
43
82
 
44
83
  For more information see the generator output, our
45
- [example application code](https://github.com/rafaelfranca/simple_form-bootstrap) and
46
- [the live example app](http://simple-form-bootstrap.plataformatec.com.br/).
84
+ [example application code](https://github.com/heartcombo/simple_form-bootstrap) and
85
+ [the live example app](https://simple-form-bootstrap.herokuapp.com/).
47
86
 
48
87
  ### Zurb Foundation 5
49
88
 
@@ -116,7 +155,7 @@ of any of them:
116
155
  ```erb
117
156
  <%= simple_form_for @user do |f| %>
118
157
  <%= f.input :username, label_html: { class: 'my_class' }, hint_html: { class: 'hint_class' } %>
119
- <%= f.input :password, hint: false, error_html: { id: 'password_error'} %>
158
+ <%= f.input :password, hint: false, error_html: { id: 'password_error' } %>
120
159
  <%= f.input :password_confirmation, label: false %>
121
160
  <%= f.button :submit %>
122
161
  <% end %>
@@ -218,7 +257,18 @@ the wrapper as well:
218
257
  <%= f.input :date_of_birth, as: :date, start_year: Date.today.year - 90,
219
258
  end_year: Date.today.year - 12, discard_day: true,
220
259
  order: [:month, :year] %>
221
- <%= f.input :accepts, as: :boolean, checked_value: true, unchecked_value: false %>
260
+ <%= f.input :accepts, as: :boolean, checked_value: 'positive', unchecked_value: 'negative' %>
261
+ <%= f.button :submit %>
262
+ <% end %>
263
+ ```
264
+
265
+ By default, **Simple Form** generates a hidden field to handle the un-checked case for boolean fields.
266
+ Passing `unchecked_value: false` in the options for boolean fields will cause this hidden field to be omitted,
267
+ following the convention in Rails. You can also specify `include_hidden: false` to skip the hidden field:
268
+
269
+ ```erb
270
+ <%= simple_form_for @user do |f| %>
271
+ <%= f.input :just_the_checked_case, as: :boolean, include_hidden: false %>
222
272
  <%= f.button :submit %>
223
273
  <% end %>
224
274
  ```
@@ -285,7 +335,7 @@ end
285
335
  </form>
286
336
  ```
287
337
 
288
- To view the actual RDocs for this, check them out here - http://rubydoc.info/github/heartcombo/simple_form/master/SimpleForm/FormBuilder:input_field
338
+ To view the actual RDocs for this, check them out here - http://rubydoc.info/github/heartcombo/simple_form/main/SimpleForm/FormBuilder:input_field
289
339
 
290
340
  ### Collections
291
341
 
@@ -326,14 +376,13 @@ If you want to change this behavior you must make it explicit, like this:
326
376
  <% end %>
327
377
  ```
328
378
 
329
- All other options given are sent straight to the underlying helper. For example, you can give prompt as:
379
+ All other options given are sent straight to the underlying Rails helper(s): [`collection_select`](http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_select), [`collection_check_boxes`](http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_check_boxes), [`collection_radio_buttons`](http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_radio_buttons). For example, you can pass `prompt` and `selected` as:
330
380
 
331
381
  ```ruby
332
382
  f.input :age, collection: 18..60, prompt: "Select your age", selected: 21
333
383
  ```
334
- Extra options are passed into helper [`collection_select`](http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_select).
335
384
 
336
- You may also find it useful to explicitly pass a value to the optional `:selected`, especially if passing a collection of nested objects.
385
+ It may also be useful to explicitly pass a value to the optional `:selected` like above, especially if passing a collection of nested objects.
337
386
 
338
387
  It is also possible to create grouped collection selects, that will use the html *optgroup* tags, like this:
339
388
 
@@ -1062,7 +1111,7 @@ Finally, add a new wrapper to the config/initializers/simple_form.rb file:
1062
1111
  ```ruby
1063
1112
  config.wrappers :with_numbers, tag: 'div', class: 'row', error_class: 'error' do |b|
1064
1113
  b.use :html5
1065
- b.use :number, wrap_with: { tag: 'div', class: 'span1 number'}
1114
+ b.use :number, wrap_with: { tag: 'div', class: 'span1 number' }
1066
1115
  b.wrapper tag: 'div', class: 'span8' do |ba|
1067
1116
  ba.use :placeholder
1068
1117
  ba.use :label
@@ -1214,7 +1263,7 @@ end
1214
1263
 
1215
1264
  You can view the **Simple Form** documentation in RDoc format here:
1216
1265
 
1217
- http://rubydoc.info/github/heartcombo/simple_form/master/frames
1266
+ http://rubydoc.info/github/heartcombo/simple_form/main/frames
1218
1267
 
1219
1268
  ### Supported Ruby / Rails versions
1220
1269
 
@@ -5,12 +5,12 @@ module SimpleForm
5
5
  desc "Copy SimpleForm default files"
6
6
  source_root File.expand_path('../templates', __FILE__)
7
7
  class_option :template_engine, desc: 'Template engine to be invoked (erb, haml or slim).'
8
- class_option :bootstrap, type: :boolean, desc: 'Add the Bootstrap wrappers to the SimpleForm initializer.'
8
+ class_option :bootstrap, type: :boolean, desc: 'Add the Bootstrap 5 wrappers to the SimpleForm initializer.'
9
9
  class_option :foundation, type: :boolean, desc: 'Add the Zurb Foundation 5 wrappers to the SimpleForm initializer.'
10
10
 
11
11
  def info_bootstrap
12
12
  return if options.bootstrap? || options.foundation?
13
- puts "SimpleForm 3 supports Bootstrap and Zurb Foundation 5. If you want "\
13
+ puts "SimpleForm supports Bootstrap 5 and Zurb Foundation 5. If you want "\
14
14
  "a configuration that is compatible with one of these frameworks, then please " \
15
15
  "re-run this generator with --bootstrap or --foundation as an option."
16
16
  end
@@ -5,6 +5,6 @@
5
5
 
6
6
  For usage examples and documentation, see:
7
7
 
8
- http://simple-form-bootstrap.plataformatec.com.br/
8
+ https://simple-form-bootstrap.herokuapp.com
9
9
 
10
10
  ===============================================================================
@@ -112,7 +112,7 @@ SimpleForm.setup do |config|
112
112
  # You can define the class to use on all labels. Default is nil.
113
113
  # config.label_class = nil
114
114
 
115
- # You can define the default class to be used on forms. Can be overriden
115
+ # You can define the default class to be used on forms. Can be overridden
116
116
  # with `html: { :class }`. Defaulting to none.
117
117
  # config.default_form_class = nil
118
118
 
@@ -1,10 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Please do not make direct changes to this file!
4
- # This generator is maintained by the community around simple_form-bootstrap:
5
- # https://github.com/rafaelfranca/simple_form-bootstrap
6
- # All future development, tests, and organization should happen there.
7
- # Background history: https://github.com/heartcombo/simple_form/issues/1561
3
+ # These defaults are defined and maintained by the community at
4
+ # https://github.com/heartcombo/simple_form-bootstrap
5
+ # Please submit feedback, changes and tests only there.
8
6
 
9
7
  # Uncomment this and change the path if necessary to include your own
10
8
  # components.
@@ -49,7 +47,7 @@ SimpleForm.setup do |config|
49
47
  # vertical forms
50
48
  #
51
49
  # vertical default_wrapper
52
- config.wrappers :vertical_form, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
50
+ config.wrappers :vertical_form, class: 'mb-3' do |b|
53
51
  b.use :html5
54
52
  b.use :placeholder
55
53
  b.optional :maxlength
@@ -57,90 +55,100 @@ SimpleForm.setup do |config|
57
55
  b.optional :pattern
58
56
  b.optional :min_max
59
57
  b.optional :readonly
60
- b.use :label
58
+ b.use :label, class: 'form-label'
61
59
  b.use :input, class: 'form-control', error_class: 'is-invalid', valid_class: 'is-valid'
62
- b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback' }
63
- b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
60
+ b.use :full_error, wrap_with: { class: 'invalid-feedback' }
61
+ b.use :hint, wrap_with: { class: 'form-text' }
64
62
  end
65
63
 
66
64
  # vertical input for boolean
67
- config.wrappers :vertical_boolean, tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
65
+ config.wrappers :vertical_boolean, tag: 'fieldset', class: 'mb-3' do |b|
68
66
  b.use :html5
69
67
  b.optional :readonly
70
- b.wrapper :form_check_wrapper, tag: 'div', class: 'form-check' do |bb|
68
+ b.wrapper :form_check_wrapper, class: 'form-check' do |bb|
71
69
  bb.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid'
72
70
  bb.use :label, class: 'form-check-label'
73
- bb.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback' }
74
- bb.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
71
+ bb.use :full_error, wrap_with: { class: 'invalid-feedback' }
72
+ bb.use :hint, wrap_with: { class: 'form-text' }
75
73
  end
76
74
  end
77
75
 
78
76
  # vertical input for radio buttons and check boxes
79
- config.wrappers :vertical_collection, item_wrapper_class: 'form-check', item_label_class: 'form-check-label', tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
77
+ config.wrappers :vertical_collection, item_wrapper_class: 'form-check', item_label_class: 'form-check-label', tag: 'fieldset', class: 'mb-3' do |b|
80
78
  b.use :html5
81
79
  b.optional :readonly
82
80
  b.wrapper :legend_tag, tag: 'legend', class: 'col-form-label pt-0' do |ba|
83
81
  ba.use :label_text
84
82
  end
85
83
  b.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid'
86
- b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
87
- b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
84
+ b.use :full_error, wrap_with: { class: 'invalid-feedback d-block' }
85
+ b.use :hint, wrap_with: { class: 'form-text' }
88
86
  end
89
87
 
90
88
  # vertical input for inline radio buttons and check boxes
91
- config.wrappers :vertical_collection_inline, item_wrapper_class: 'form-check form-check-inline', item_label_class: 'form-check-label', tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
89
+ config.wrappers :vertical_collection_inline, item_wrapper_class: 'form-check form-check-inline', item_label_class: 'form-check-label', tag: 'fieldset', class: 'mb-3' do |b|
92
90
  b.use :html5
93
91
  b.optional :readonly
94
92
  b.wrapper :legend_tag, tag: 'legend', class: 'col-form-label pt-0' do |ba|
95
93
  ba.use :label_text
96
94
  end
97
95
  b.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid'
98
- b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
99
- b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
96
+ b.use :full_error, wrap_with: { class: 'invalid-feedback d-block' }
97
+ b.use :hint, wrap_with: { class: 'form-text' }
100
98
  end
101
99
 
102
100
  # vertical file input
103
- config.wrappers :vertical_file, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
101
+ config.wrappers :vertical_file, class: 'mb-3' do |b|
104
102
  b.use :html5
105
103
  b.use :placeholder
106
104
  b.optional :maxlength
107
105
  b.optional :minlength
108
106
  b.optional :readonly
109
- b.use :label
110
- b.use :input, class: 'form-control-file', error_class: 'is-invalid', valid_class: 'is-valid'
111
- b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback' }
112
- b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
107
+ b.use :label, class: 'form-label'
108
+ b.use :input, class: 'form-control', error_class: 'is-invalid', valid_class: 'is-valid'
109
+ b.use :full_error, wrap_with: { class: 'invalid-feedback' }
110
+ b.use :hint, wrap_with: { class: 'form-text' }
111
+ end
112
+
113
+ # vertical select input
114
+ config.wrappers :vertical_select, class: 'mb-3' do |b|
115
+ b.use :html5
116
+ b.optional :readonly
117
+ b.use :label, class: 'form-label'
118
+ b.use :input, class: 'form-select', error_class: 'is-invalid', valid_class: 'is-valid'
119
+ b.use :full_error, wrap_with: { class: 'invalid-feedback' }
120
+ b.use :hint, wrap_with: { class: 'form-text' }
113
121
  end
114
122
 
115
123
  # vertical multi select
116
- config.wrappers :vertical_multi_select, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
124
+ config.wrappers :vertical_multi_select, class: 'mb-3' do |b|
117
125
  b.use :html5
118
126
  b.optional :readonly
119
- b.use :label
120
- b.wrapper tag: 'div', class: 'd-flex flex-row justify-content-between align-items-center' do |ba|
121
- ba.use :input, class: 'form-control mx-1', error_class: 'is-invalid', valid_class: 'is-valid'
127
+ b.use :label, class: 'form-label'
128
+ b.wrapper class: 'd-flex flex-row justify-content-between align-items-center' do |ba|
129
+ ba.use :input, class: 'form-select mx-1', error_class: 'is-invalid', valid_class: 'is-valid'
122
130
  end
123
- b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
124
- b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
131
+ b.use :full_error, wrap_with: { class: 'invalid-feedback d-block' }
132
+ b.use :hint, wrap_with: { class: 'form-text' }
125
133
  end
126
134
 
127
135
  # vertical range input
128
- config.wrappers :vertical_range, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
136
+ config.wrappers :vertical_range, class: 'mb-3' do |b|
129
137
  b.use :html5
130
138
  b.use :placeholder
131
139
  b.optional :readonly
132
140
  b.optional :step
133
- b.use :label
134
- b.use :input, class: 'form-control-range', error_class: 'is-invalid', valid_class: 'is-valid'
135
- b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
136
- b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
141
+ b.use :label, class: 'form-label'
142
+ b.use :input, class: 'form-range', error_class: 'is-invalid', valid_class: 'is-valid'
143
+ b.use :full_error, wrap_with: { class: 'invalid-feedback' }
144
+ b.use :hint, wrap_with: { class: 'form-text' }
137
145
  end
138
146
 
139
147
 
140
148
  # horizontal forms
141
149
  #
142
150
  # horizontal default_wrapper
143
- config.wrappers :horizontal_form, tag: 'div', class: 'form-group row', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
151
+ config.wrappers :horizontal_form, class: 'row mb-3' do |b|
144
152
  b.use :html5
145
153
  b.use :placeholder
146
154
  b.optional :maxlength
@@ -149,94 +157,103 @@ SimpleForm.setup do |config|
149
157
  b.optional :min_max
150
158
  b.optional :readonly
151
159
  b.use :label, class: 'col-sm-3 col-form-label'
152
- b.wrapper :grid_wrapper, tag: 'div', class: 'col-sm-9' do |ba|
160
+ b.wrapper :grid_wrapper, class: 'col-sm-9' do |ba|
153
161
  ba.use :input, class: 'form-control', error_class: 'is-invalid', valid_class: 'is-valid'
154
- ba.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback' }
155
- ba.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
162
+ ba.use :full_error, wrap_with: { class: 'invalid-feedback' }
163
+ ba.use :hint, wrap_with: { class: 'form-text' }
156
164
  end
157
165
  end
158
166
 
159
167
  # horizontal input for boolean
160
- config.wrappers :horizontal_boolean, tag: 'div', class: 'form-group row', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
168
+ config.wrappers :horizontal_boolean, class: 'row mb-3' do |b|
161
169
  b.use :html5
162
170
  b.optional :readonly
163
- b.wrapper tag: 'label', class: 'col-sm-3' do |ba|
164
- ba.use :label_text
165
- end
166
- b.wrapper :grid_wrapper, tag: 'div', class: 'col-sm-9' do |wr|
167
- wr.wrapper :form_check_wrapper, tag: 'div', class: 'form-check' do |bb|
171
+ b.wrapper :grid_wrapper, class: 'col-sm-9 offset-sm-3' do |wr|
172
+ wr.wrapper :form_check_wrapper, class: 'form-check' do |bb|
168
173
  bb.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid'
169
174
  bb.use :label, class: 'form-check-label'
170
- bb.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
171
- bb.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
175
+ bb.use :full_error, wrap_with: { class: 'invalid-feedback' }
176
+ bb.use :hint, wrap_with: { class: 'form-text' }
172
177
  end
173
178
  end
174
179
  end
175
180
 
176
181
  # horizontal input for radio buttons and check boxes
177
- config.wrappers :horizontal_collection, item_wrapper_class: 'form-check', item_label_class: 'form-check-label', tag: 'div', class: 'form-group row', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
182
+ config.wrappers :horizontal_collection, item_wrapper_class: 'form-check', item_label_class: 'form-check-label', class: 'row mb-3' do |b|
178
183
  b.use :html5
179
184
  b.optional :readonly
180
185
  b.use :label, class: 'col-sm-3 col-form-label pt-0'
181
- b.wrapper :grid_wrapper, tag: 'div', class: 'col-sm-9' do |ba|
186
+ b.wrapper :grid_wrapper, class: 'col-sm-9' do |ba|
182
187
  ba.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid'
183
- ba.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
184
- ba.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
188
+ ba.use :full_error, wrap_with: { class: 'invalid-feedback d-block' }
189
+ ba.use :hint, wrap_with: { class: 'form-text' }
185
190
  end
186
191
  end
187
192
 
188
193
  # horizontal input for inline radio buttons and check boxes
189
- config.wrappers :horizontal_collection_inline, item_wrapper_class: 'form-check form-check-inline', item_label_class: 'form-check-label', tag: 'div', class: 'form-group row', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
194
+ config.wrappers :horizontal_collection_inline, item_wrapper_class: 'form-check form-check-inline', item_label_class: 'form-check-label', class: 'row mb-3' do |b|
190
195
  b.use :html5
191
196
  b.optional :readonly
192
197
  b.use :label, class: 'col-sm-3 col-form-label pt-0'
193
- b.wrapper :grid_wrapper, tag: 'div', class: 'col-sm-9' do |ba|
198
+ b.wrapper :grid_wrapper, class: 'col-sm-9' do |ba|
194
199
  ba.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid'
195
- ba.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
196
- ba.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
200
+ ba.use :full_error, wrap_with: { class: 'invalid-feedback d-block' }
201
+ ba.use :hint, wrap_with: { class: 'form-text' }
197
202
  end
198
203
  end
199
204
 
200
205
  # horizontal file input
201
- config.wrappers :horizontal_file, tag: 'div', class: 'form-group row', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
206
+ config.wrappers :horizontal_file, class: 'row mb-3' do |b|
202
207
  b.use :html5
203
208
  b.use :placeholder
204
209
  b.optional :maxlength
205
210
  b.optional :minlength
206
211
  b.optional :readonly
207
212
  b.use :label, class: 'col-sm-3 col-form-label'
208
- b.wrapper :grid_wrapper, tag: 'div', class: 'col-sm-9' do |ba|
209
- ba.use :input, error_class: 'is-invalid', valid_class: 'is-valid'
210
- ba.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
211
- ba.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
213
+ b.wrapper :grid_wrapper, class: 'col-sm-9' do |ba|
214
+ ba.use :input, class: 'form-control', error_class: 'is-invalid', valid_class: 'is-valid'
215
+ ba.use :full_error, wrap_with: { class: 'invalid-feedback' }
216
+ ba.use :hint, wrap_with: { class: 'form-text' }
217
+ end
218
+ end
219
+
220
+ # horizontal select input
221
+ config.wrappers :horizontal_select, class: 'row mb-3' do |b|
222
+ b.use :html5
223
+ b.optional :readonly
224
+ b.use :label, class: 'col-sm-3 col-form-label'
225
+ b.wrapper :grid_wrapper, class: 'col-sm-9' do |ba|
226
+ ba.use :input, class: 'form-select', error_class: 'is-invalid', valid_class: 'is-valid'
227
+ ba.use :full_error, wrap_with: { class: 'invalid-feedback' }
228
+ ba.use :hint, wrap_with: { class: 'form-text' }
212
229
  end
213
230
  end
214
231
 
215
232
  # horizontal multi select
216
- config.wrappers :horizontal_multi_select, tag: 'div', class: 'form-group row', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
233
+ config.wrappers :horizontal_multi_select, class: 'row mb-3' do |b|
217
234
  b.use :html5
218
235
  b.optional :readonly
219
236
  b.use :label, class: 'col-sm-3 col-form-label'
220
- b.wrapper :grid_wrapper, tag: 'div', class: 'col-sm-9' do |ba|
221
- ba.wrapper tag: 'div', class: 'd-flex flex-row justify-content-between align-items-center' do |bb|
222
- bb.use :input, class: 'form-control mx-1', error_class: 'is-invalid', valid_class: 'is-valid'
237
+ b.wrapper :grid_wrapper, class: 'col-sm-9' do |ba|
238
+ ba.wrapper class: 'd-flex flex-row justify-content-between align-items-center' do |bb|
239
+ bb.use :input, class: 'form-select mx-1', error_class: 'is-invalid', valid_class: 'is-valid'
223
240
  end
224
- ba.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
225
- ba.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
241
+ ba.use :full_error, wrap_with: { class: 'invalid-feedback d-block' }
242
+ ba.use :hint, wrap_with: { class: 'form-text' }
226
243
  end
227
244
  end
228
245
 
229
246
  # horizontal range input
230
- config.wrappers :horizontal_range, tag: 'div', class: 'form-group row', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
247
+ config.wrappers :horizontal_range, class: 'row mb-3' do |b|
231
248
  b.use :html5
232
249
  b.use :placeholder
233
250
  b.optional :readonly
234
251
  b.optional :step
235
- b.use :label, class: 'col-sm-3 col-form-label'
236
- b.wrapper :grid_wrapper, tag: 'div', class: 'col-sm-9' do |ba|
237
- ba.use :input, class: 'form-control-range', error_class: 'is-invalid', valid_class: 'is-valid'
238
- ba.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
239
- ba.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
252
+ b.use :label, class: 'col-sm-3 col-form-label pt-0'
253
+ b.wrapper :grid_wrapper, class: 'col-sm-9' do |ba|
254
+ ba.use :input, class: 'form-range', error_class: 'is-invalid', valid_class: 'is-valid'
255
+ ba.use :full_error, wrap_with: { class: 'invalid-feedback' }
256
+ ba.use :hint, wrap_with: { class: 'form-text' }
240
257
  end
241
258
  end
242
259
 
@@ -244,7 +261,7 @@ SimpleForm.setup do |config|
244
261
  # inline forms
245
262
  #
246
263
  # inline default_wrapper
247
- config.wrappers :inline_form, tag: 'span', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
264
+ config.wrappers :inline_form, class: 'col-12' do |b|
248
265
  b.use :html5
249
266
  b.use :placeholder
250
267
  b.optional :maxlength
@@ -252,140 +269,66 @@ SimpleForm.setup do |config|
252
269
  b.optional :pattern
253
270
  b.optional :min_max
254
271
  b.optional :readonly
255
- b.use :label, class: 'sr-only'
272
+ b.use :label, class: 'visually-hidden'
256
273
 
257
274
  b.use :input, class: 'form-control', error_class: 'is-invalid', valid_class: 'is-valid'
258
- b.use :error, wrap_with: { tag: 'div', class: 'invalid-feedback' }
259
- b.optional :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
275
+ b.use :error, wrap_with: { class: 'invalid-feedback' }
276
+ b.optional :hint, wrap_with: { class: 'form-text' }
260
277
  end
261
278
 
262
279
  # inline input for boolean
263
- config.wrappers :inline_boolean, tag: 'span', class: 'form-check mb-2 mr-sm-2', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
280
+ config.wrappers :inline_boolean, class: 'col-12' do |b|
264
281
  b.use :html5
265
282
  b.optional :readonly
266
- b.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid'
267
- b.use :label, class: 'form-check-label'
268
- b.use :error, wrap_with: { tag: 'div', class: 'invalid-feedback' }
269
- b.optional :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
283
+ b.wrapper :form_check_wrapper, class: 'form-check' do |bb|
284
+ bb.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid'
285
+ bb.use :label, class: 'form-check-label'
286
+ bb.use :error, wrap_with: { class: 'invalid-feedback' }
287
+ bb.optional :hint, wrap_with: { class: 'form-text' }
288
+ end
270
289
  end
271
290
 
272
291
 
273
292
  # bootstrap custom forms
274
293
  #
275
- # custom input for boolean
276
- config.wrappers :custom_boolean, tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
277
- b.use :html5
278
- b.optional :readonly
279
- b.wrapper :form_check_wrapper, tag: 'div', class: 'custom-control custom-checkbox' do |bb|
280
- bb.use :input, class: 'custom-control-input', error_class: 'is-invalid', valid_class: 'is-valid'
281
- bb.use :label, class: 'custom-control-label'
282
- bb.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback' }
283
- bb.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
284
- end
285
- end
286
-
287
294
  # custom input switch for boolean
288
- config.wrappers :custom_boolean_switch, tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
295
+ config.wrappers :custom_boolean_switch, class: 'mb-3' do |b|
289
296
  b.use :html5
290
297
  b.optional :readonly
291
- b.wrapper :form_check_wrapper, tag: 'div', class: 'custom-control custom-switch' do |bb|
292
- bb.use :input, class: 'custom-control-input', error_class: 'is-invalid', valid_class: 'is-valid'
293
- bb.use :label, class: 'custom-control-label'
298
+ b.wrapper :form_check_wrapper, tag: 'div', class: 'form-check form-switch' do |bb|
299
+ bb.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid'
300
+ bb.use :label, class: 'form-check-label'
294
301
  bb.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback' }
295
- bb.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
302
+ bb.use :hint, wrap_with: { class: 'form-text' }
296
303
  end
297
304
  end
298
305
 
299
- # custom input for radio buttons and check boxes
300
- config.wrappers :custom_collection, item_wrapper_class: 'custom-control', item_label_class: 'custom-control-label', tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
301
- b.use :html5
302
- b.optional :readonly
303
- b.wrapper :legend_tag, tag: 'legend', class: 'col-form-label pt-0' do |ba|
304
- ba.use :label_text
305
- end
306
- b.use :input, class: 'custom-control-input', error_class: 'is-invalid', valid_class: 'is-valid'
307
- b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
308
- b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
309
- end
310
306
 
311
- # custom input for inline radio buttons and check boxes
312
- config.wrappers :custom_collection_inline, item_wrapper_class: 'custom-control custom-control-inline', item_label_class: 'custom-control-label', tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
313
- b.use :html5
314
- b.optional :readonly
315
- b.wrapper :legend_tag, tag: 'legend', class: 'col-form-label pt-0' do |ba|
316
- ba.use :label_text
317
- end
318
- b.use :input, class: 'custom-control-input', error_class: 'is-invalid', valid_class: 'is-valid'
319
- b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
320
- b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
321
- end
322
-
323
- # custom file input
324
- config.wrappers :custom_file, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
307
+ # Input Group - custom component
308
+ # see example app and config at https://github.com/heartcombo/simple_form-bootstrap
309
+ config.wrappers :input_group, class: 'mb-3' do |b|
325
310
  b.use :html5
326
311
  b.use :placeholder
327
312
  b.optional :maxlength
328
313
  b.optional :minlength
314
+ b.optional :pattern
315
+ b.optional :min_max
329
316
  b.optional :readonly
330
- b.use :label
331
- b.wrapper :custom_file_wrapper, tag: 'div', class: 'custom-file' do |ba|
332
- ba.use :input, class: 'custom-file-input', error_class: 'is-invalid', valid_class: 'is-valid'
333
- ba.use :label, class: 'custom-file-label'
334
- ba.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback' }
335
- end
336
- b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
337
- end
338
-
339
- # custom multi select
340
- config.wrappers :custom_multi_select, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
341
- b.use :html5
342
- b.optional :readonly
343
- b.use :label
344
- b.wrapper tag: 'div', class: 'd-flex flex-row justify-content-between align-items-center' do |ba|
345
- ba.use :input, class: 'custom-select mx-1', error_class: 'is-invalid', valid_class: 'is-valid'
317
+ b.use :label, class: 'form-label'
318
+ b.wrapper :input_group_tag, class: 'input-group' do |ba|
319
+ ba.optional :prepend
320
+ ba.use :input, class: 'form-control', error_class: 'is-invalid', valid_class: 'is-valid'
321
+ ba.optional :append
322
+ ba.use :full_error, wrap_with: { class: 'invalid-feedback' }
346
323
  end
347
- b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
348
- b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
349
- end
350
-
351
- # custom range input
352
- config.wrappers :custom_range, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
353
- b.use :html5
354
- b.use :placeholder
355
- b.optional :readonly
356
- b.optional :step
357
- b.use :label
358
- b.use :input, class: 'custom-range', error_class: 'is-invalid', valid_class: 'is-valid'
359
- b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
360
- b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
324
+ b.use :hint, wrap_with: { class: 'form-text' }
361
325
  end
362
326
 
363
327
 
364
- # Input Group - custom component
365
- # see example app and config at https://github.com/rafaelfranca/simple_form-bootstrap
366
- # config.wrappers :input_group, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
367
- # b.use :html5
368
- # b.use :placeholder
369
- # b.optional :maxlength
370
- # b.optional :minlength
371
- # b.optional :pattern
372
- # b.optional :min_max
373
- # b.optional :readonly
374
- # b.use :label
375
- # b.wrapper :input_group_tag, tag: 'div', class: 'input-group' do |ba|
376
- # ba.optional :prepend
377
- # ba.use :input, class: 'form-control', error_class: 'is-invalid', valid_class: 'is-valid'
378
- # ba.optional :append
379
- # end
380
- # b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
381
- # b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
382
- # end
383
-
384
-
385
328
  # Floating Labels form
386
329
  #
387
330
  # floating labels default_wrapper
388
- config.wrappers :floating_labels_form, tag: 'div', class: 'form-label-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
331
+ config.wrappers :floating_labels_form, class: 'form-floating mb-3' do |b|
389
332
  b.use :html5
390
333
  b.use :placeholder
391
334
  b.optional :maxlength
@@ -395,18 +338,18 @@ SimpleForm.setup do |config|
395
338
  b.optional :readonly
396
339
  b.use :input, class: 'form-control', error_class: 'is-invalid', valid_class: 'is-valid'
397
340
  b.use :label
398
- b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback' }
399
- b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
341
+ b.use :full_error, wrap_with: { class: 'invalid-feedback' }
342
+ b.use :hint, wrap_with: { class: 'form-text' }
400
343
  end
401
344
 
402
345
  # custom multi select
403
- config.wrappers :floating_labels_select, tag: 'div', class: 'form-label-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
346
+ config.wrappers :floating_labels_select, class: 'form-floating mb-3' do |b|
404
347
  b.use :html5
405
348
  b.optional :readonly
406
- b.use :input, class: 'custom-select', error_class: 'is-invalid', valid_class: 'is-valid'
349
+ b.use :input, class: 'form-select', error_class: 'is-invalid', valid_class: 'is-valid'
407
350
  b.use :label
408
- b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback' }
409
- b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
351
+ b.use :full_error, wrap_with: { class: 'invalid-feedback' }
352
+ b.use :hint, wrap_with: { class: 'form-text' }
410
353
  end
411
354
 
412
355
 
@@ -423,18 +366,7 @@ SimpleForm.setup do |config|
423
366
  file: :vertical_file,
424
367
  radio_buttons: :vertical_collection,
425
368
  range: :vertical_range,
426
- time: :vertical_multi_select
369
+ time: :vertical_multi_select,
370
+ select: :vertical_select
427
371
  }
428
-
429
- # enable custom form wrappers
430
- # config.wrapper_mappings = {
431
- # boolean: :custom_boolean,
432
- # check_boxes: :custom_collection,
433
- # date: :custom_multi_select,
434
- # datetime: :custom_multi_select,
435
- # file: :custom_file,
436
- # radio_buttons: :custom_collection,
437
- # range: :custom_range,
438
- # time: :custom_multi_select
439
- # }
440
372
  end
@@ -497,7 +497,7 @@ module SimpleForm
497
497
  conditions = reflection.options[:conditions]
498
498
  conditions = object.instance_exec(&conditions) if conditions.respond_to?(:call)
499
499
 
500
- relation = relation.where(conditions) if relation.respond_to?(:where)
500
+ relation = relation.where(conditions) if relation.respond_to?(:where) && conditions.present?
501
501
  relation = relation.order(order) if relation.respond_to?(:order)
502
502
  end
503
503
 
@@ -12,7 +12,11 @@ module SimpleForm
12
12
  inline_label
13
13
  }
14
14
  else
15
- build_check_box(unchecked_value, merged_input_options)
15
+ if include_hidden?
16
+ build_check_box(unchecked_value, merged_input_options)
17
+ else
18
+ build_check_box_without_hidden_field(merged_input_options)
19
+ end
16
20
  end
17
21
  end
18
22
 
@@ -60,7 +64,7 @@ module SimpleForm
60
64
  # we need the hidden field to be *outside* the label (otherwise it
61
65
  # generates invalid html - html5 only).
62
66
  def build_hidden_field_for_checkbox
63
- return "" if !include_hidden? || !unchecked_value
67
+ return "".html_safe if !include_hidden? || !unchecked_value
64
68
  options = { value: unchecked_value, id: nil, disabled: input_html_options[:disabled] }
65
69
  options[:name] = input_html_options[:name] if input_html_options.key?(:name)
66
70
  options[:form] = input_html_options[:form] if input_html_options.key?(:form)
@@ -23,7 +23,7 @@ module SimpleForm
23
23
 
24
24
  # Sample collection
25
25
  def collection
26
- @collection ||= grouped_collection.map { |collection| collection.try(:send, group_method) }.detect(&:present?) || []
26
+ @collection ||= grouped_collection.map { |collection| group_method.respond_to?(:call) ? group_method.call(collection) : collection.try(:send, group_method) }.detect(&:present?) || []
27
27
  end
28
28
 
29
29
  def group_method
@@ -5,8 +5,7 @@ module SimpleForm
5
5
  def input(wrapper_options = nil)
6
6
  merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
7
7
 
8
- @builder.send(:"#{input_type}_select", attribute_name, input_priority,
9
- input_options, merged_input_options)
8
+ send(:"#{input_type}_input", merged_input_options)
10
9
  end
11
10
 
12
11
  def input_priority
@@ -15,6 +14,21 @@ module SimpleForm
15
14
 
16
15
  protected
17
16
 
17
+ def country_input(merged_input_options)
18
+ @builder.send(:country_select,
19
+ attribute_name,
20
+ input_options.merge(priority_countries: input_priority),
21
+ merged_input_options)
22
+ end
23
+
24
+ def time_zone_input(merged_input_options)
25
+ @builder.send(:time_zone_select,
26
+ attribute_name,
27
+ input_priority,
28
+ input_options,
29
+ merged_input_options)
30
+ end
31
+
18
32
  def skip_include_blank?
19
33
  super || input_priority.present?
20
34
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module SimpleForm
3
- VERSION = "5.1.0".freeze
3
+ VERSION = "5.2.0".freeze
4
4
  end
data/lib/simple_form.rb CHANGED
@@ -114,7 +114,7 @@ See http://blog.plataformatec.com.br/2019/09/incorrect-access-control-in-simple-
114
114
  mattr_reader :form_class
115
115
  @@form_class = :simple_form
116
116
 
117
- # You can define the default class to be used on all forms. Can be overriden
117
+ # You can define the default class to be used on all forms. Can be overridden
118
118
  # with `html: { :class }`. Defaults to none.
119
119
  mattr_accessor :default_form_class
120
120
  @@default_form_class = nil
@@ -195,12 +195,12 @@ class WrapperTest < ActionView::TestCase
195
195
  with_form_for @user, :name
196
196
  assert_no_select "section.custom_wrapper div.another_wrapper label"
197
197
  assert_no_select "section.custom_wrapper div.another_wrapper input.string"
198
- output_buffer.replace ""
198
+ output_buffer.to_s.replace ""
199
199
 
200
200
  with_form_for @user, :name, wrapper: :another
201
201
  assert_select "section.custom_wrapper div.another_wrapper label"
202
202
  assert_select "section.custom_wrapper div.another_wrapper input.string"
203
- output_buffer.replace ""
203
+ output_buffer.to_s.replace ""
204
204
  end
205
205
 
206
206
  with_form_for @user, :name, wrapper: custom_wrapper
@@ -33,6 +33,11 @@ class BooleanInputTest < ActionView::TestCase
33
33
  assert_select 'input[type=hidden][value=off]'
34
34
  end
35
35
 
36
+ test 'input allows skipping hidden input when setting :include_hidden to false' do
37
+ with_input_for @user, :active, :boolean, include_hidden: false
38
+ assert_no_select "input[type=hidden][name='user[active]']"
39
+ end
40
+
36
41
  test 'input uses inline boolean style by default' do
37
42
  with_input_for @user, :active, :boolean
38
43
  assert_select 'input.boolean + label.boolean.optional'
@@ -154,6 +159,14 @@ class BooleanInputTest < ActionView::TestCase
154
159
  end
155
160
  end
156
161
 
162
+ test 'input with nested style and with single wrapper allows disabling hidden field' do
163
+ swap SimpleForm, boolean_style: :nested do
164
+ with_input_for @user, :active, :boolean, include_hidden: false, wrapper: custom_wrapper_with_wrapped_label_input
165
+ assert_select "label.boolean > input.boolean"
166
+ assert_no_select "input[type=hidden] + label.boolean"
167
+ end
168
+ end
169
+
157
170
  test 'input with nested style does not include hidden field when unchecked_value is false' do
158
171
  swap SimpleForm, boolean_style: :nested do
159
172
  with_input_for @user, :active, :boolean, unchecked_value: false
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+ # encoding: UTF-8
3
+ require 'test_helper'
4
+
5
+ class CountryInputTest < ActionView::TestCase
6
+ test 'input generates a country select field' do
7
+ with_input_for @user, :country, :country
8
+ assert_select 'select#user_country'
9
+ assert_select 'select option[value=BR]', 'Brazil'
10
+ assert_no_select 'select option[value=""][disabled=disabled]'
11
+ end
12
+
13
+ test 'input generates a country select with SimpleForm default' do
14
+ swap SimpleForm, country_priority: [ 'Brazil' ] do
15
+ with_input_for @user, :country, :country
16
+ assert_select 'select option[value="BR"] + option[value="---------------"][disabled=disabled]'
17
+ end
18
+ end
19
+
20
+ test 'input generates a country select using options priority' do
21
+ with_input_for @user, :country, :country, priority: [ 'Ukraine' ]
22
+ assert_select 'select option[value="UA"] + option[value="---------------"][disabled=disabled]'
23
+ end
24
+
25
+ test 'input does generate select element with required html attribute' do
26
+ with_input_for @user, :country, :country
27
+ assert_select 'select.required'
28
+ assert_select 'select[required]'
29
+ end
30
+
31
+ test 'input does generate select element with aria-required html attribute' do
32
+ with_input_for @user, :country, :country
33
+ assert_select 'select.required'
34
+ assert_select 'select[aria-required]'
35
+ end
36
+ end
@@ -66,6 +66,19 @@ class GroupedCollectionSelectInputTest < ActionView::TestCase
66
66
  end
67
67
  end
68
68
 
69
+ test 'grouped collection allows overriding group_method using a lambda' do
70
+ with_input_for @user, :tag_ids, :grouped_select,
71
+ collection: { Authors: %w[Jose Carlos] },
72
+ group_method: ->(i) { i.last }
73
+
74
+ assert_select 'select.grouped_select#user_tag_ids' do
75
+ assert_select 'optgroup[label=Authors]' do
76
+ assert_select 'option[value=Jose]', 'Jose'
77
+ assert_select 'option[value=Carlos]', 'Carlos'
78
+ end
79
+ end
80
+ end
81
+
69
82
  test 'grouped collection accepts group_label_method option' do
70
83
  with_input_for @user, :tag_ids, :grouped_select,
71
84
  collection: { %w[Jose Carlos] => 'Authors' },
@@ -2,21 +2,7 @@
2
2
  # encoding: UTF-8
3
3
  require 'test_helper'
4
4
 
5
- class PriorityInputTest < ActionView::TestCase
6
- test 'input generates a country select field' do
7
- with_input_for @user, :country, :country
8
- assert_select 'select#user_country'
9
- assert_select 'select option[value=BR]', 'Brazil'
10
- assert_no_select 'select option[value=""][disabled=disabled]'
11
- end
12
-
13
- test 'input generates a country select with SimpleForm default' do
14
- swap SimpleForm, country_priority: [ 'Brazil' ] do
15
- with_input_for @user, :country, :country
16
- assert_select 'select option[value="---------------"][disabled=disabled]'
17
- end
18
- end
19
-
5
+ class TimeZoneInputTest < ActionView::TestCase
20
6
  test 'input generates a time zone select field' do
21
7
  with_input_for @user, :time_zone, :time_zone
22
8
  assert_select 'select#user_time_zone'
@@ -36,14 +22,14 @@ class PriorityInputTest < ActionView::TestCase
36
22
  assert_no_select 'select option[value=""]', /^$/
37
23
  end
38
24
 
39
- test 'priority input does generate select element with required html attribute' do
40
- with_input_for @user, :country, :country
25
+ test 'input does generate select element with required html attribute' do
26
+ with_input_for @user, :time_zone, :time_zone
41
27
  assert_select 'select.required'
42
28
  assert_select 'select[required]'
43
29
  end
44
30
 
45
- test 'priority input does generate select element with aria-required html attribute' do
46
- with_input_for @user, :country, :country
31
+ test 'input does generate select element with aria-required html attribute' do
32
+ with_input_for @user, :time_zone, :time_zone
47
33
  assert_select 'select.required'
48
34
  assert_select 'select[aria-required]'
49
35
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_form
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.0
4
+ version: 5.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - José Valim
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-02-09 00:00:00.000000000 Z
13
+ date: 2023-01-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activemodel
@@ -131,6 +131,7 @@ files:
131
131
  - test/inputs/collection_radio_buttons_input_test.rb
132
132
  - test/inputs/collection_select_input_test.rb
133
133
  - test/inputs/color_input_test.rb
134
+ - test/inputs/country_input_test.rb
134
135
  - test/inputs/datetime_input_test.rb
135
136
  - test/inputs/disabled_test.rb
136
137
  - test/inputs/discovery_test.rb
@@ -139,12 +140,12 @@ files:
139
140
  - test/inputs/grouped_collection_select_input_test.rb
140
141
  - test/inputs/hidden_input_test.rb
141
142
  - test/inputs/numeric_input_test.rb
142
- - test/inputs/priority_input_test.rb
143
143
  - test/inputs/readonly_test.rb
144
144
  - test/inputs/required_test.rb
145
145
  - test/inputs/rich_text_area_input_test.rb
146
146
  - test/inputs/string_input_test.rb
147
147
  - test/inputs/text_input_test.rb
148
+ - test/inputs/time_zone_input_test.rb
148
149
  - test/simple_form_test.rb
149
150
  - test/support/discovery_inputs.rb
150
151
  - test/support/misc_helpers.rb
@@ -154,7 +155,13 @@ files:
154
155
  homepage: https://github.com/heartcombo/simple_form
155
156
  licenses:
156
157
  - MIT
157
- metadata: {}
158
+ metadata:
159
+ homepage_uri: https://github.com/heartcombo/simple_form
160
+ documentation_uri: https://rubydoc.info/github/heartcombo/simple_form
161
+ changelog_uri: https://github.com/heartcombo/simple_form/blob/master/CHANGELOG.md
162
+ source_code_uri: https://github.com/heartcombo/simple_form
163
+ bug_tracker_uri: https://github.com/heartcombo/simple_form/issues
164
+ wiki_uri: https://github.com/heartcombo/simple_form/wiki
158
165
  post_install_message:
159
166
  rdoc_options: []
160
167
  require_paths:
@@ -170,47 +177,48 @@ required_rubygems_version: !ruby/object:Gem::Requirement
170
177
  - !ruby/object:Gem::Version
171
178
  version: '0'
172
179
  requirements: []
173
- rubygems_version: 3.2.6
180
+ rubygems_version: 3.4.5
174
181
  signing_key:
175
182
  specification_version: 4
176
183
  summary: Forms made easy!
177
184
  test_files:
178
- - test/components/label_test.rb
185
+ - test/action_view_extensions/builder_test.rb
186
+ - test/action_view_extensions/form_helper_test.rb
179
187
  - test/components/custom_components_test.rb
180
- - test/support/discovery_inputs.rb
181
- - test/support/misc_helpers.rb
182
- - test/support/mock_controller.rb
183
- - test/support/models.rb
184
- - test/test_helper.rb
185
- - test/form_builder/error_test.rb
186
- - test/form_builder/hint_test.rb
188
+ - test/components/label_test.rb
189
+ - test/form_builder/association_test.rb
190
+ - test/form_builder/button_test.rb
187
191
  - test/form_builder/error_notification_test.rb
192
+ - test/form_builder/error_test.rb
188
193
  - test/form_builder/general_test.rb
189
- - test/form_builder/button_test.rb
194
+ - test/form_builder/hint_test.rb
190
195
  - test/form_builder/input_field_test.rb
191
196
  - test/form_builder/label_test.rb
192
197
  - test/form_builder/wrapper_test.rb
193
- - test/form_builder/association_test.rb
194
198
  - test/generators/simple_form_generator_test.rb
195
- - test/action_view_extensions/builder_test.rb
196
- - test/action_view_extensions/form_helper_test.rb
197
- - test/simple_form_test.rb
198
- - test/inputs/string_input_test.rb
199
- - test/inputs/numeric_input_test.rb
200
- - test/inputs/rich_text_area_input_test.rb
201
- - test/inputs/readonly_test.rb
202
- - test/inputs/grouped_collection_select_input_test.rb
203
- - test/inputs/text_input_test.rb
204
- - test/inputs/collection_check_boxes_input_test.rb
205
199
  - test/inputs/boolean_input_test.rb
200
+ - test/inputs/collection_check_boxes_input_test.rb
201
+ - test/inputs/collection_radio_buttons_input_test.rb
202
+ - test/inputs/collection_select_input_test.rb
203
+ - test/inputs/color_input_test.rb
204
+ - test/inputs/country_input_test.rb
205
+ - test/inputs/datetime_input_test.rb
206
206
  - test/inputs/disabled_test.rb
207
207
  - test/inputs/discovery_test.rb
208
- - test/inputs/collection_select_input_test.rb
208
+ - test/inputs/file_input_test.rb
209
209
  - test/inputs/general_test.rb
210
- - test/inputs/color_input_test.rb
211
- - test/inputs/required_test.rb
212
- - test/inputs/collection_radio_buttons_input_test.rb
213
- - test/inputs/priority_input_test.rb
210
+ - test/inputs/grouped_collection_select_input_test.rb
214
211
  - test/inputs/hidden_input_test.rb
215
- - test/inputs/file_input_test.rb
216
- - test/inputs/datetime_input_test.rb
212
+ - test/inputs/numeric_input_test.rb
213
+ - test/inputs/readonly_test.rb
214
+ - test/inputs/required_test.rb
215
+ - test/inputs/rich_text_area_input_test.rb
216
+ - test/inputs/string_input_test.rb
217
+ - test/inputs/text_input_test.rb
218
+ - test/inputs/time_zone_input_test.rb
219
+ - test/simple_form_test.rb
220
+ - test/support/discovery_inputs.rb
221
+ - test/support/misc_helpers.rb
222
+ - test/support/mock_controller.rb
223
+ - test/support/models.rb
224
+ - test/test_helper.rb