simple_form 2.0.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 +7 -0
- data/CHANGELOG.md +97 -198
- data/MIT-LICENSE +1 -1
- data/README.md +572 -296
- data/lib/generators/simple_form/install_generator.rb +17 -7
- data/lib/generators/simple_form/templates/README +3 -4
- 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.tt → simple_form.rb} +57 -63
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +155 -0
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +111 -0
- data/lib/generators/simple_form/templates/config/locales/simple_form.en.yml +14 -7
- data/lib/simple_form/action_view_extensions/builder.rb +5 -305
- data/lib/simple_form/action_view_extensions/form_helper.rb +18 -20
- data/lib/simple_form/components/errors.rb +30 -3
- data/lib/simple_form/components/hints.rb +10 -3
- data/lib/simple_form/components/html5.rb +17 -3
- data/lib/simple_form/components/label_input.rb +21 -2
- data/lib/simple_form/components/labels.rb +16 -11
- data/lib/simple_form/components/maxlength.rb +19 -12
- data/lib/simple_form/components/min_max.rb +4 -2
- data/lib/simple_form/components/minlength.rb +48 -0
- data/lib/simple_form/components/pattern.rb +5 -4
- data/lib/simple_form/components/placeholders.rb +3 -2
- data/lib/simple_form/components/readonly.rb +3 -2
- data/lib/simple_form/components.rb +15 -11
- data/lib/simple_form/error_notification.rb +4 -3
- data/lib/simple_form/form_builder.rb +283 -105
- 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 +4 -3
- data/lib/simple_form/helpers.rb +7 -6
- data/lib/simple_form/i18n_cache.rb +1 -0
- data/lib/simple_form/inputs/base.rb +76 -23
- data/lib/simple_form/inputs/block_input.rb +3 -2
- data/lib/simple_form/inputs/boolean_input.rb +55 -16
- data/lib/simple_form/inputs/collection_check_boxes_input.rb +2 -1
- data/lib/simple_form/inputs/collection_input.rb +41 -18
- data/lib/simple_form/inputs/collection_radio_buttons_input.rb +11 -19
- data/lib/simple_form/inputs/collection_select_input.rb +5 -2
- data/lib/simple_form/inputs/date_time_input.rb +23 -12
- data/lib/simple_form/inputs/file_input.rb +5 -2
- data/lib/simple_form/inputs/grouped_collection_select_input.rb +16 -3
- data/lib/simple_form/inputs/hidden_input.rb +5 -2
- data/lib/simple_form/inputs/numeric_input.rb +4 -8
- data/lib/simple_form/inputs/password_input.rb +6 -4
- data/lib/simple_form/inputs/priority_input.rb +5 -2
- data/lib/simple_form/inputs/range_input.rb +2 -1
- data/lib/simple_form/inputs/string_input.rb +6 -4
- data/lib/simple_form/inputs/text_input.rb +6 -3
- data/lib/simple_form/inputs.rb +20 -17
- data/lib/simple_form/map_type.rb +1 -0
- data/lib/simple_form/railtie.rb +15 -0
- data/lib/simple_form/tags.rb +69 -0
- data/lib/simple_form/version.rb +2 -1
- data/lib/simple_form/wrappers/builder.rb +12 -35
- data/lib/simple_form/wrappers/leaf.rb +29 -0
- data/lib/simple_form/wrappers/many.rb +12 -7
- data/lib/simple_form/wrappers/root.rb +7 -4
- data/lib/simple_form/wrappers/single.rb +12 -3
- data/lib/simple_form/wrappers.rb +3 -1
- data/lib/simple_form.rb +118 -63
- data/test/action_view_extensions/builder_test.rb +230 -164
- data/test/action_view_extensions/form_helper_test.rb +107 -39
- data/test/components/label_test.rb +105 -87
- data/test/form_builder/association_test.rb +131 -62
- data/test/form_builder/button_test.rb +15 -14
- data/test/form_builder/error_notification_test.rb +11 -10
- data/test/form_builder/error_test.rb +188 -34
- data/test/form_builder/general_test.rb +247 -102
- data/test/form_builder/hint_test.rb +59 -32
- data/test/form_builder/input_field_test.rb +138 -25
- data/test/form_builder/label_test.rb +84 -13
- data/test/form_builder/wrapper_test.rb +236 -33
- data/test/generators/simple_form_generator_test.rb +15 -4
- data/test/inputs/boolean_input_test.rb +147 -13
- data/test/inputs/collection_check_boxes_input_test.rb +166 -71
- data/test/inputs/collection_radio_buttons_input_test.rb +229 -113
- data/test/inputs/collection_select_input_test.rb +222 -85
- data/test/inputs/datetime_input_test.rb +134 -47
- data/test/inputs/disabled_test.rb +62 -21
- data/test/inputs/discovery_test.rb +70 -10
- data/test/inputs/file_input_test.rb +4 -3
- data/test/inputs/general_test.rb +90 -26
- data/test/inputs/grouped_collection_select_input_test.rb +88 -23
- data/test/inputs/hidden_input_test.rb +7 -5
- data/test/inputs/numeric_input_test.rb +56 -46
- data/test/inputs/priority_input_test.rb +31 -16
- data/test/inputs/readonly_test.rb +68 -27
- data/test/inputs/required_test.rb +63 -18
- data/test/inputs/string_input_test.rb +76 -51
- data/test/inputs/text_input_test.rb +21 -8
- data/test/simple_form_test.rb +9 -0
- data/test/support/discovery_inputs.rb +39 -2
- data/test/support/misc_helpers.rb +176 -20
- data/test/support/mock_controller.rb +13 -7
- data/test/support/models.rb +187 -71
- data/test/test_helper.rb +38 -39
- metadata +53 -39
- data/lib/simple_form/core_ext/hash.rb +0 -16
- data/test/support/mock_response.rb +0 -14
|
@@ -1,44 +1,77 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
require 'test_helper'
|
|
2
3
|
|
|
3
4
|
class RequiredTest < ActionView::TestCase
|
|
4
5
|
# REQUIRED AND PRESENCE VALIDATION
|
|
5
|
-
test 'builder input
|
|
6
|
+
test 'builder input obtains required from ActiveModel::Validations when it is included' do
|
|
6
7
|
with_form_for @validating_user, :name
|
|
7
8
|
assert_select 'input.required[required]#validating_user_name'
|
|
8
9
|
with_form_for @validating_user, :status
|
|
9
10
|
assert_select 'input.optional#validating_user_status'
|
|
10
11
|
end
|
|
11
12
|
|
|
12
|
-
test 'builder input
|
|
13
|
-
with_form_for @validating_user, :name, :
|
|
13
|
+
test 'builder input allows overriding required when ActiveModel::Validations is included' do
|
|
14
|
+
with_form_for @validating_user, :name, required: false
|
|
14
15
|
assert_select 'input.optional#validating_user_name'
|
|
15
|
-
with_form_for @validating_user, :status, :
|
|
16
|
+
with_form_for @validating_user, :status, required: true
|
|
16
17
|
assert_select 'input.required[required]#validating_user_status'
|
|
17
18
|
end
|
|
18
19
|
|
|
19
|
-
test 'builder input
|
|
20
|
+
test 'builder input is required by default when ActiveModel::Validations is not included' do
|
|
20
21
|
with_form_for @user, :name
|
|
21
22
|
assert_select 'input.required[required]#user_name'
|
|
22
23
|
end
|
|
23
24
|
|
|
24
|
-
test 'builder input
|
|
25
|
-
swap SimpleForm, :
|
|
25
|
+
test 'builder input does not be required by default when ActiveModel::Validations is not included if option is set to false' do
|
|
26
|
+
swap SimpleForm, required_by_default: false do
|
|
26
27
|
with_form_for @user, :name
|
|
27
28
|
assert_select 'input.optional#user_name'
|
|
28
29
|
assert_no_select 'input[required]'
|
|
29
30
|
end
|
|
30
31
|
end
|
|
31
32
|
|
|
32
|
-
test 'when not using browser validations, input
|
|
33
|
-
swap SimpleForm, :
|
|
33
|
+
test 'when not using browser validations, input does not generate required html attribute' do
|
|
34
|
+
swap SimpleForm, browser_validations: false do
|
|
34
35
|
with_input_for @user, :name, :string
|
|
35
36
|
assert_select 'input[type=text].required'
|
|
36
37
|
assert_no_select 'input[type=text][required]'
|
|
38
|
+
assert_no_select 'input[type=text][aria-required]'
|
|
37
39
|
end
|
|
38
40
|
end
|
|
39
41
|
|
|
40
|
-
test '
|
|
41
|
-
|
|
42
|
+
test 'when not using browser validations, when required option is set to false, input does not generate required html attribute' do
|
|
43
|
+
swap SimpleForm, browser_validations: false do
|
|
44
|
+
with_input_for @user, :name, :string, required: false
|
|
45
|
+
assert_no_select 'input[type=text].required'
|
|
46
|
+
assert_no_select 'input[type=text][required]'
|
|
47
|
+
assert_no_select 'input[type=text][aria-required]'
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
test 'when not using browser validations, when required option is set to true, input generates required html attribute' do
|
|
52
|
+
swap SimpleForm, browser_validations: false do
|
|
53
|
+
with_input_for @user, :name, :string, required: true
|
|
54
|
+
assert_select 'input[type=text].required'
|
|
55
|
+
assert_select 'input[type=text][required]'
|
|
56
|
+
assert_select 'input[type=text][aria-required]'
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
test 'when not using browser validations, when required option is true in the wrapper, input does not generate required html attribute' do
|
|
61
|
+
swap SimpleForm, browser_validations: false do
|
|
62
|
+
swap_wrapper :default, self.custom_wrapper_with_required_input do
|
|
63
|
+
with_concat_form_for(@user) do |f|
|
|
64
|
+
concat f.input :name
|
|
65
|
+
end
|
|
66
|
+
assert_select 'input[type=text].required'
|
|
67
|
+
assert_no_select 'input[type=text][required]'
|
|
68
|
+
assert_no_select 'input[type=text][aria-required]'
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
test 'builder input allows disabling required when ActiveModel::Validations is not included' do
|
|
74
|
+
with_form_for @user, :name, required: false
|
|
42
75
|
assert_no_select 'input.required'
|
|
43
76
|
assert_no_select 'input[required]'
|
|
44
77
|
assert_select 'input.optional#user_name'
|
|
@@ -53,14 +86,14 @@ class RequiredTest < ActionView::TestCase
|
|
|
53
86
|
end
|
|
54
87
|
|
|
55
88
|
# VALIDATORS :if :unless
|
|
56
|
-
test 'builder input
|
|
89
|
+
test 'builder input does not be required when ActiveModel::Validations is included and if option is present' do
|
|
57
90
|
with_form_for @validating_user, :age
|
|
58
91
|
assert_no_select 'input.required'
|
|
59
92
|
assert_no_select 'input[required]'
|
|
60
93
|
assert_select 'input.optional#validating_user_age'
|
|
61
94
|
end
|
|
62
95
|
|
|
63
|
-
test 'builder input
|
|
96
|
+
test 'builder input does not be required when ActiveModel::Validations is included and unless option is present' do
|
|
64
97
|
with_form_for @validating_user, :amount
|
|
65
98
|
assert_no_select 'input.required'
|
|
66
99
|
assert_no_select 'input[required]'
|
|
@@ -68,7 +101,7 @@ class RequiredTest < ActionView::TestCase
|
|
|
68
101
|
end
|
|
69
102
|
|
|
70
103
|
# VALIDATORS :on
|
|
71
|
-
test 'builder input
|
|
104
|
+
test 'builder input is required when validation is on create and is not persisted' do
|
|
72
105
|
@validating_user.new_record!
|
|
73
106
|
with_form_for @validating_user, :action
|
|
74
107
|
assert_select 'input.required'
|
|
@@ -76,14 +109,14 @@ class RequiredTest < ActionView::TestCase
|
|
|
76
109
|
assert_select 'input.required[required]#validating_user_action'
|
|
77
110
|
end
|
|
78
111
|
|
|
79
|
-
test 'builder input
|
|
112
|
+
test 'builder input does not be required when validation is on create and is persisted' do
|
|
80
113
|
with_form_for @validating_user, :action
|
|
81
114
|
assert_no_select 'input.required'
|
|
82
115
|
assert_no_select 'input[required]'
|
|
83
116
|
assert_select 'input.optional#validating_user_action'
|
|
84
117
|
end
|
|
85
118
|
|
|
86
|
-
test 'builder input
|
|
119
|
+
test 'builder input is required when validation is on save' do
|
|
87
120
|
with_form_for @validating_user, :credit_limit
|
|
88
121
|
assert_select 'input.required'
|
|
89
122
|
assert_select 'input[required]'
|
|
@@ -96,18 +129,30 @@ class RequiredTest < ActionView::TestCase
|
|
|
96
129
|
assert_select 'input.required[required]#validating_user_credit_limit'
|
|
97
130
|
end
|
|
98
131
|
|
|
99
|
-
test 'builder input
|
|
132
|
+
test 'builder input is required when validation is on update and is persisted' do
|
|
100
133
|
with_form_for @validating_user, :phone_number
|
|
101
134
|
assert_select 'input.required'
|
|
102
135
|
assert_select 'input[required]'
|
|
103
136
|
assert_select 'input.required[required]#validating_user_phone_number'
|
|
104
137
|
end
|
|
105
138
|
|
|
106
|
-
test 'builder input
|
|
139
|
+
test 'builder input does not be required when validation is on update and is not persisted' do
|
|
107
140
|
@validating_user.new_record!
|
|
108
141
|
with_form_for @validating_user, :phone_number
|
|
109
142
|
assert_no_select 'input.required'
|
|
110
143
|
assert_no_select 'input[required]'
|
|
111
144
|
assert_select 'input.optional#validating_user_phone_number'
|
|
112
145
|
end
|
|
146
|
+
|
|
147
|
+
test 'builder input does not generate required html attribute when option is set to false when it is set to true in wrapper' do
|
|
148
|
+
swap SimpleForm, browser_validations: true do
|
|
149
|
+
swap_wrapper :default, self.custom_wrapper_with_required_input do
|
|
150
|
+
with_concat_form_for(@user) do |f|
|
|
151
|
+
concat f.input :name, required: false
|
|
152
|
+
end
|
|
153
|
+
assert_no_select 'input[type=text][required]'
|
|
154
|
+
assert_no_select 'input[type=text][aria-required]'
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
end
|
|
113
158
|
end
|
|
@@ -1,121 +1,146 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
# encoding: UTF-8
|
|
2
3
|
require 'test_helper'
|
|
3
4
|
|
|
4
5
|
class StringInputTest < ActionView::TestCase
|
|
5
|
-
test 'input
|
|
6
|
+
test 'input maps text field to string attribute' do
|
|
6
7
|
with_input_for @user, :name, :string
|
|
7
|
-
assert_select "input#user_name[type=text][name='user[name]'][value=New in SimpleForm!]"
|
|
8
|
+
assert_select "input#user_name[type=text][name='user[name]'][value='New in SimpleForm!']"
|
|
8
9
|
end
|
|
9
10
|
|
|
10
|
-
test 'input
|
|
11
|
+
test 'input generates a password field for password attributes' do
|
|
11
12
|
with_input_for @user, :password, :password
|
|
12
13
|
assert_select "input#user_password.password[type=password][name='user[password]']"
|
|
13
14
|
end
|
|
14
15
|
|
|
15
|
-
test 'input
|
|
16
|
-
with_input_for @user, :credit_limit, :decimal
|
|
17
|
-
assert_no_select 'input.decimal[size]'
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
test 'input should get maxlength from column definition for string attributes' do
|
|
16
|
+
test 'input gets maxlength from column definition for string attributes' do
|
|
21
17
|
with_input_for @user, :name, :string
|
|
22
|
-
assert_select 'input.string[maxlength=100]'
|
|
18
|
+
assert_select 'input.string[maxlength="100"]'
|
|
23
19
|
end
|
|
24
20
|
|
|
25
|
-
test 'input
|
|
21
|
+
test 'input does not get maxlength from column without size definition for string attributes' do
|
|
26
22
|
with_input_for @user, :action, :string
|
|
27
23
|
assert_no_select 'input.string[maxlength]'
|
|
28
24
|
end
|
|
29
25
|
|
|
30
|
-
test 'input
|
|
31
|
-
with_input_for @user, :name, :string
|
|
32
|
-
assert_select 'input.string[size=50]'
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
test 'input should use default text size for password attributes' do
|
|
26
|
+
test 'input gets maxlength from column definition for password attributes' do
|
|
36
27
|
with_input_for @user, :password, :password
|
|
37
|
-
assert_select 'input.password[type=password][
|
|
28
|
+
assert_select 'input.password[type=password][maxlength="100"]'
|
|
38
29
|
end
|
|
39
30
|
|
|
40
|
-
test 'input
|
|
41
|
-
with_input_for @
|
|
42
|
-
assert_select 'input.
|
|
31
|
+
test 'input infers maxlength column definition from validation when present' do
|
|
32
|
+
with_input_for @validating_user, :name, :string
|
|
33
|
+
assert_select 'input.string[maxlength="25"]'
|
|
43
34
|
end
|
|
44
35
|
|
|
45
|
-
test 'input
|
|
36
|
+
test 'input infers minlength column definition from validation when present' do
|
|
46
37
|
with_input_for @validating_user, :name, :string
|
|
47
|
-
assert_select 'input.string[
|
|
38
|
+
assert_select 'input.string[minlength="5"]'
|
|
48
39
|
end
|
|
49
40
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
41
|
+
if ActionPack::VERSION::STRING < '5'
|
|
42
|
+
test 'input does not get maxlength from validation when tokenizer present' do
|
|
43
|
+
with_input_for @validating_user, :action, :string
|
|
44
|
+
assert_no_select 'input.string[maxlength]'
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
test 'input does not get minlength from validation when tokenizer present' do
|
|
48
|
+
with_input_for @validating_user, :action, :string
|
|
49
|
+
assert_no_select 'input.string[minlength]'
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
test 'input gets maxlength from validation when :is option present' do
|
|
54
|
+
with_input_for @validating_user, :home_picture, :string
|
|
55
|
+
assert_select 'input.string[maxlength="12"]'
|
|
53
56
|
end
|
|
54
57
|
|
|
55
|
-
test 'input
|
|
58
|
+
test 'input gets minlength from validation when :is option present' do
|
|
56
59
|
with_input_for @validating_user, :home_picture, :string
|
|
57
|
-
assert_select 'input.string[
|
|
60
|
+
assert_select 'input.string[minlength="12"]'
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
test 'input maxlength is the column limit plus one to make room for decimal point' do
|
|
64
|
+
with_input_for @user, :credit_limit, :string
|
|
65
|
+
|
|
66
|
+
assert_select 'input.string[maxlength="16"]'
|
|
58
67
|
end
|
|
59
68
|
|
|
60
|
-
test 'input
|
|
69
|
+
test 'input does not generate placeholder by default' do
|
|
61
70
|
with_input_for @user, :name, :string
|
|
62
71
|
assert_no_select 'input[placeholder]'
|
|
63
72
|
end
|
|
64
73
|
|
|
65
|
-
test 'input
|
|
66
|
-
with_input_for @user, :name, :string, :
|
|
67
|
-
assert_select 'input.string[placeholder=Put in some text]'
|
|
74
|
+
test 'input accepts the placeholder option' do
|
|
75
|
+
with_input_for @user, :name, :string, placeholder: 'Put in some text'
|
|
76
|
+
assert_select 'input.string[placeholder="Put in some text"]'
|
|
68
77
|
end
|
|
69
78
|
|
|
70
|
-
test 'input
|
|
71
|
-
with_input_for @user, :password, :password, :
|
|
72
|
-
assert_select 'input[type=password].password[placeholder=Password Confirmation]#user_password'
|
|
79
|
+
test 'input generates a password field for password attributes that accept placeholder' do
|
|
80
|
+
with_input_for @user, :password, :password, placeholder: 'Password Confirmation'
|
|
81
|
+
assert_select 'input[type=password].password[placeholder="Password Confirmation"]#user_password'
|
|
73
82
|
end
|
|
74
83
|
|
|
75
|
-
test 'input
|
|
84
|
+
test 'input does not infer pattern from attributes by default' do
|
|
76
85
|
with_input_for @other_validating_user, :country, :string
|
|
77
86
|
assert_no_select 'input[pattern="\w+"]'
|
|
78
87
|
end
|
|
79
88
|
|
|
80
|
-
test 'input
|
|
81
|
-
with_input_for @other_validating_user, :country, :string, :
|
|
89
|
+
test 'input infers pattern from attributes' do
|
|
90
|
+
with_input_for @other_validating_user, :country, :string, pattern: true
|
|
82
91
|
assert_select 'input[pattern="\w+"]'
|
|
83
92
|
end
|
|
84
93
|
|
|
85
|
-
test 'input
|
|
86
|
-
with_input_for @other_validating_user, :name, :string, :
|
|
94
|
+
test 'input infers pattern from attributes using proc' do
|
|
95
|
+
with_input_for @other_validating_user, :name, :string, pattern: true
|
|
87
96
|
assert_select 'input[pattern="\w+"]'
|
|
88
97
|
end
|
|
89
98
|
|
|
90
|
-
test 'input
|
|
99
|
+
test 'input does not infer pattern from attributes if root default is false' do
|
|
91
100
|
swap_wrapper do
|
|
92
101
|
with_input_for @other_validating_user, :country, :string
|
|
93
102
|
assert_no_select 'input[pattern="\w+"]'
|
|
94
103
|
end
|
|
95
104
|
end
|
|
96
105
|
|
|
97
|
-
test 'input
|
|
98
|
-
with_input_for @other_validating_user, :country, :string, :
|
|
106
|
+
test 'input uses given pattern from attributes' do
|
|
107
|
+
with_input_for @other_validating_user, :country, :string, input_html: { pattern: "\\d+" }
|
|
99
108
|
assert_select 'input[pattern="\d+"]'
|
|
100
109
|
end
|
|
101
110
|
|
|
102
|
-
test 'input
|
|
103
|
-
|
|
104
|
-
|
|
111
|
+
test 'input does not use pattern if model has :without validation option' do
|
|
112
|
+
with_input_for @other_validating_user, :description, :string, pattern: true
|
|
113
|
+
assert_no_select 'input[pattern="\d+"]'
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
test 'input uses i18n to translate placeholder text' do
|
|
117
|
+
store_translations(:en, simple_form: { placeholders: { user: {
|
|
118
|
+
name: 'Name goes here'
|
|
105
119
|
} } }) do
|
|
106
120
|
with_input_for @user, :name, :string
|
|
107
|
-
assert_select 'input.string[placeholder=Name goes here]'
|
|
121
|
+
assert_select 'input.string[placeholder="Name goes here"]'
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
test 'input uses custom i18n scope to translate placeholder text' do
|
|
126
|
+
store_translations(:en, my_scope: { placeholders: { user: {
|
|
127
|
+
name: 'Name goes here'
|
|
128
|
+
} } }) do
|
|
129
|
+
swap SimpleForm, i18n_scope: :my_scope do
|
|
130
|
+
with_input_for @user, :name, :string
|
|
131
|
+
assert_select 'input.string[placeholder="Name goes here"]'
|
|
132
|
+
end
|
|
108
133
|
end
|
|
109
134
|
end
|
|
110
135
|
|
|
111
|
-
[
|
|
112
|
-
test "input
|
|
136
|
+
%i[email url search tel].each do |type|
|
|
137
|
+
test "input allows type #{type}" do
|
|
113
138
|
with_input_for @user, :name, type
|
|
114
139
|
assert_select "input.string.#{type}"
|
|
115
140
|
assert_select "input[type=#{type}]"
|
|
116
141
|
end
|
|
117
142
|
|
|
118
|
-
test "input
|
|
143
|
+
test "input does not allow type #{type} if HTML5 compatibility is disabled" do
|
|
119
144
|
swap_wrapper do
|
|
120
145
|
with_input_for @user, :name, type
|
|
121
146
|
assert_select "input[type=text]"
|
|
@@ -132,7 +157,7 @@ class StringInputTest < ActionView::TestCase
|
|
|
132
157
|
end
|
|
133
158
|
|
|
134
159
|
test 'input strips extra spaces from class html attribute when giving a custom class' do
|
|
135
|
-
with_input_for @user, :name, :string, :
|
|
160
|
+
with_input_for @user, :name, :string, input_html: { class: "my_input" }
|
|
136
161
|
assert_select "input[class='string required my_input']"
|
|
137
162
|
assert_no_select "input[class='string required my_input ']"
|
|
138
163
|
assert_no_select "input[class=' string required my_input']"
|
|
@@ -1,24 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
# encoding: UTF-8
|
|
2
3
|
require 'test_helper'
|
|
3
4
|
|
|
4
5
|
class TextInputTest < ActionView::TestCase
|
|
5
|
-
test 'input
|
|
6
|
+
test 'input generates a text area for text attributes' do
|
|
6
7
|
with_input_for @user, :description, :text
|
|
7
8
|
assert_select 'textarea.text#user_description'
|
|
8
9
|
end
|
|
9
10
|
|
|
10
|
-
test 'input
|
|
11
|
-
with_input_for @user, :description, :text, :
|
|
12
|
-
assert_select 'textarea.text[placeholder=Put in some text]'
|
|
11
|
+
test 'input generates a text area for text attributes that accept placeholder' do
|
|
12
|
+
with_input_for @user, :description, :text, placeholder: 'Put in some text'
|
|
13
|
+
assert_select 'textarea.text[placeholder="Put in some text"]'
|
|
13
14
|
end
|
|
14
15
|
|
|
15
|
-
test 'input
|
|
16
|
+
test 'input generates a placeholder from the translations' do
|
|
17
|
+
store_translations(:en, simple_form: { placeholders: { user: { name: "placeholder from i18n en.simple_form.placeholders.user.name" } } }) do
|
|
18
|
+
with_input_for @user, :name, :text
|
|
19
|
+
assert_select 'textarea.text[placeholder="placeholder from i18n en.simple_form.placeholders.user.name"]'
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
test 'input gets maxlength from column definition for text attributes' do
|
|
16
24
|
with_input_for @user, :description, :text
|
|
17
|
-
assert_select 'textarea.text[maxlength=200]'
|
|
25
|
+
assert_select 'textarea.text[maxlength="200"]'
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
test 'input infers maxlength column definition from validation when present for text attributes' do
|
|
29
|
+
with_input_for @validating_user, :description, :text
|
|
30
|
+
assert_select 'textarea.text[maxlength="50"]'
|
|
18
31
|
end
|
|
19
32
|
|
|
20
|
-
test 'input
|
|
33
|
+
test 'input infers minlength column definition from validation when present for text attributes' do
|
|
21
34
|
with_input_for @validating_user, :description, :text
|
|
22
|
-
assert_select 'textarea.text[
|
|
35
|
+
assert_select 'textarea.text[minlength="15"]'
|
|
23
36
|
end
|
|
24
37
|
end
|
data/test/simple_form_test.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
require 'test_helper'
|
|
2
3
|
|
|
3
4
|
class SimpleFormTest < ActiveSupport::TestCase
|
|
@@ -6,4 +7,12 @@ class SimpleFormTest < ActiveSupport::TestCase
|
|
|
6
7
|
assert_equal SimpleForm, config
|
|
7
8
|
end
|
|
8
9
|
end
|
|
10
|
+
|
|
11
|
+
test 'setup block configure Simple Form' do
|
|
12
|
+
SimpleForm.setup do |config|
|
|
13
|
+
assert_equal SimpleForm, config
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
assert_equal true, SimpleForm.configured?
|
|
17
|
+
end
|
|
9
18
|
end
|
|
@@ -1,16 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
class StringInput < SimpleForm::Inputs::StringInput
|
|
2
|
-
def input
|
|
3
|
+
def input(wrapper_options = nil)
|
|
3
4
|
"<section>#{super}</section>".html_safe
|
|
4
5
|
end
|
|
5
6
|
end
|
|
6
7
|
|
|
7
8
|
class NumericInput < SimpleForm::Inputs::NumericInput
|
|
8
|
-
def input
|
|
9
|
+
def input(wrapper_options = nil)
|
|
9
10
|
"<section>#{super}</section>".html_safe
|
|
10
11
|
end
|
|
11
12
|
end
|
|
12
13
|
|
|
13
14
|
class CustomizedInput < SimpleForm::Inputs::StringInput
|
|
15
|
+
def input(wrapper_options = nil)
|
|
16
|
+
"<section>#{super}</section>".html_safe
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def input_method
|
|
20
|
+
:text_field
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
class DeprecatedInput < SimpleForm::Inputs::StringInput
|
|
14
25
|
def input
|
|
15
26
|
"<section>#{super}</section>".html_safe
|
|
16
27
|
end
|
|
@@ -19,3 +30,29 @@ class CustomizedInput < SimpleForm::Inputs::StringInput
|
|
|
19
30
|
:text_field
|
|
20
31
|
end
|
|
21
32
|
end
|
|
33
|
+
|
|
34
|
+
class CollectionSelectInput < SimpleForm::Inputs::CollectionSelectInput
|
|
35
|
+
def input_html_classes
|
|
36
|
+
super.push('chosen')
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
module CustomInputs
|
|
41
|
+
class CustomizedInput < SimpleForm::Inputs::StringInput
|
|
42
|
+
def input_html_classes
|
|
43
|
+
super.push('customized-namespace-custom-input')
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
class PasswordInput < SimpleForm::Inputs::PasswordInput
|
|
48
|
+
def input_html_classes
|
|
49
|
+
super.push('password-custom-input')
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
class NumericInput < SimpleForm::Inputs::PasswordInput
|
|
54
|
+
def input_html_classes
|
|
55
|
+
super.push('numeric-custom-input')
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|