simple_form 2.1.0 → 3.2.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 +7 -0
- data/CHANGELOG.md +77 -33
- data/MIT-LICENSE +1 -1
- data/README.md +387 -187
- data/lib/generators/simple_form/install_generator.rb +4 -4
- data/lib/generators/simple_form/templates/README +3 -4
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +45 -22
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +128 -24
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +87 -6
- data/lib/generators/simple_form/templates/config/locales/simple_form.en.yml +7 -2
- data/lib/simple_form/action_view_extensions/builder.rb +2 -319
- data/lib/simple_form/action_view_extensions/form_helper.rb +8 -11
- data/lib/simple_form/components/errors.rb +28 -2
- data/lib/simple_form/components/hints.rb +8 -3
- data/lib/simple_form/components/html5.rb +6 -3
- data/lib/simple_form/components/label_input.rb +20 -2
- data/lib/simple_form/components/labels.rb +14 -10
- data/lib/simple_form/components/maxlength.rb +2 -9
- data/lib/simple_form/components/min_max.rb +1 -1
- data/lib/simple_form/components/pattern.rb +3 -3
- data/lib/simple_form/components/placeholders.rb +2 -2
- data/lib/simple_form/components/readonly.rb +1 -1
- data/lib/simple_form/components.rb +1 -1
- data/lib/simple_form/error_notification.rb +2 -2
- data/lib/simple_form/form_builder.rb +262 -107
- data/lib/simple_form/helpers.rb +6 -6
- data/lib/simple_form/inputs/base.rb +37 -16
- data/lib/simple_form/inputs/block_input.rb +2 -2
- data/lib/simple_form/inputs/boolean_input.rb +33 -18
- data/lib/simple_form/inputs/collection_input.rb +34 -13
- data/lib/simple_form/inputs/collection_radio_buttons_input.rb +7 -12
- data/lib/simple_form/inputs/collection_select_input.rb +4 -2
- data/lib/simple_form/inputs/date_time_input.rb +23 -9
- data/lib/simple_form/inputs/file_input.rb +4 -2
- data/lib/simple_form/inputs/grouped_collection_select_input.rb +15 -3
- data/lib/simple_form/inputs/hidden_input.rb +4 -2
- data/lib/simple_form/inputs/numeric_input.rb +3 -8
- data/lib/simple_form/inputs/password_input.rb +4 -3
- data/lib/simple_form/inputs/priority_input.rb +4 -2
- data/lib/simple_form/inputs/range_input.rb +1 -1
- data/lib/simple_form/inputs/string_input.rb +4 -3
- data/lib/simple_form/inputs/text_input.rb +4 -2
- data/lib/simple_form/railtie.rb +14 -0
- data/lib/simple_form/tags.rb +68 -0
- data/lib/simple_form/version.rb +1 -1
- data/lib/simple_form/wrappers/builder.rb +11 -35
- data/lib/simple_form/wrappers/leaf.rb +28 -0
- data/lib/simple_form/wrappers/many.rb +7 -7
- data/lib/simple_form/wrappers/root.rb +2 -2
- data/lib/simple_form/wrappers/single.rb +5 -3
- data/lib/simple_form/wrappers.rb +2 -1
- data/lib/simple_form.rb +99 -52
- data/test/action_view_extensions/builder_test.rb +113 -127
- data/test/action_view_extensions/form_helper_test.rb +58 -30
- data/test/components/label_test.rb +83 -83
- data/test/form_builder/association_test.rb +96 -61
- data/test/form_builder/button_test.rb +14 -14
- data/test/form_builder/error_notification_test.rb +9 -9
- data/test/form_builder/error_test.rb +159 -34
- data/test/form_builder/general_test.rb +176 -121
- data/test/form_builder/hint_test.rb +43 -37
- data/test/form_builder/input_field_test.rb +99 -52
- data/test/form_builder/label_test.rb +67 -15
- data/test/form_builder/wrapper_test.rb +157 -41
- data/test/generators/simple_form_generator_test.rb +4 -4
- data/test/inputs/boolean_input_test.rb +92 -24
- data/test/inputs/collection_check_boxes_input_test.rb +150 -71
- data/test/inputs/collection_radio_buttons_input_test.rb +213 -113
- data/test/inputs/collection_select_input_test.rb +221 -85
- data/test/inputs/datetime_input_test.rb +125 -47
- data/test/inputs/disabled_test.rb +25 -25
- data/test/inputs/discovery_test.rb +60 -10
- data/test/inputs/file_input_test.rb +3 -3
- data/test/inputs/general_test.rb +48 -32
- data/test/inputs/grouped_collection_select_input_test.rb +76 -27
- data/test/inputs/hidden_input_test.rb +6 -5
- data/test/inputs/numeric_input_test.rb +46 -46
- data/test/inputs/priority_input_test.rb +21 -15
- data/test/inputs/readonly_test.rb +31 -31
- data/test/inputs/required_test.rb +30 -18
- data/test/inputs/string_input_test.rb +53 -52
- data/test/inputs/text_input_test.rb +15 -8
- data/test/simple_form_test.rb +8 -0
- data/test/support/discovery_inputs.rb +32 -2
- data/test/support/misc_helpers.rb +130 -29
- data/test/support/mock_controller.rb +6 -6
- data/test/support/models.rb +125 -71
- data/test/test_helper.rb +28 -35
- metadata +17 -29
- data/lib/simple_form/action_view_extensions/builder.rb.orig +0 -247
- data/lib/simple_form/core_ext/hash.rb +0 -16
- data/lib/simple_form/form_builder.rb.orig +0 -486
- data/lib/simple_form/version.rb.orig +0 -7
@@ -2,43 +2,43 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class RequiredTest < ActionView::TestCase
|
4
4
|
# REQUIRED AND PRESENCE VALIDATION
|
5
|
-
test 'builder input
|
5
|
+
test 'builder input obtains required from ActiveModel::Validations when it is included' do
|
6
6
|
with_form_for @validating_user, :name
|
7
7
|
assert_select 'input.required[required]#validating_user_name'
|
8
8
|
with_form_for @validating_user, :status
|
9
9
|
assert_select 'input.optional#validating_user_status'
|
10
10
|
end
|
11
11
|
|
12
|
-
test 'builder input
|
13
|
-
with_form_for @validating_user, :name, :
|
12
|
+
test 'builder input allows overriding required when ActiveModel::Validations is included' do
|
13
|
+
with_form_for @validating_user, :name, required: false
|
14
14
|
assert_select 'input.optional#validating_user_name'
|
15
|
-
with_form_for @validating_user, :status, :
|
15
|
+
with_form_for @validating_user, :status, required: true
|
16
16
|
assert_select 'input.required[required]#validating_user_status'
|
17
17
|
end
|
18
18
|
|
19
|
-
test 'builder input
|
19
|
+
test 'builder input is required by default when ActiveModel::Validations is not included' do
|
20
20
|
with_form_for @user, :name
|
21
21
|
assert_select 'input.required[required]#user_name'
|
22
22
|
end
|
23
23
|
|
24
|
-
test 'builder input
|
25
|
-
swap SimpleForm, :
|
24
|
+
test 'builder input does not be required by default when ActiveModel::Validations is not included if option is set to false' do
|
25
|
+
swap SimpleForm, required_by_default: false do
|
26
26
|
with_form_for @user, :name
|
27
27
|
assert_select 'input.optional#user_name'
|
28
28
|
assert_no_select 'input[required]'
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
test 'when not using browser validations, input
|
33
|
-
swap SimpleForm, :
|
32
|
+
test 'when not using browser validations, input does not generate required html attribute' do
|
33
|
+
swap SimpleForm, browser_validations: false do
|
34
34
|
with_input_for @user, :name, :string
|
35
35
|
assert_select 'input[type=text].required'
|
36
36
|
assert_no_select 'input[type=text][required]'
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
test 'builder input
|
41
|
-
with_form_for @user, :name, :
|
40
|
+
test 'builder input allows disabling required when ActiveModel::Validations is not included' do
|
41
|
+
with_form_for @user, :name, required: false
|
42
42
|
assert_no_select 'input.required'
|
43
43
|
assert_no_select 'input[required]'
|
44
44
|
assert_select 'input.optional#user_name'
|
@@ -53,14 +53,14 @@ class RequiredTest < ActionView::TestCase
|
|
53
53
|
end
|
54
54
|
|
55
55
|
# VALIDATORS :if :unless
|
56
|
-
test 'builder input
|
56
|
+
test 'builder input does not be required when ActiveModel::Validations is included and if option is present' do
|
57
57
|
with_form_for @validating_user, :age
|
58
58
|
assert_no_select 'input.required'
|
59
59
|
assert_no_select 'input[required]'
|
60
60
|
assert_select 'input.optional#validating_user_age'
|
61
61
|
end
|
62
62
|
|
63
|
-
test 'builder input
|
63
|
+
test 'builder input does not be required when ActiveModel::Validations is included and unless option is present' do
|
64
64
|
with_form_for @validating_user, :amount
|
65
65
|
assert_no_select 'input.required'
|
66
66
|
assert_no_select 'input[required]'
|
@@ -68,7 +68,7 @@ class RequiredTest < ActionView::TestCase
|
|
68
68
|
end
|
69
69
|
|
70
70
|
# VALIDATORS :on
|
71
|
-
test 'builder input
|
71
|
+
test 'builder input is required when validation is on create and is not persisted' do
|
72
72
|
@validating_user.new_record!
|
73
73
|
with_form_for @validating_user, :action
|
74
74
|
assert_select 'input.required'
|
@@ -76,14 +76,14 @@ class RequiredTest < ActionView::TestCase
|
|
76
76
|
assert_select 'input.required[required]#validating_user_action'
|
77
77
|
end
|
78
78
|
|
79
|
-
test 'builder input
|
79
|
+
test 'builder input does not be required when validation is on create and is persisted' do
|
80
80
|
with_form_for @validating_user, :action
|
81
81
|
assert_no_select 'input.required'
|
82
82
|
assert_no_select 'input[required]'
|
83
83
|
assert_select 'input.optional#validating_user_action'
|
84
84
|
end
|
85
85
|
|
86
|
-
test 'builder input
|
86
|
+
test 'builder input is required when validation is on save' do
|
87
87
|
with_form_for @validating_user, :credit_limit
|
88
88
|
assert_select 'input.required'
|
89
89
|
assert_select 'input[required]'
|
@@ -96,18 +96,30 @@ class RequiredTest < ActionView::TestCase
|
|
96
96
|
assert_select 'input.required[required]#validating_user_credit_limit'
|
97
97
|
end
|
98
98
|
|
99
|
-
test 'builder input
|
99
|
+
test 'builder input is required when validation is on update and is persisted' do
|
100
100
|
with_form_for @validating_user, :phone_number
|
101
101
|
assert_select 'input.required'
|
102
102
|
assert_select 'input[required]'
|
103
103
|
assert_select 'input.required[required]#validating_user_phone_number'
|
104
104
|
end
|
105
105
|
|
106
|
-
test 'builder input
|
106
|
+
test 'builder input does not be required when validation is on update and is not persisted' do
|
107
107
|
@validating_user.new_record!
|
108
108
|
with_form_for @validating_user, :phone_number
|
109
109
|
assert_no_select 'input.required'
|
110
110
|
assert_no_select 'input[required]'
|
111
111
|
assert_select 'input.optional#validating_user_phone_number'
|
112
112
|
end
|
113
|
+
|
114
|
+
test 'builder input does not generate required html attribute when option is set to false when it is set to true in wrapper' do
|
115
|
+
swap SimpleForm, browser_validations: true do
|
116
|
+
swap_wrapper :default, self.custom_wrapper_with_required_input do
|
117
|
+
with_concat_form_for(@user) do |f|
|
118
|
+
concat f.input :name, required: false
|
119
|
+
end
|
120
|
+
assert_no_select 'input[type=text][required]'
|
121
|
+
assert_no_select 'input[type=text][aria-required]'
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
113
125
|
end
|
@@ -2,126 +2,127 @@
|
|
2
2
|
require 'test_helper'
|
3
3
|
|
4
4
|
class StringInputTest < ActionView::TestCase
|
5
|
-
test 'input
|
5
|
+
test 'input maps text field to string attribute' do
|
6
6
|
with_input_for @user, :name, :string
|
7
|
-
assert_select "input#user_name[type=text][name='user[name]'][value=New in SimpleForm!]"
|
7
|
+
assert_select "input#user_name[type=text][name='user[name]'][value='New in SimpleForm!']"
|
8
8
|
end
|
9
9
|
|
10
|
-
test 'input
|
10
|
+
test 'input generates a password field for password attributes' do
|
11
11
|
with_input_for @user, :password, :password
|
12
12
|
assert_select "input#user_password.password[type=password][name='user[password]']"
|
13
13
|
end
|
14
14
|
|
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
|
15
|
+
test 'input gets maxlength from column definition for string attributes' do
|
21
16
|
with_input_for @user, :name, :string
|
22
|
-
assert_select 'input.string[maxlength=100]'
|
17
|
+
assert_select 'input.string[maxlength="100"]'
|
23
18
|
end
|
24
19
|
|
25
|
-
test 'input
|
20
|
+
test 'input does not get maxlength from column without size definition for string attributes' do
|
26
21
|
with_input_for @user, :action, :string
|
27
22
|
assert_no_select 'input.string[maxlength]'
|
28
23
|
end
|
29
24
|
|
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
|
36
|
-
with_input_for @user, :password, :password
|
37
|
-
assert_select 'input.password[type=password][size=50]'
|
38
|
-
end
|
39
|
-
|
40
|
-
test 'input should get maxlength from column definition for password attributes' do
|
25
|
+
test 'input gets maxlength from column definition for password attributes' do
|
41
26
|
with_input_for @user, :password, :password
|
42
|
-
assert_select 'input.password[type=password][maxlength=100]'
|
27
|
+
assert_select 'input.password[type=password][maxlength="100"]'
|
43
28
|
end
|
44
29
|
|
45
|
-
test 'input
|
30
|
+
test 'input infers maxlength column definition from validation when present' do
|
46
31
|
with_input_for @validating_user, :name, :string
|
47
|
-
assert_select 'input.string[maxlength=25]'
|
32
|
+
assert_select 'input.string[maxlength="25"]'
|
48
33
|
end
|
49
34
|
|
50
|
-
test 'input
|
35
|
+
test 'input does not get maxlength from validation when tokenizer present' do
|
51
36
|
with_input_for @validating_user, :action, :string
|
52
37
|
assert_no_select 'input.string[maxlength]'
|
53
38
|
end
|
54
39
|
|
55
|
-
test 'input
|
40
|
+
test 'input gets maxlength from validation when :is option present' do
|
56
41
|
with_input_for @validating_user, :home_picture, :string
|
57
|
-
assert_select 'input.string[maxlength=12]'
|
42
|
+
assert_select 'input.string[maxlength="12"]'
|
58
43
|
end
|
59
44
|
|
60
|
-
test 'input
|
45
|
+
test 'input maxlength is the column limit plus one to make room for decimal point' do
|
61
46
|
with_input_for @user, :credit_limit, :string
|
62
47
|
|
63
|
-
assert_select
|
48
|
+
assert_select 'input.string[maxlength="16"]'
|
64
49
|
end
|
65
50
|
|
66
|
-
test 'input
|
51
|
+
test 'input does not generate placeholder by default' do
|
67
52
|
with_input_for @user, :name, :string
|
68
53
|
assert_no_select 'input[placeholder]'
|
69
54
|
end
|
70
55
|
|
71
|
-
test 'input
|
72
|
-
with_input_for @user, :name, :string, :
|
73
|
-
assert_select 'input.string[placeholder=Put in some text]'
|
56
|
+
test 'input accepts the placeholder option' do
|
57
|
+
with_input_for @user, :name, :string, placeholder: 'Put in some text'
|
58
|
+
assert_select 'input.string[placeholder="Put in some text"]'
|
74
59
|
end
|
75
60
|
|
76
|
-
test 'input
|
77
|
-
with_input_for @user, :password, :password, :
|
78
|
-
assert_select 'input[type=password].password[placeholder=Password Confirmation]#user_password'
|
61
|
+
test 'input generates a password field for password attributes that accept placeholder' do
|
62
|
+
with_input_for @user, :password, :password, placeholder: 'Password Confirmation'
|
63
|
+
assert_select 'input[type=password].password[placeholder="Password Confirmation"]#user_password'
|
79
64
|
end
|
80
65
|
|
81
|
-
test 'input
|
66
|
+
test 'input does not infer pattern from attributes by default' do
|
82
67
|
with_input_for @other_validating_user, :country, :string
|
83
68
|
assert_no_select 'input[pattern="\w+"]'
|
84
69
|
end
|
85
70
|
|
86
|
-
test 'input
|
87
|
-
with_input_for @other_validating_user, :country, :string, :
|
71
|
+
test 'input infers pattern from attributes' do
|
72
|
+
with_input_for @other_validating_user, :country, :string, pattern: true
|
88
73
|
assert_select 'input[pattern="\w+"]'
|
89
74
|
end
|
90
75
|
|
91
|
-
test 'input
|
92
|
-
with_input_for @other_validating_user, :name, :string, :
|
76
|
+
test 'input infers pattern from attributes using proc' do
|
77
|
+
with_input_for @other_validating_user, :name, :string, pattern: true
|
93
78
|
assert_select 'input[pattern="\w+"]'
|
94
79
|
end
|
95
80
|
|
96
|
-
test 'input
|
81
|
+
test 'input does not infer pattern from attributes if root default is false' do
|
97
82
|
swap_wrapper do
|
98
83
|
with_input_for @other_validating_user, :country, :string
|
99
84
|
assert_no_select 'input[pattern="\w+"]'
|
100
85
|
end
|
101
86
|
end
|
102
87
|
|
103
|
-
test 'input
|
104
|
-
with_input_for @other_validating_user, :country, :string, :
|
88
|
+
test 'input uses given pattern from attributes' do
|
89
|
+
with_input_for @other_validating_user, :country, :string, input_html: { pattern: "\\d+" }
|
105
90
|
assert_select 'input[pattern="\d+"]'
|
106
91
|
end
|
107
92
|
|
108
|
-
test 'input
|
109
|
-
|
110
|
-
|
93
|
+
test 'input does not use pattern if model has :without validation option' do
|
94
|
+
with_input_for @other_validating_user, :description, :string, pattern: true
|
95
|
+
assert_no_select 'input[pattern="\d+"]'
|
96
|
+
end
|
97
|
+
|
98
|
+
test 'input uses i18n to translate placeholder text' do
|
99
|
+
store_translations(:en, simple_form: { placeholders: { user: {
|
100
|
+
name: 'Name goes here'
|
111
101
|
} } }) do
|
112
102
|
with_input_for @user, :name, :string
|
113
|
-
assert_select 'input.string[placeholder=Name goes here]'
|
103
|
+
assert_select 'input.string[placeholder="Name goes here"]'
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
test 'input uses custom i18n scope to translate placeholder text' do
|
108
|
+
store_translations(:en, my_scope: { placeholders: { user: {
|
109
|
+
name: 'Name goes here'
|
110
|
+
} } }) do
|
111
|
+
swap SimpleForm, i18n_scope: :my_scope do
|
112
|
+
with_input_for @user, :name, :string
|
113
|
+
assert_select 'input.string[placeholder="Name goes here"]'
|
114
|
+
end
|
114
115
|
end
|
115
116
|
end
|
116
117
|
|
117
118
|
[:email, :url, :search, :tel].each do |type|
|
118
|
-
test "input
|
119
|
+
test "input allows type #{type}" do
|
119
120
|
with_input_for @user, :name, type
|
120
121
|
assert_select "input.string.#{type}"
|
121
122
|
assert_select "input[type=#{type}]"
|
122
123
|
end
|
123
124
|
|
124
|
-
test "input
|
125
|
+
test "input does not allow type #{type} if HTML5 compatibility is disabled" do
|
125
126
|
swap_wrapper do
|
126
127
|
with_input_for @user, :name, type
|
127
128
|
assert_select "input[type=text]"
|
@@ -138,7 +139,7 @@ class StringInputTest < ActionView::TestCase
|
|
138
139
|
end
|
139
140
|
|
140
141
|
test 'input strips extra spaces from class html attribute when giving a custom class' do
|
141
|
-
with_input_for @user, :name, :string, :
|
142
|
+
with_input_for @user, :name, :string, input_html: { class: "my_input" }
|
142
143
|
assert_select "input[class='string required my_input']"
|
143
144
|
assert_no_select "input[class='string required my_input ']"
|
144
145
|
assert_no_select "input[class=' string required my_input']"
|
@@ -2,23 +2,30 @@
|
|
2
2
|
require 'test_helper'
|
3
3
|
|
4
4
|
class TextInputTest < ActionView::TestCase
|
5
|
-
test 'input
|
5
|
+
test 'input generates a text area for text attributes' do
|
6
6
|
with_input_for @user, :description, :text
|
7
7
|
assert_select 'textarea.text#user_description'
|
8
8
|
end
|
9
9
|
|
10
|
-
test 'input
|
11
|
-
with_input_for @user, :description, :text, :
|
12
|
-
assert_select 'textarea.text[placeholder=Put in some text]'
|
10
|
+
test 'input generates a text area for text attributes that accept placeholder' do
|
11
|
+
with_input_for @user, :description, :text, placeholder: 'Put in some text'
|
12
|
+
assert_select 'textarea.text[placeholder="Put in some text"]'
|
13
13
|
end
|
14
14
|
|
15
|
-
test 'input
|
15
|
+
test 'input generates a placeholder from the translations' do
|
16
|
+
store_translations(:en, simple_form: { placeholders: { user: { name: "placeholder from i18n en.simple_form.placeholders.user.name" } } }) do
|
17
|
+
with_input_for @user, :name, :text
|
18
|
+
assert_select 'textarea.text[placeholder="placeholder from i18n en.simple_form.placeholders.user.name"]'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
test 'input gets maxlength from column definition for text attributes' do
|
16
23
|
with_input_for @user, :description, :text
|
17
|
-
assert_select 'textarea.text[maxlength=200]'
|
24
|
+
assert_select 'textarea.text[maxlength="200"]'
|
18
25
|
end
|
19
26
|
|
20
|
-
test 'input
|
27
|
+
test 'input infers maxlength column definition from validation when present for text attributes' do
|
21
28
|
with_input_for @validating_user, :description, :text
|
22
|
-
assert_select 'textarea.text[maxlength=50]'
|
29
|
+
assert_select 'textarea.text[maxlength="50"]'
|
23
30
|
end
|
24
31
|
end
|
data/test/simple_form_test.rb
CHANGED
@@ -6,4 +6,12 @@ class SimpleFormTest < ActiveSupport::TestCase
|
|
6
6
|
assert_equal SimpleForm, config
|
7
7
|
end
|
8
8
|
end
|
9
|
+
|
10
|
+
test 'setup block configure Simple Form' do
|
11
|
+
SimpleForm.setup do |config|
|
12
|
+
assert_equal SimpleForm, config
|
13
|
+
end
|
14
|
+
|
15
|
+
assert_equal true, SimpleForm.configured?
|
16
|
+
end
|
9
17
|
end
|
@@ -1,16 +1,26 @@
|
|
1
1
|
class StringInput < SimpleForm::Inputs::StringInput
|
2
|
-
def input
|
2
|
+
def input(wrapper_options = nil)
|
3
3
|
"<section>#{super}</section>".html_safe
|
4
4
|
end
|
5
5
|
end
|
6
6
|
|
7
7
|
class NumericInput < SimpleForm::Inputs::NumericInput
|
8
|
-
def input
|
8
|
+
def input(wrapper_options = nil)
|
9
9
|
"<section>#{super}</section>".html_safe
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
class CustomizedInput < SimpleForm::Inputs::StringInput
|
14
|
+
def input(wrapper_options = nil)
|
15
|
+
"<section>#{super}</section>".html_safe
|
16
|
+
end
|
17
|
+
|
18
|
+
def input_method
|
19
|
+
:text_field
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class DeprecatedInput < SimpleForm::Inputs::StringInput
|
14
24
|
def input
|
15
25
|
"<section>#{super}</section>".html_safe
|
16
26
|
end
|
@@ -25,3 +35,23 @@ class CollectionSelectInput < SimpleForm::Inputs::CollectionSelectInput
|
|
25
35
|
super.push('chosen')
|
26
36
|
end
|
27
37
|
end
|
38
|
+
|
39
|
+
module CustomInputs
|
40
|
+
class CustomizedInput < SimpleForm::Inputs::StringInput
|
41
|
+
def input_html_classes
|
42
|
+
super.push('customized-namespace-custom-input')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class PasswordInput < SimpleForm::Inputs::PasswordInput
|
47
|
+
def input_html_classes
|
48
|
+
super.push('password-custom-input')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class NumericInput < SimpleForm::Inputs::PasswordInput
|
53
|
+
def input_html_classes
|
54
|
+
super.push('numeric-custom-input')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -8,7 +8,7 @@ module MiscHelpers
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def assert_no_select(selector, value = nil)
|
11
|
-
assert_select(selector, :
|
11
|
+
assert_select(selector, text: value, count: 0)
|
12
12
|
end
|
13
13
|
|
14
14
|
def swap(object, new_values)
|
@@ -24,78 +24,179 @@ module MiscHelpers
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
def
|
28
|
-
|
29
|
-
|
27
|
+
def stub_any_instance(klass, method, value)
|
28
|
+
klass.class_eval do
|
29
|
+
alias_method :"new_#{method}", method
|
30
|
+
|
31
|
+
define_method(method) do
|
32
|
+
if value.respond_to?(:call)
|
33
|
+
value.call
|
34
|
+
else
|
35
|
+
value
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
30
40
|
yield
|
31
41
|
ensure
|
32
|
-
|
42
|
+
klass.class_eval do
|
43
|
+
undef_method method
|
44
|
+
alias_method method, :"new_#{method}"
|
45
|
+
undef_method :"new_#{method}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def swap_wrapper(name = :default, wrapper = custom_wrapper)
|
50
|
+
old = SimpleForm.wrappers[name.to_s]
|
51
|
+
SimpleForm.wrappers[name.to_s] = wrapper
|
52
|
+
yield
|
53
|
+
ensure
|
54
|
+
SimpleForm.wrappers[name.to_s] = old
|
33
55
|
end
|
34
56
|
|
35
57
|
def custom_wrapper
|
36
|
-
SimpleForm.build :
|
58
|
+
SimpleForm.build tag: :section, class: "custom_wrapper", pattern: false do |b|
|
37
59
|
b.use :pattern
|
38
|
-
b.wrapper :another, :
|
60
|
+
b.wrapper :another, class: "another_wrapper" do |ba|
|
39
61
|
ba.use :label
|
40
62
|
ba.use :input
|
41
63
|
end
|
42
|
-
b.wrapper :error_wrapper, :
|
43
|
-
be.use :error, :
|
64
|
+
b.wrapper :error_wrapper, tag: :div, class: "error_wrapper" do |be|
|
65
|
+
be.use :error, wrap_with: { tag: :span, class: "omg_error" }
|
66
|
+
end
|
67
|
+
b.use :hint, wrap_with: { class: "omg_hint" }
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def custom_wrapper_with_wrapped_optional_component
|
72
|
+
SimpleForm.build tag: :section, class: "custom_wrapper" do |b|
|
73
|
+
b.wrapper tag: :div, class: 'no_output_wrapper' do |ba|
|
74
|
+
ba.optional :hint, wrap_with: { tag: :p, class: 'omg_hint' }
|
44
75
|
end
|
45
|
-
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def custom_wrapper_with_unless_blank
|
80
|
+
SimpleForm.build tag: :section, class: "custom_wrapper" do |b|
|
81
|
+
b.wrapper tag: :div, class: 'no_output_wrapper', unless_blank: true do |ba|
|
82
|
+
ba.optional :hint, wrap_with: { tag: :p, class: 'omg_hint' }
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def custom_wrapper_with_input_class
|
88
|
+
SimpleForm.build tag: :div, class: "custom_wrapper" do |b|
|
89
|
+
b.use :label
|
90
|
+
b.use :input, class: 'inline-class'
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def custom_wrapper_with_label_class
|
95
|
+
SimpleForm.build tag: :div, class: "custom_wrapper" do |b|
|
96
|
+
b.use :label, class: 'inline-class'
|
97
|
+
b.use :input
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def custom_wrapper_with_input_attributes
|
102
|
+
SimpleForm.build tag: :div, class: "custom_wrapper" do |b|
|
103
|
+
b.use :input, data: { modal: true }
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def custom_wrapper_with_label_input_class
|
108
|
+
SimpleForm.build tag: :div, class: "custom_wrapper" do |b|
|
109
|
+
b.use :label_input, class: 'inline-class'
|
46
110
|
end
|
47
111
|
end
|
48
112
|
|
49
113
|
def custom_wrapper_with_wrapped_input
|
50
|
-
SimpleForm.build :
|
51
|
-
b.wrapper :
|
114
|
+
SimpleForm.build tag: :div, class: "custom_wrapper" do |b|
|
115
|
+
b.wrapper tag: :div, class: 'elem' do |component|
|
52
116
|
component.use :label
|
53
|
-
component.use :input, :
|
117
|
+
component.use :input, wrap_with: { tag: :div, class: 'input' }
|
54
118
|
end
|
55
119
|
end
|
56
120
|
end
|
57
121
|
|
58
122
|
def custom_wrapper_with_wrapped_label
|
59
|
-
SimpleForm.build :
|
60
|
-
b.wrapper :
|
61
|
-
component.use :label, :
|
123
|
+
SimpleForm.build tag: :div, class: "custom_wrapper" do |b|
|
124
|
+
b.wrapper tag: :div, class: 'elem' do |component|
|
125
|
+
component.use :label, wrap_with: { tag: :div, class: 'label' }
|
62
126
|
component.use :input
|
63
127
|
end
|
64
128
|
end
|
65
129
|
end
|
66
130
|
|
67
131
|
def custom_wrapper_without_top_level
|
68
|
-
SimpleForm.build :
|
132
|
+
SimpleForm.build tag: false, class: 'custom_wrapper_without_top_level' do |b|
|
69
133
|
b.use :label_input
|
70
|
-
b.use :hint, :
|
71
|
-
b.use :error, :
|
134
|
+
b.use :hint, wrap_with: { tag: :span, class: :hint }
|
135
|
+
b.use :error, wrap_with: { tag: :span, class: :error }
|
72
136
|
end
|
73
137
|
end
|
74
138
|
|
75
139
|
def custom_wrapper_without_class
|
76
|
-
SimpleForm.build :
|
140
|
+
SimpleForm.build tag: :div, wrapper_html: { id: 'custom_wrapper_without_class' } do |b|
|
77
141
|
b.use :label_input
|
78
142
|
end
|
79
143
|
end
|
80
144
|
|
81
145
|
def custom_wrapper_with_label_html_option
|
82
|
-
SimpleForm.build :
|
146
|
+
SimpleForm.build tag: :div, class: "custom_wrapper", label_html: { class: 'extra-label-class' } do |b|
|
83
147
|
b.use :label_input
|
84
148
|
end
|
85
149
|
end
|
86
150
|
|
87
151
|
def custom_wrapper_with_wrapped_label_input
|
88
|
-
SimpleForm.build :
|
89
|
-
b.use :label_input, :
|
152
|
+
SimpleForm.build tag: :section, class: "custom_wrapper", pattern: false do |b|
|
153
|
+
b.use :label_input, wrap_with: { tag: :div, class: :field }
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def custom_wrapper_with_additional_attributes
|
158
|
+
SimpleForm.build tag: :div, class: 'custom_wrapper', html: { data: { wrapper: :test }, title: 'some title' } do |b|
|
159
|
+
b.use :label_input
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def custom_wrapper_with_full_error
|
164
|
+
SimpleForm.build tag: :div, class: 'custom_wrapper' do |b|
|
165
|
+
b.use :full_error, wrap_with: { tag: :span, class: :error }
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
def custom_wrapper_with_label_text
|
170
|
+
SimpleForm.build :label_text => proc { |label, required| "**#{label}**" } do |b|
|
171
|
+
b.use :label_input
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
def custom_wrapper_with_custom_label_component
|
176
|
+
SimpleForm.build tag: :span, class: 'custom_wrapper' do |b|
|
177
|
+
b.use :label_text
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def custom_wrapper_with_html5_components
|
182
|
+
SimpleForm.build tag: :span, class: 'custom_wrapper' do |b|
|
183
|
+
b.use :label_text
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
def custom_wrapper_with_required_input
|
188
|
+
SimpleForm.build tag: :span, class: 'custom_wrapper' do |b|
|
189
|
+
b.use :html5
|
190
|
+
b.use :input, required: true
|
90
191
|
end
|
91
192
|
end
|
92
193
|
|
93
194
|
def custom_form_for(object, *args, &block)
|
94
|
-
simple_form_for(object, *
|
195
|
+
simple_form_for(object, *args, { builder: CustomFormBuilder }, &block)
|
95
196
|
end
|
96
197
|
|
97
198
|
def custom_mapping_form_for(object, *args, &block)
|
98
|
-
simple_form_for(object, *
|
199
|
+
simple_form_for(object, *args, { builder: CustomMapTypeFormBuilder }, &block)
|
99
200
|
end
|
100
201
|
|
101
202
|
def with_concat_form_for(*args, &block)
|
@@ -120,19 +221,19 @@ module MiscHelpers
|
|
120
221
|
end
|
121
222
|
end
|
122
223
|
|
123
|
-
def with_input_for(object, attribute_name, type, options={})
|
224
|
+
def with_input_for(object, attribute_name, type, options = {})
|
124
225
|
with_concat_form_for(object) do |f|
|
125
|
-
f.input(attribute_name, options.merge(:
|
226
|
+
f.input(attribute_name, options.merge(as: type))
|
126
227
|
end
|
127
228
|
end
|
128
229
|
end
|
129
230
|
|
130
231
|
class CustomFormBuilder < SimpleForm::FormBuilder
|
131
232
|
def input(attribute_name, *args, &block)
|
132
|
-
super(attribute_name, *
|
233
|
+
super(attribute_name, *args, { input_html: { class: 'custom' } }, &block)
|
133
234
|
end
|
134
235
|
end
|
135
236
|
|
136
237
|
class CustomMapTypeFormBuilder < SimpleForm::FormBuilder
|
137
|
-
map_type :custom_type, :
|
238
|
+
map_type :custom_type, to: SimpleForm::Inputs::StringInput
|
138
239
|
end
|