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