simple_form 2.1.0 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
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
@@ -3,13 +3,13 @@ module SimpleForm
|
|
3
3
|
class InstallGenerator < Rails::Generators::Base
|
4
4
|
desc "Copy SimpleForm default files"
|
5
5
|
source_root File.expand_path('../templates', __FILE__)
|
6
|
-
class_option :template_engine, :
|
7
|
-
class_option :bootstrap, :
|
8
|
-
class_option :foundation, :
|
6
|
+
class_option :template_engine, desc: 'Template engine to be invoked (erb, haml or slim).'
|
7
|
+
class_option :bootstrap, type: :boolean, desc: 'Add the Bootstrap wrappers to the SimpleForm initializer.'
|
8
|
+
class_option :foundation, type: :boolean, desc: 'Add the Zurb Foundation 5 wrappers to the SimpleForm initializer.'
|
9
9
|
|
10
10
|
def info_bootstrap
|
11
11
|
return if options.bootstrap? || options.foundation?
|
12
|
-
puts "SimpleForm
|
12
|
+
puts "SimpleForm 3 supports Bootstrap and Zurb Foundation 5. If you want "\
|
13
13
|
"a configuration that is compatible with one of these frameworks, then please " \
|
14
14
|
"re-run this generator with --bootstrap or --foundation as an option."
|
15
15
|
end
|
@@ -1,12 +1,11 @@
|
|
1
1
|
===============================================================================
|
2
2
|
|
3
3
|
Be sure to have a copy of the Bootstrap stylesheet available on your
|
4
|
-
application, you can get it on http://
|
4
|
+
application, you can get it on http://getbootstrap.com/.
|
5
5
|
|
6
6
|
Inside your views, use the 'simple_form_for' with one of the Bootstrap form
|
7
|
-
classes, '.form-horizontal'
|
8
|
-
'.form-vertical', as the following:
|
7
|
+
classes, '.form-horizontal' or '.form-inline', as the following:
|
9
8
|
|
10
|
-
= simple_form_for(@user, :
|
9
|
+
= simple_form_for(@user, html: { class: 'form-horizontal' }) do |form|
|
11
10
|
|
12
11
|
===============================================================================
|
@@ -5,8 +5,8 @@ SimpleForm.setup do |config|
|
|
5
5
|
# wrapper, change the order or even add your own to the
|
6
6
|
# stack. The options given below are used to wrap the
|
7
7
|
# whole input.
|
8
|
-
config.wrappers :default, :
|
9
|
-
:
|
8
|
+
config.wrappers :default, class: :input,
|
9
|
+
hint_class: :field_with_hint, error_class: :field_with_errors do |b|
|
10
10
|
## Extensions enabled by default
|
11
11
|
# Any of these extensions can be disabled for a
|
12
12
|
# given input by passing: `f.input EXTENSION_NAME => false`.
|
@@ -18,13 +18,13 @@ SimpleForm.setup do |config|
|
|
18
18
|
b.use :html5
|
19
19
|
|
20
20
|
# Calculates placeholders automatically from I18n
|
21
|
-
# You can also pass a string as f.input :
|
21
|
+
# You can also pass a string as f.input placeholder: "Placeholder"
|
22
22
|
b.use :placeholder
|
23
23
|
|
24
24
|
## Optional extensions
|
25
|
-
# They are disabled unless you pass `f.input EXTENSION_NAME =>
|
25
|
+
# They are disabled unless you pass `f.input EXTENSION_NAME => true`
|
26
26
|
# to the input. If so, they will retrieve the values from the model
|
27
|
-
# if any exists. If you want to enable
|
27
|
+
# if any exists. If you want to enable any of those
|
28
28
|
# extensions by default, you can change `b.optional` to `b.use`.
|
29
29
|
|
30
30
|
# Calculates maxlength from length validations for string inputs
|
@@ -41,8 +41,14 @@ SimpleForm.setup do |config|
|
|
41
41
|
|
42
42
|
## Inputs
|
43
43
|
b.use :label_input
|
44
|
-
b.use :hint, :
|
45
|
-
b.use :error, :
|
44
|
+
b.use :hint, wrap_with: { tag: :span, class: :hint }
|
45
|
+
b.use :error, wrap_with: { tag: :span, class: :error }
|
46
|
+
|
47
|
+
## full_messages_for
|
48
|
+
# If you want to display the full error message for the attribute, you can
|
49
|
+
# use the component :full_error, like:
|
50
|
+
#
|
51
|
+
# b.use :full_error, wrap_with: { tag: :span, class: :error }
|
46
52
|
end
|
47
53
|
|
48
54
|
# The default wrapper to be used by the FormBuilder.
|
@@ -50,8 +56,8 @@ SimpleForm.setup do |config|
|
|
50
56
|
|
51
57
|
# Define the way to render check boxes / radio buttons with labels.
|
52
58
|
# Defaults to :nested for bootstrap config.
|
53
|
-
# :
|
54
|
-
# :
|
59
|
+
# inline: input + label
|
60
|
+
# nested: label > input
|
55
61
|
config.boolean_style = :nested
|
56
62
|
|
57
63
|
# Default class for buttons
|
@@ -66,7 +72,7 @@ SimpleForm.setup do |config|
|
|
66
72
|
config.error_notification_tag = :div
|
67
73
|
|
68
74
|
# CSS class to add for error notification helper.
|
69
|
-
config.error_notification_class = '
|
75
|
+
config.error_notification_class = 'error_notification'
|
70
76
|
|
71
77
|
# ID to add for error notification helper.
|
72
78
|
# config.error_notification_id = nil
|
@@ -84,21 +90,21 @@ SimpleForm.setup do |config|
|
|
84
90
|
# config.collection_wrapper_class = nil
|
85
91
|
|
86
92
|
# You can wrap each item in a collection of radio/check boxes with a tag,
|
87
|
-
# defaulting to :span.
|
88
|
-
# SimpleForm will force this option to be a label.
|
93
|
+
# defaulting to :span.
|
89
94
|
# config.item_wrapper_tag = :span
|
90
95
|
|
91
96
|
# You can define a class to use in all item wrappers. Defaulting to none.
|
92
97
|
# config.item_wrapper_class = nil
|
93
98
|
|
94
99
|
# How the label text should be generated altogether with the required text.
|
95
|
-
# config.label_text = lambda { |label, required| "#{required} #{label}" }
|
100
|
+
# config.label_text = lambda { |label, required, explicit_label| "#{required} #{label}" }
|
96
101
|
|
97
102
|
# You can define the class to use on all labels. Default is nil.
|
98
|
-
config.label_class =
|
103
|
+
# config.label_class = nil
|
99
104
|
|
100
|
-
# You can define the class to
|
101
|
-
#
|
105
|
+
# You can define the default class to be used on forms. Can be overriden
|
106
|
+
# with `html: { :class }`. Defaulting to none.
|
107
|
+
# config.default_form_class = nil
|
102
108
|
|
103
109
|
# You can define which elements should obtain additional classes
|
104
110
|
# config.generate_additional_classes_for = [:wrapper, :label, :input]
|
@@ -106,8 +112,11 @@ SimpleForm.setup do |config|
|
|
106
112
|
# Whether attributes are required by default (or not). Default is true.
|
107
113
|
# config.required_by_default = true
|
108
114
|
|
109
|
-
# Tell browsers whether to use
|
110
|
-
#
|
115
|
+
# Tell browsers whether to use the native HTML5 validations (novalidate form option).
|
116
|
+
# These validations are enabled in SimpleForm's internal config but disabled by default
|
117
|
+
# in this configuration, which is recommended due to some quirks from different browsers.
|
118
|
+
# To stop SimpleForm from generating the novalidate option, enabling the HTML5 validations,
|
119
|
+
# change this configuration to true.
|
111
120
|
config.browser_validations = false
|
112
121
|
|
113
122
|
# Collection of methods to detect if a file type was given.
|
@@ -120,7 +129,11 @@ SimpleForm.setup do |config|
|
|
120
129
|
|
121
130
|
# Custom wrappers for input types. This should be a hash containing an input
|
122
131
|
# type as key and the wrapper that will be used for all inputs with specified type.
|
123
|
-
# config.wrapper_mappings = { :
|
132
|
+
# config.wrapper_mappings = { string: :prepend }
|
133
|
+
|
134
|
+
# Namespaces where SimpleForm should look for custom input classes that
|
135
|
+
# override default inputs.
|
136
|
+
# config.custom_inputs_namespaces << "CustomInputs"
|
124
137
|
|
125
138
|
# Default priority for time_zone inputs.
|
126
139
|
# config.time_zone_priority = nil
|
@@ -128,9 +141,6 @@ SimpleForm.setup do |config|
|
|
128
141
|
# Default priority for country inputs.
|
129
142
|
# config.country_priority = nil
|
130
143
|
|
131
|
-
# Default size for text inputs.
|
132
|
-
# config.default_input_size = 50
|
133
|
-
|
134
144
|
# When false, do not use translations for labels.
|
135
145
|
# config.translate_labels = true
|
136
146
|
|
@@ -139,4 +149,17 @@ SimpleForm.setup do |config|
|
|
139
149
|
|
140
150
|
# Cache SimpleForm inputs discovery
|
141
151
|
# config.cache_discovery = !Rails.env.development?
|
152
|
+
|
153
|
+
# Default class for inputs
|
154
|
+
# config.input_class = nil
|
155
|
+
|
156
|
+
# Define the default class of the input wrapper of the boolean input.
|
157
|
+
config.boolean_label_class = 'checkbox'
|
158
|
+
|
159
|
+
# Defines if the default input wrapper class should be included in radio
|
160
|
+
# collection wrappers.
|
161
|
+
# config.include_default_input_wrapper_class = true
|
162
|
+
|
163
|
+
# Defines which i18n scope will be used in Simple Form.
|
164
|
+
# config.i18n_scope = 'simple_form'
|
142
165
|
end
|
@@ -1,45 +1,149 @@
|
|
1
1
|
# Use this setup block to configure all options available in SimpleForm.
|
2
2
|
SimpleForm.setup do |config|
|
3
|
-
config.
|
3
|
+
config.error_notification_class = 'alert alert-danger'
|
4
|
+
config.button_class = 'btn btn-default'
|
5
|
+
config.boolean_label_class = nil
|
6
|
+
|
7
|
+
config.wrappers :vertical_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
|
4
8
|
b.use :html5
|
5
9
|
b.use :placeholder
|
6
|
-
b.
|
7
|
-
b.
|
8
|
-
|
9
|
-
|
10
|
-
|
10
|
+
b.optional :maxlength
|
11
|
+
b.optional :pattern
|
12
|
+
b.optional :min_max
|
13
|
+
b.optional :readonly
|
14
|
+
b.use :label, class: 'control-label'
|
15
|
+
|
16
|
+
b.use :input, class: 'form-control'
|
17
|
+
b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
18
|
+
b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
19
|
+
end
|
20
|
+
|
21
|
+
config.wrappers :vertical_file_input, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
|
22
|
+
b.use :html5
|
23
|
+
b.use :placeholder
|
24
|
+
b.optional :maxlength
|
25
|
+
b.optional :readonly
|
26
|
+
b.use :label, class: 'control-label'
|
27
|
+
|
28
|
+
b.use :input
|
29
|
+
b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
30
|
+
b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
31
|
+
end
|
32
|
+
|
33
|
+
config.wrappers :vertical_boolean, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
|
34
|
+
b.use :html5
|
35
|
+
b.optional :readonly
|
36
|
+
|
37
|
+
b.wrapper tag: 'div', class: 'checkbox' do |ba|
|
38
|
+
ba.use :label_input
|
11
39
|
end
|
40
|
+
|
41
|
+
b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
42
|
+
b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
43
|
+
end
|
44
|
+
|
45
|
+
config.wrappers :vertical_radio_and_checkboxes, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
|
46
|
+
b.use :html5
|
47
|
+
b.optional :readonly
|
48
|
+
b.use :label, class: 'control-label'
|
49
|
+
b.use :input
|
50
|
+
b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
51
|
+
b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
12
52
|
end
|
13
53
|
|
14
|
-
config.wrappers :
|
54
|
+
config.wrappers :horizontal_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
|
15
55
|
b.use :html5
|
16
56
|
b.use :placeholder
|
17
|
-
b.
|
18
|
-
b.
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
57
|
+
b.optional :maxlength
|
58
|
+
b.optional :pattern
|
59
|
+
b.optional :min_max
|
60
|
+
b.optional :readonly
|
61
|
+
b.use :label, class: 'col-sm-3 control-label'
|
62
|
+
|
63
|
+
b.wrapper tag: 'div', class: 'col-sm-9' do |ba|
|
64
|
+
ba.use :input, class: 'form-control'
|
65
|
+
ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
66
|
+
ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
24
67
|
end
|
25
68
|
end
|
26
69
|
|
27
|
-
config.wrappers :
|
70
|
+
config.wrappers :horizontal_file_input, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
|
28
71
|
b.use :html5
|
29
72
|
b.use :placeholder
|
30
|
-
b.
|
31
|
-
b.
|
32
|
-
|
33
|
-
|
73
|
+
b.optional :maxlength
|
74
|
+
b.optional :readonly
|
75
|
+
b.use :label, class: 'col-sm-3 control-label'
|
76
|
+
|
77
|
+
b.wrapper tag: 'div', class: 'col-sm-9' do |ba|
|
78
|
+
ba.use :input
|
79
|
+
ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
80
|
+
ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
config.wrappers :horizontal_boolean, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
|
85
|
+
b.use :html5
|
86
|
+
b.optional :readonly
|
87
|
+
|
88
|
+
b.wrapper tag: 'div', class: 'col-sm-offset-3 col-sm-9' do |wr|
|
89
|
+
wr.wrapper tag: 'div', class: 'checkbox' do |ba|
|
90
|
+
ba.use :label_input
|
34
91
|
end
|
35
|
-
|
36
|
-
|
92
|
+
|
93
|
+
wr.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
94
|
+
wr.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
config.wrappers :horizontal_radio_and_checkboxes, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
|
99
|
+
b.use :html5
|
100
|
+
b.optional :readonly
|
101
|
+
|
102
|
+
b.use :label, class: 'col-sm-3 control-label'
|
103
|
+
|
104
|
+
b.wrapper tag: 'div', class: 'col-sm-9' do |ba|
|
105
|
+
ba.use :input
|
106
|
+
ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
107
|
+
ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
37
108
|
end
|
38
109
|
end
|
39
110
|
|
40
|
-
|
41
|
-
|
111
|
+
config.wrappers :inline_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
|
112
|
+
b.use :html5
|
113
|
+
b.use :placeholder
|
114
|
+
b.optional :maxlength
|
115
|
+
b.optional :pattern
|
116
|
+
b.optional :min_max
|
117
|
+
b.optional :readonly
|
118
|
+
b.use :label, class: 'sr-only'
|
119
|
+
|
120
|
+
b.use :input, class: 'form-control'
|
121
|
+
b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
122
|
+
b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
123
|
+
end
|
124
|
+
|
125
|
+
config.wrappers :multi_select, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
|
126
|
+
b.use :html5
|
127
|
+
b.optional :readonly
|
128
|
+
b.use :label, class: 'control-label'
|
129
|
+
b.wrapper tag: 'div', class: 'form-inline' do |ba|
|
130
|
+
ba.use :input, class: 'form-control'
|
131
|
+
ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
132
|
+
ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
133
|
+
end
|
134
|
+
end
|
135
|
+
# Wrappers for forms and inputs using the Bootstrap toolkit.
|
136
|
+
# Check the Bootstrap docs (http://getbootstrap.com)
|
42
137
|
# to learn about the different styles for forms and inputs,
|
43
138
|
# buttons and other elements.
|
44
|
-
config.default_wrapper = :
|
139
|
+
config.default_wrapper = :vertical_form
|
140
|
+
config.wrapper_mappings = {
|
141
|
+
check_boxes: :vertical_radio_and_checkboxes,
|
142
|
+
radio_buttons: :vertical_radio_and_checkboxes,
|
143
|
+
file: :vertical_file_input,
|
144
|
+
boolean: :vertical_boolean,
|
145
|
+
datetime: :multi_select,
|
146
|
+
date: :multi_select,
|
147
|
+
time: :multi_select
|
148
|
+
}
|
45
149
|
end
|
@@ -1,6 +1,13 @@
|
|
1
1
|
# Use this setup block to configure all options available in SimpleForm.
|
2
2
|
SimpleForm.setup do |config|
|
3
|
-
|
3
|
+
# Don't forget to edit this file to adapt it to your needs (specially
|
4
|
+
# all the grid-related classes)
|
5
|
+
#
|
6
|
+
# Please note that hints are commented out by default since Foundation
|
7
|
+
# does't provide styles for hints. You will need to provide your own CSS styles for hints.
|
8
|
+
# Uncomment them to enable hints.
|
9
|
+
|
10
|
+
config.wrappers :vertical_form, class: :input, hint_class: :field_with_hint, error_class: :error do |b|
|
4
11
|
b.use :html5
|
5
12
|
b.use :placeholder
|
6
13
|
b.optional :maxlength
|
@@ -8,19 +15,93 @@ SimpleForm.setup do |config|
|
|
8
15
|
b.optional :min_max
|
9
16
|
b.optional :readonly
|
10
17
|
b.use :label_input
|
11
|
-
b.use :error, :
|
18
|
+
b.use :error, wrap_with: { tag: :small, class: :error }
|
19
|
+
|
20
|
+
# b.use :hint, wrap_with: { tag: :span, class: :hint }
|
21
|
+
end
|
22
|
+
|
23
|
+
config.wrappers :horizontal_form, tag: 'div', class: 'row', hint_class: :field_with_hint, error_class: :error do |b|
|
24
|
+
b.use :html5
|
25
|
+
b.use :placeholder
|
26
|
+
b.optional :maxlength
|
27
|
+
b.optional :pattern
|
28
|
+
b.optional :min_max
|
29
|
+
b.optional :readonly
|
30
|
+
|
31
|
+
b.wrapper :label_wrapper, tag: :div, class: 'small-3 columns' do |ba|
|
32
|
+
ba.use :label, class: 'right inline'
|
33
|
+
end
|
34
|
+
|
35
|
+
b.wrapper :right_input_wrapper, tag: :div, class: 'small-9 columns' do |ba|
|
36
|
+
ba.use :input
|
37
|
+
ba.use :error, wrap_with: { tag: :small, class: :error }
|
38
|
+
# ba.use :hint, wrap_with: { tag: :span, class: :hint }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
config.wrappers :horizontal_radio_and_checkboxes, tag: 'div', class: 'row' do |b|
|
43
|
+
b.use :html5
|
44
|
+
b.optional :readonly
|
45
|
+
|
46
|
+
b.wrapper :container_wrapper, tag: 'div', class: 'small-offset-3 small-9 columns' do |ba|
|
47
|
+
ba.wrapper :tag => 'label', :class => 'checkbox' do |bb|
|
48
|
+
bb.use :input
|
49
|
+
bb.use :label_text
|
50
|
+
end
|
12
51
|
|
13
|
-
|
14
|
-
|
15
|
-
|
52
|
+
ba.use :error, wrap_with: { tag: :small, class: :error }
|
53
|
+
# ba.use :hint, wrap_with: { tag: :span, class: :hint }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# Foundation does not provide a way to handle inline forms
|
58
|
+
# This wrapper can be used to create an inline form
|
59
|
+
# by hiding that labels on every screen sizes ('hidden-for-small-up').
|
60
|
+
#
|
61
|
+
# Note that you need to adapt this wrapper to your needs. If you need a 4
|
62
|
+
# columns form then change the wrapper class to 'small-3', if you need
|
63
|
+
# only two use 'small-6' and so on.
|
64
|
+
config.wrappers :inline_form, tag: 'div', class: 'column small-4', hint_class: :field_with_hint, error_class: :error do |b|
|
65
|
+
b.use :html5
|
66
|
+
b.use :placeholder
|
67
|
+
b.optional :maxlength
|
68
|
+
b.optional :pattern
|
69
|
+
b.optional :min_max
|
70
|
+
b.optional :readonly
|
71
|
+
|
72
|
+
b.use :label, class: 'hidden-for-small-up'
|
73
|
+
b.use :input
|
74
|
+
|
75
|
+
b.use :error, wrap_with: { tag: :small, class: :error }
|
76
|
+
# b.use :hint, wrap_with: { tag: :span, class: :hint }
|
77
|
+
end
|
78
|
+
|
79
|
+
# Examples of use:
|
80
|
+
# - wrapper_html: {class: 'row'}, custom_wrapper_html: {class: 'column small-12'}
|
81
|
+
# - custom_wrapper_html: {class: 'column small-3 end'}
|
82
|
+
config.wrappers :customizable_wrapper, tag: 'div', error_class: :error do |b|
|
83
|
+
b.use :html5
|
84
|
+
b.optional :readonly
|
85
|
+
|
86
|
+
b.wrapper :custom_wrapper, tag: :div do |ba|
|
87
|
+
ba.use :label_input
|
88
|
+
end
|
89
|
+
|
90
|
+
b.use :error, wrap_with: { tag: :small, class: :error }
|
91
|
+
# b.use :hint, wrap_with: { tag: :span, class: :hint }
|
16
92
|
end
|
17
93
|
|
18
94
|
# CSS class for buttons
|
19
95
|
config.button_class = 'button'
|
20
96
|
|
97
|
+
# Set this to div to make the checkbox and radio properly work
|
98
|
+
# otherwise simple_form adds a label tag instead of a div arround
|
99
|
+
# the nested label
|
100
|
+
config.item_wrapper_tag = :div
|
101
|
+
|
21
102
|
# CSS class to add for error notification helper.
|
22
103
|
config.error_notification_class = 'alert-box alert'
|
23
104
|
|
24
105
|
# The default wrapper to be used by the FormBuilder.
|
25
|
-
config.default_wrapper = :
|
106
|
+
config.default_wrapper = :vertical_form
|
26
107
|
end
|
@@ -10,7 +10,7 @@ en:
|
|
10
10
|
# html: '<abbr title="required">*</abbr>'
|
11
11
|
error_notification:
|
12
12
|
default_message: "Please review the problems below:"
|
13
|
-
#
|
13
|
+
# Examples
|
14
14
|
# labels:
|
15
15
|
# defaults:
|
16
16
|
# password: 'Password'
|
@@ -23,4 +23,9 @@ en:
|
|
23
23
|
# defaults:
|
24
24
|
# username: 'User name to sign in.'
|
25
25
|
# password: 'No special characters, please.'
|
26
|
-
|
26
|
+
# include_blanks:
|
27
|
+
# defaults:
|
28
|
+
# age: 'Rather not say'
|
29
|
+
# prompts:
|
30
|
+
# defaults:
|
31
|
+
# age: 'Select your age'
|