simple_form 3.5.1 → 4.0.0
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 +23 -0
- data/README.md +165 -3
- data/lib/generators/simple_form/templates/README +3 -3
- 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/_form.html.slim +1 -0
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +14 -2
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +357 -73
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +16 -5
- data/lib/simple_form.rb +51 -2
- data/lib/simple_form/components/errors.rb +8 -0
- data/lib/simple_form/components/labels.rb +9 -3
- data/lib/simple_form/components/maxlength.rb +3 -13
- data/lib/simple_form/components/minlength.rb +3 -13
- data/lib/simple_form/components/placeholders.rb +1 -1
- data/lib/simple_form/form_builder.rb +65 -16
- data/lib/simple_form/inputs/base.rb +18 -0
- data/lib/simple_form/version.rb +1 -1
- data/lib/simple_form/wrappers/root.rb +1 -0
- data/test/components/custom_components_test.rb +62 -0
- data/test/components/label_test.rb +28 -0
- data/test/form_builder/general_test.rb +34 -0
- data/test/form_builder/input_field_test.rb +25 -0
- data/test/form_builder/wrapper_test.rb +21 -2
- data/test/support/misc_helpers.rb +14 -0
- data/test/support/models.rb +9 -3
- metadata +4 -14
@@ -249,6 +249,15 @@ class IsolatedLabelTest < ActionView::TestCase
|
|
249
249
|
end
|
250
250
|
end
|
251
251
|
|
252
|
+
test 'label uses custom i18n scope to find required text' do
|
253
|
+
store_translations(:en, my_scope: { required: { text: 'Pflichtfeld' } }) do
|
254
|
+
swap SimpleForm, i18n_scope: :my_scope do
|
255
|
+
with_label_for @user, :name, :string
|
256
|
+
assert_select 'form label abbr[title="Pflichtfeld"]', '*'
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
252
261
|
test 'label uses i18n to find required mark' do
|
253
262
|
store_translations(:en, simple_form: { required: { mark: '*-*' } }) do
|
254
263
|
with_label_for @user, :name, :string
|
@@ -256,6 +265,15 @@ class IsolatedLabelTest < ActionView::TestCase
|
|
256
265
|
end
|
257
266
|
end
|
258
267
|
|
268
|
+
test 'label uses custom i18n scope to find required mark' do
|
269
|
+
store_translations(:en, my_scope: { required: { mark: '!!' } }) do
|
270
|
+
swap SimpleForm, i18n_scope: :my_scope do
|
271
|
+
with_label_for @user, :name, :string
|
272
|
+
assert_select 'form label abbr', '!!'
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
259
277
|
test 'label uses i18n to find required string tag' do
|
260
278
|
store_translations(:en, simple_form: { required: { html: '<span class="required" title="requerido">*</span>' } }) do
|
261
279
|
with_label_for @user, :name, :string
|
@@ -264,6 +282,16 @@ class IsolatedLabelTest < ActionView::TestCase
|
|
264
282
|
end
|
265
283
|
end
|
266
284
|
|
285
|
+
test 'label uses custom i18n scope to find required string tag' do
|
286
|
+
store_translations(:en, my_scope: { required: { html: '<span class="mandatory" title="Pflichtfeld">!!</span>' } }) do
|
287
|
+
swap SimpleForm, i18n_scope: :my_scope do
|
288
|
+
with_label_for @user, :name, :string
|
289
|
+
assert_no_select 'form label abbr'
|
290
|
+
assert_select 'form label span.mandatory[title=Pflichtfeld]', '!!'
|
291
|
+
end
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
267
295
|
test 'label allows overwriting input id' do
|
268
296
|
with_label_for @user, :name, :string, input_html: { id: 'my_new_id' }
|
269
297
|
assert_select 'label[for=my_new_id]'
|
@@ -142,6 +142,24 @@ class FormBuilderTest < ActionView::TestCase
|
|
142
142
|
assert_select 'form input#user_description.string'
|
143
143
|
end
|
144
144
|
|
145
|
+
test 'builder generates text areas for hstore columns' do
|
146
|
+
with_form_for @user, :hstore
|
147
|
+
assert_no_select 'form input#user_hstore.string'
|
148
|
+
assert_select 'form textarea#user_hstore.text'
|
149
|
+
end
|
150
|
+
|
151
|
+
test 'builder generates text areas for json columns' do
|
152
|
+
with_form_for @user, :json
|
153
|
+
assert_no_select 'form input#user_json.string'
|
154
|
+
assert_select 'form textarea#user_json.text'
|
155
|
+
end
|
156
|
+
|
157
|
+
test 'builder generates text areas for jsonb columns' do
|
158
|
+
with_form_for @user, :jsonb
|
159
|
+
assert_no_select 'form input#user_jsonb.string'
|
160
|
+
assert_select 'form textarea#user_jsonb.text'
|
161
|
+
end
|
162
|
+
|
145
163
|
test 'builder generates a checkbox for boolean columns' do
|
146
164
|
with_form_for @user, :active
|
147
165
|
assert_select 'form input[type=checkbox]#user_active.boolean'
|
@@ -166,6 +184,11 @@ class FormBuilderTest < ActionView::TestCase
|
|
166
184
|
end
|
167
185
|
end
|
168
186
|
|
187
|
+
test 'builder generates string fields for citext columns' do
|
188
|
+
with_form_for @user, :citext
|
189
|
+
assert_select 'form input#user_citext.string'
|
190
|
+
end
|
191
|
+
|
169
192
|
test 'builder generates password fields for columns that matches password' do
|
170
193
|
with_form_for @user, :password
|
171
194
|
assert_select 'form input#user_password.password'
|
@@ -219,6 +242,16 @@ class FormBuilderTest < ActionView::TestCase
|
|
219
242
|
test 'builder generates file for file columns' do
|
220
243
|
@user.avatar = MiniTest::Mock.new
|
221
244
|
@user.avatar.expect(:public_filename, true)
|
245
|
+
@user.avatar.expect(:!, false)
|
246
|
+
|
247
|
+
with_form_for @user, :avatar
|
248
|
+
assert_select 'form input#user_avatar.file'
|
249
|
+
end
|
250
|
+
|
251
|
+
test 'builder generates file for activestorage entries' do
|
252
|
+
@user.avatar = MiniTest::Mock.new
|
253
|
+
@user.avatar.expect(:attached?, false)
|
254
|
+
@user.avatar.expect(:!, false)
|
222
255
|
|
223
256
|
with_form_for @user, :avatar
|
224
257
|
assert_select 'form input#user_avatar.file'
|
@@ -227,6 +260,7 @@ class FormBuilderTest < ActionView::TestCase
|
|
227
260
|
test 'builder generates file for attributes that are real db columns but have file methods' do
|
228
261
|
@user.home_picture = MiniTest::Mock.new
|
229
262
|
@user.home_picture.expect(:mounted_as, true)
|
263
|
+
@user.home_picture.expect(:!, false)
|
230
264
|
|
231
265
|
with_form_for @user, :home_picture
|
232
266
|
assert_select 'form input#user_home_picture.file'
|
@@ -173,4 +173,29 @@ class InputFieldTest < ActionView::TestCase
|
|
173
173
|
assert_select 'input[readonly="readonly"]'
|
174
174
|
end
|
175
175
|
end
|
176
|
+
|
177
|
+
test 'adds valid class to input_field when it is configured' do
|
178
|
+
swap SimpleForm, input_field_valid_class: 'is-valid' do
|
179
|
+
@user.instance_eval { undef errors }
|
180
|
+
with_input_field_for @user, :name
|
181
|
+
|
182
|
+
assert_select 'input.string.required.is-valid'
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
test 'adds error class to input_field when it is configured' do
|
187
|
+
swap SimpleForm, input_field_error_class: 'is-invalid' do
|
188
|
+
with_input_field_for @user, :name
|
189
|
+
|
190
|
+
assert_select 'input.string.required.is-invalid'
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
test 'does not add validation classes to input_field when it is not configured' do
|
195
|
+
swap SimpleForm, input_field_error_class: nil, input_field_valid_class: nil do
|
196
|
+
with_input_field_for @user, :name
|
197
|
+
|
198
|
+
assert_select 'input.string.required'
|
199
|
+
end
|
200
|
+
end
|
176
201
|
end
|
@@ -38,6 +38,27 @@ class WrapperTest < ActionView::TestCase
|
|
38
38
|
assert_select 'div.field_with_errors'
|
39
39
|
end
|
40
40
|
|
41
|
+
test 'wrapper adds error class to input for attribute with errors' do
|
42
|
+
with_form_for @user, :name, wrapper: custom_wrapper_with_input_error_class
|
43
|
+
assert_select 'div.field_with_errors'
|
44
|
+
assert_select 'input.is-invalid'
|
45
|
+
end
|
46
|
+
|
47
|
+
test 'wrapper does not add error class to input when the attribute is valid' do
|
48
|
+
with_form_for @user, :phone_number, wrapper: custom_wrapper_with_input_error_class
|
49
|
+
assert_no_select 'div.field_with_errors'
|
50
|
+
assert_no_select 'input.is-invalid'
|
51
|
+
end
|
52
|
+
|
53
|
+
test 'wrapper adds valid class for present attribute without errors' do
|
54
|
+
@user.instance_eval { undef errors }
|
55
|
+
with_form_for @user, :name, wrapper: custom_wrapper_with_input_valid_class
|
56
|
+
assert_select 'div.field_without_errors'
|
57
|
+
assert_select 'input.is-valid'
|
58
|
+
assert_no_select 'div.field_with_errors'
|
59
|
+
assert_no_select 'input.is-invalid'
|
60
|
+
end
|
61
|
+
|
41
62
|
test 'wrapper adds hint class for attribute with a hint' do
|
42
63
|
with_form_for @user, :name, hint: 'hint'
|
43
64
|
assert_select 'div.field_with_hint'
|
@@ -264,8 +285,6 @@ class WrapperTest < ActionView::TestCase
|
|
264
285
|
end
|
265
286
|
|
266
287
|
test "input with aria attributes will merge with wrapper_options' aria" do
|
267
|
-
skip unless ActionPack::VERSION::MAJOR == '4' && ActionPack::VERSION::MINOR >= '2'
|
268
|
-
|
269
288
|
swap_wrapper :default, custom_wrapper_with_input_aria_modal do
|
270
289
|
with_concat_form_for @user do |f|
|
271
290
|
concat f.input :name, input_html: { aria: { modal: 'another-aria', target: 'merge-aria' } }
|
@@ -206,6 +206,20 @@ module MiscHelpers
|
|
206
206
|
end
|
207
207
|
end
|
208
208
|
|
209
|
+
def custom_wrapper_with_input_error_class
|
210
|
+
SimpleForm.build tag: :div, class: "custom_wrapper", error_class: :field_with_errors do |b|
|
211
|
+
b.use :label
|
212
|
+
b.use :input, class: 'inline-class', error_class: 'is-invalid'
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
def custom_wrapper_with_input_valid_class
|
217
|
+
SimpleForm.build tag: :div, class: "custom_wrapper", valid_class: :field_without_errors do |b|
|
218
|
+
b.use :label
|
219
|
+
b.use :input, class: 'inline-class', valid_class: 'is-valid'
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
209
223
|
def custom_form_for(object, *args, &block)
|
210
224
|
simple_form_for(object, *args, { builder: CustomFormBuilder }, &block)
|
211
225
|
end
|
data/test/support/models.rb
CHANGED
@@ -90,7 +90,8 @@ class User
|
|
90
90
|
:avatar, :home_picture, :email, :status, :residence_country, :phone_number,
|
91
91
|
:post_count, :lock_version, :amount, :attempts, :action, :credit_card, :gender,
|
92
92
|
:extra_special_company_id, :pictures, :picture_ids, :special_pictures,
|
93
|
-
:special_picture_ids, :uuid, :friends, :friend_ids, :special_tags, :special_tag_ids
|
93
|
+
:special_picture_ids, :uuid, :friends, :friend_ids, :special_tags, :special_tag_ids,
|
94
|
+
:citext, :hstore, :json, :jsonb
|
94
95
|
|
95
96
|
def self.build(extra_attributes = {})
|
96
97
|
attributes = {
|
@@ -141,7 +142,7 @@ class User
|
|
141
142
|
when :attempts then :integer
|
142
143
|
when :action then :string
|
143
144
|
when :credit_card then :string
|
144
|
-
|
145
|
+
else attribute.to_sym
|
145
146
|
end
|
146
147
|
Column.new(attribute, column_type, limit)
|
147
148
|
end
|
@@ -175,6 +176,10 @@ class User
|
|
175
176
|
when 'action' then :string
|
176
177
|
when 'credit_card' then :string
|
177
178
|
when 'uuid' then :string
|
179
|
+
when 'citext' then :string
|
180
|
+
when 'hstore' then [:text, 200]
|
181
|
+
when 'json' then [:text, 200]
|
182
|
+
when 'jsonb' then [:text, 200]
|
178
183
|
end
|
179
184
|
|
180
185
|
ActiveModel::Type.lookup(column_type, limit: limit)
|
@@ -187,7 +192,8 @@ class User
|
|
187
192
|
when :name, :status, :password, :description, :age,
|
188
193
|
:credit_limit, :active, :born_at, :delivery_time,
|
189
194
|
:created_at, :updated_at, :lock_version, :home_picture,
|
190
|
-
:amount, :attempts, :action, :credit_card, :uuid
|
195
|
+
:amount, :attempts, :action, :credit_card, :uuid,
|
196
|
+
:citext, :hstore, :json, :jsonb then true
|
191
197
|
else false
|
192
198
|
end
|
193
199
|
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:
|
4
|
+
version: 4.0.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: 2018-
|
13
|
+
date: 2018-04-11 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activemodel
|
@@ -19,9 +19,6 @@ dependencies:
|
|
19
19
|
- - ">"
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: '4'
|
22
|
-
- - "<"
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version: '5.2'
|
25
22
|
type: :runtime
|
26
23
|
prerelease: false
|
27
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,9 +26,6 @@ dependencies:
|
|
29
26
|
- - ">"
|
30
27
|
- !ruby/object:Gem::Version
|
31
28
|
version: '4'
|
32
|
-
- - "<"
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: '5.2'
|
35
29
|
- !ruby/object:Gem::Dependency
|
36
30
|
name: actionpack
|
37
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,9 +33,6 @@ dependencies:
|
|
39
33
|
- - ">"
|
40
34
|
- !ruby/object:Gem::Version
|
41
35
|
version: '4'
|
42
|
-
- - "<"
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
version: '5.2'
|
45
36
|
type: :runtime
|
46
37
|
prerelease: false
|
47
38
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -49,9 +40,6 @@ dependencies:
|
|
49
40
|
- - ">"
|
50
41
|
- !ruby/object:Gem::Version
|
51
42
|
version: '4'
|
52
|
-
- - "<"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '5.2'
|
55
43
|
description: Forms made easy!
|
56
44
|
email: opensource@plataformatec.com.br
|
57
45
|
executables: []
|
@@ -125,6 +113,7 @@ files:
|
|
125
113
|
- lib/simple_form/wrappers/single.rb
|
126
114
|
- test/action_view_extensions/builder_test.rb
|
127
115
|
- test/action_view_extensions/form_helper_test.rb
|
116
|
+
- test/components/custom_components_test.rb
|
128
117
|
- test/components/label_test.rb
|
129
118
|
- test/form_builder/association_test.rb
|
130
119
|
- test/form_builder/button_test.rb
|
@@ -186,6 +175,7 @@ summary: Forms made easy!
|
|
186
175
|
test_files:
|
187
176
|
- test/action_view_extensions/builder_test.rb
|
188
177
|
- test/action_view_extensions/form_helper_test.rb
|
178
|
+
- test/components/custom_components_test.rb
|
189
179
|
- test/components/label_test.rb
|
190
180
|
- test/form_builder/association_test.rb
|
191
181
|
- test/form_builder/button_test.rb
|