simple_form 3.0.1 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +149 -25
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +441 -107
  5. data/lib/generators/simple_form/install_generator.rb +4 -3
  6. data/lib/generators/simple_form/templates/README +4 -5
  7. data/lib/generators/simple_form/templates/_form.html.erb +2 -0
  8. data/lib/generators/simple_form/templates/_form.html.haml +2 -0
  9. data/lib/generators/simple_form/templates/_form.html.slim +1 -0
  10. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +48 -11
  11. data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +417 -23
  12. data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +101 -5
  13. data/lib/generators/simple_form/templates/config/locales/simple_form.en.yml +7 -2
  14. data/lib/simple_form/action_view_extensions/builder.rb +2 -0
  15. data/lib/simple_form/action_view_extensions/form_helper.rb +10 -3
  16. data/lib/simple_form/components/errors.rb +38 -3
  17. data/lib/simple_form/components/hints.rb +3 -2
  18. data/lib/simple_form/components/html5.rb +16 -5
  19. data/lib/simple_form/components/label_input.rb +21 -2
  20. data/lib/simple_form/components/labels.rb +22 -11
  21. data/lib/simple_form/components/maxlength.rb +9 -5
  22. data/lib/simple_form/components/min_max.rb +2 -1
  23. data/lib/simple_form/components/minlength.rb +38 -0
  24. data/lib/simple_form/components/pattern.rb +2 -1
  25. data/lib/simple_form/components/placeholders.rb +4 -3
  26. data/lib/simple_form/components/readonly.rb +2 -1
  27. data/lib/simple_form/components.rb +2 -0
  28. data/lib/simple_form/error_notification.rb +1 -0
  29. data/lib/simple_form/form_builder.rb +193 -80
  30. data/lib/simple_form/helpers/autofocus.rb +1 -0
  31. data/lib/simple_form/helpers/disabled.rb +1 -0
  32. data/lib/simple_form/helpers/readonly.rb +1 -0
  33. data/lib/simple_form/helpers/required.rb +1 -0
  34. data/lib/simple_form/helpers/validators.rb +2 -1
  35. data/lib/simple_form/helpers.rb +6 -5
  36. data/lib/simple_form/i18n_cache.rb +1 -0
  37. data/lib/simple_form/inputs/base.rb +57 -14
  38. data/lib/simple_form/inputs/block_input.rb +2 -1
  39. data/lib/simple_form/inputs/boolean_input.rb +39 -16
  40. data/lib/simple_form/inputs/collection_check_boxes_input.rb +2 -1
  41. data/lib/simple_form/inputs/collection_input.rb +37 -14
  42. data/lib/simple_form/inputs/collection_radio_buttons_input.rb +9 -13
  43. data/lib/simple_form/inputs/collection_select_input.rb +5 -2
  44. data/lib/simple_form/inputs/date_time_input.rb +24 -9
  45. data/lib/simple_form/inputs/file_input.rb +5 -2
  46. data/lib/simple_form/inputs/grouped_collection_select_input.rb +16 -3
  47. data/lib/simple_form/inputs/hidden_input.rb +5 -2
  48. data/lib/simple_form/inputs/numeric_input.rb +6 -4
  49. data/lib/simple_form/inputs/password_input.rb +6 -3
  50. data/lib/simple_form/inputs/priority_input.rb +5 -2
  51. data/lib/simple_form/inputs/range_input.rb +2 -1
  52. data/lib/simple_form/inputs/string_input.rb +6 -3
  53. data/lib/simple_form/inputs/text_input.rb +6 -3
  54. data/lib/simple_form/inputs.rb +1 -0
  55. data/lib/simple_form/map_type.rb +1 -0
  56. data/lib/simple_form/railtie.rb +8 -0
  57. data/lib/simple_form/tags.rb +7 -0
  58. data/lib/simple_form/version.rb +2 -1
  59. data/lib/simple_form/wrappers/builder.rb +7 -6
  60. data/lib/simple_form/wrappers/leaf.rb +29 -0
  61. data/lib/simple_form/wrappers/many.rb +7 -6
  62. data/lib/simple_form/wrappers/root.rb +3 -1
  63. data/lib/simple_form/wrappers/single.rb +7 -4
  64. data/lib/simple_form/wrappers.rb +2 -0
  65. data/lib/simple_form.rb +117 -18
  66. data/test/action_view_extensions/builder_test.rb +42 -41
  67. data/test/action_view_extensions/form_helper_test.rb +36 -16
  68. data/test/components/custom_components_test.rb +62 -0
  69. data/test/components/label_test.rb +70 -41
  70. data/test/form_builder/association_test.rb +79 -37
  71. data/test/form_builder/button_test.rb +11 -10
  72. data/test/form_builder/error_notification_test.rb +2 -1
  73. data/test/form_builder/error_test.rb +173 -24
  74. data/test/form_builder/general_test.rb +171 -73
  75. data/test/form_builder/hint_test.rb +24 -18
  76. data/test/form_builder/input_field_test.rb +132 -56
  77. data/test/form_builder/label_test.rb +68 -13
  78. data/test/form_builder/wrapper_test.rb +190 -22
  79. data/test/generators/simple_form_generator_test.rb +8 -7
  80. data/test/inputs/boolean_input_test.rb +89 -6
  81. data/test/inputs/collection_check_boxes_input_test.rb +109 -25
  82. data/test/inputs/collection_radio_buttons_input_test.rb +168 -54
  83. data/test/inputs/collection_select_input_test.rb +183 -77
  84. data/test/inputs/datetime_input_test.rb +131 -50
  85. data/test/inputs/disabled_test.rb +16 -15
  86. data/test/inputs/discovery_test.rb +58 -6
  87. data/test/inputs/file_input_test.rb +3 -2
  88. data/test/inputs/general_test.rb +23 -22
  89. data/test/inputs/grouped_collection_select_input_test.rb +54 -17
  90. data/test/inputs/hidden_input_test.rb +5 -4
  91. data/test/inputs/numeric_input_test.rb +48 -44
  92. data/test/inputs/priority_input_test.rb +23 -14
  93. data/test/inputs/readonly_test.rb +20 -19
  94. data/test/inputs/required_test.rb +58 -13
  95. data/test/inputs/string_input_test.rb +62 -33
  96. data/test/inputs/text_input_test.rb +20 -7
  97. data/test/simple_form_test.rb +9 -0
  98. data/test/support/discovery_inputs.rb +33 -2
  99. data/test/support/misc_helpers.rb +113 -5
  100. data/test/support/mock_controller.rb +7 -1
  101. data/test/support/models.rb +137 -37
  102. data/test/test_helper.rb +15 -1
  103. metadata +25 -33
@@ -1,15 +1,16 @@
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
7
  class_option :template_engine, desc: 'Template engine to be invoked (erb, haml or slim).'
7
- class_option :bootstrap, type: :boolean, desc: 'Add the Twitter Bootstrap wrappers to the SimpleForm initializer.'
8
- class_option :foundation, type: :boolean, desc: 'Add the Zurb Foundation 3 wrappers to the SimpleForm initializer.'
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.'
9
10
 
10
11
  def info_bootstrap
11
12
  return if options.bootstrap? || options.foundation?
12
- puts "SimpleForm 2 supports Twitter Bootstrap and Zurb Foundation 3. If you want "\
13
+ puts "SimpleForm 3 supports Bootstrap and Zurb Foundation 5. If you want "\
13
14
  "a configuration that is compatible with one of these frameworks, then please " \
14
15
  "re-run this generator with --bootstrap or --foundation as an option."
15
16
  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://twitter.github.com/bootstrap.
4
+ application, you can get it on http://getbootstrap.com/.
5
5
 
6
- Inside your views, use the 'simple_form_for' with one of the Bootstrap form
7
- classes, '.form-horizontal', '.form-inline', '.form-search' or
8
- '.form-vertical', as the following:
6
+ Inside your views, use the 'simple_form_for' with the Bootstrap form
7
+ class, '.form-inline', as the following:
9
8
 
10
- = simple_form_for(@user, html: {class: 'form-horizontal' }) do |form|
9
+ = simple_form_for(@user, html: { class: 'form-inline' }) do |form|
11
10
 
12
11
  ===============================================================================
@@ -1,5 +1,7 @@
1
+ <%# frozen_string_literal: true %>
1
2
  <%%= simple_form_for(@<%= singular_table_name %>) do |f| %>
2
3
  <%%= f.error_notification %>
4
+ <%%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %>
3
5
 
4
6
  <div class="form-inputs">
5
7
  <%- attributes.each do |attribute| -%>
@@ -1,5 +1,7 @@
1
+ -# frozen_string_literal: true
1
2
  = simple_form_for(@<%= singular_table_name %>) do |f|
2
3
  = f.error_notification
4
+ = f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present?
3
5
 
4
6
  .form-inputs
5
7
  <%- attributes.each do |attribute| -%>
@@ -1,5 +1,6 @@
1
1
  = simple_form_for(@<%= singular_table_name %>) do |f|
2
2
  = f.error_notification
3
+ = f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present?
3
4
 
4
5
  .form-inputs
5
6
  <%- attributes.each do |attribute| -%>
@@ -1,3 +1,11 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Uncomment this and change the path if necessary to include your own
4
+ # components.
5
+ # See https://github.com/plataformatec/simple_form#custom-components to know
6
+ # more about custom components.
7
+ # Dir[Rails.root.join('lib/components/**/*.rb')].each { |f| require f }
8
+ #
1
9
  # Use this setup block to configure all options available in SimpleForm.
2
10
  SimpleForm.setup do |config|
3
11
  # Wrappers are used by the form builder to generate a
@@ -6,7 +14,7 @@ SimpleForm.setup do |config|
6
14
  # stack. The options given below are used to wrap the
7
15
  # whole input.
8
16
  config.wrappers :default, class: :input,
9
- hint_class: :field_with_hint, error_class: :field_with_errors do |b|
17
+ hint_class: :field_with_hint, error_class: :field_with_errors, valid_class: :field_without_errors do |b|
10
18
  ## Extensions enabled by default
11
19
  # Any of these extensions can be disabled for a
12
20
  # given input by passing: `f.input EXTENSION_NAME => false`.
@@ -22,14 +30,18 @@ SimpleForm.setup do |config|
22
30
  b.use :placeholder
23
31
 
24
32
  ## Optional extensions
25
- # They are disabled unless you pass `f.input EXTENSION_NAME => :lookup`
33
+ # They are disabled unless you pass `f.input EXTENSION_NAME => true`
26
34
  # to the input. If so, they will retrieve the values from the model
27
- # if any exists. If you want to enable the lookup for any of those
35
+ # if any exists. If you want to enable any of those
28
36
  # extensions by default, you can change `b.optional` to `b.use`.
29
37
 
30
38
  # Calculates maxlength from length validations for string inputs
39
+ # and/or database column lengths
31
40
  b.optional :maxlength
32
41
 
42
+ # Calculate minlength from length validations for string inputs
43
+ b.optional :minlength
44
+
33
45
  # Calculates pattern from format validations for string inputs
34
46
  b.optional :pattern
35
47
 
@@ -40,9 +52,16 @@ SimpleForm.setup do |config|
40
52
  b.optional :readonly
41
53
 
42
54
  ## Inputs
55
+ # b.use :input, class: 'input', error_class: 'is-invalid', valid_class: 'is-valid'
43
56
  b.use :label_input
44
57
  b.use :hint, wrap_with: { tag: :span, class: :hint }
45
58
  b.use :error, wrap_with: { tag: :span, class: :error }
59
+
60
+ ## full_messages_for
61
+ # If you want to display the full error message for the attribute, you can
62
+ # use the component :full_error, like:
63
+ #
64
+ # b.use :full_error, wrap_with: { tag: :span, class: :error }
46
65
  end
47
66
 
48
67
  # The default wrapper to be used by the FormBuilder.
@@ -66,7 +85,7 @@ SimpleForm.setup do |config|
66
85
  config.error_notification_tag = :div
67
86
 
68
87
  # CSS class to add for error notification helper.
69
- config.error_notification_class = 'alert alert-error'
88
+ config.error_notification_class = 'error_notification'
70
89
 
71
90
  # ID to add for error notification helper.
72
91
  # config.error_notification_id = nil
@@ -84,21 +103,21 @@ SimpleForm.setup do |config|
84
103
  # config.collection_wrapper_class = nil
85
104
 
86
105
  # You can wrap each item in a collection of radio/check boxes with a tag,
87
- # defaulting to :span. Please note that when using :boolean_style = :nested,
88
- # SimpleForm will force this option to be a label.
106
+ # defaulting to :span.
89
107
  # config.item_wrapper_tag = :span
90
108
 
91
109
  # You can define a class to use in all item wrappers. Defaulting to none.
92
110
  # config.item_wrapper_class = nil
93
111
 
94
112
  # How the label text should be generated altogether with the required text.
95
- # config.label_text = lambda { |label, required| "#{required} #{label}" }
113
+ # config.label_text = lambda { |label, required, explicit_label| "#{required} #{label}" }
96
114
 
97
115
  # You can define the class to use on all labels. Default is nil.
98
- config.label_class = 'control-label'
116
+ # config.label_class = nil
99
117
 
100
- # You can define the class to use on all forms. Default is simple_form.
101
- # config.form_class = :simple_form
118
+ # You can define the default class to be used on forms. Can be overriden
119
+ # with `html: { :class }`. Defaulting to none.
120
+ # config.default_form_class = nil
102
121
 
103
122
  # You can define which elements should obtain additional classes
104
123
  # config.generate_additional_classes_for = [:wrapper, :label, :input]
@@ -114,7 +133,7 @@ SimpleForm.setup do |config|
114
133
  config.browser_validations = false
115
134
 
116
135
  # Collection of methods to detect if a file type was given.
117
- # config.file_methods = [ :mounted_as, :file?, :public_filename ]
136
+ # config.file_methods = [ :mounted_as, :file?, :public_filename :attached? ]
118
137
 
119
138
  # Custom mappings for input types. This should be a hash containing a regexp
120
139
  # to match as key, and the input type that will be used when the field name
@@ -125,6 +144,10 @@ SimpleForm.setup do |config|
125
144
  # type as key and the wrapper that will be used for all inputs with specified type.
126
145
  # config.wrapper_mappings = { string: :prepend }
127
146
 
147
+ # Namespaces where SimpleForm should look for custom input classes that
148
+ # override default inputs.
149
+ # config.custom_inputs_namespaces << "CustomInputs"
150
+
128
151
  # Default priority for time_zone inputs.
129
152
  # config.time_zone_priority = nil
130
153
 
@@ -142,4 +165,18 @@ SimpleForm.setup do |config|
142
165
 
143
166
  # Default class for inputs
144
167
  # config.input_class = nil
168
+
169
+ # Define the default class of the input wrapper of the boolean input.
170
+ config.boolean_label_class = 'checkbox'
171
+
172
+ # Defines if the default input wrapper class should be included in radio
173
+ # collection wrappers.
174
+ # config.include_default_input_wrapper_class = true
175
+
176
+ # Defines which i18n scope will be used in Simple Form.
177
+ # config.i18n_scope = 'simple_form'
178
+
179
+ # Defines validation classes to the input_field. By default it's nil.
180
+ # config.input_field_valid_class = 'is-valid'
181
+ # config.input_field_error_class = 'is-invalid'
145
182
  end
@@ -1,45 +1,439 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Please do not make direct changes to this file!
4
+ # This generator is maintained by the community around simple_form-bootstrap:
5
+ # https://github.com/rafaelfranca/simple_form-bootstrap
6
+ # All future development, tests, and organization should happen there.
7
+ # Background history: https://github.com/plataformatec/simple_form/issues/1561
8
+
9
+ # Uncomment this and change the path if necessary to include your own
10
+ # components.
11
+ # See https://github.com/plataformatec/simple_form#custom-components
12
+ # to know more about custom components.
13
+ # Dir[Rails.root.join('lib/components/**/*.rb')].each { |f| require f }
14
+
1
15
  # Use this setup block to configure all options available in SimpleForm.
2
16
  SimpleForm.setup do |config|
3
- config.wrappers :bootstrap, tag: 'div', class: 'control-group', error_class: 'error' do |b|
17
+ # Default class for buttons
18
+ config.button_class = 'btn'
19
+
20
+ # Define the default class of the input wrapper of the boolean input.
21
+ config.boolean_label_class = 'form-check-label'
22
+
23
+ # How the label text should be generated altogether with the required text.
24
+ config.label_text = lambda { |label, required, explicit_label| "#{label} #{required}" }
25
+
26
+ # Define the way to render check boxes / radio buttons with labels.
27
+ config.boolean_style = :inline
28
+
29
+ # You can wrap each item in a collection of radio/check boxes with a tag
30
+ config.item_wrapper_tag = :div
31
+
32
+ # Defines if the default input wrapper class should be included in radio
33
+ # collection wrappers.
34
+ config.include_default_input_wrapper_class = false
35
+
36
+ # CSS class to add for error notification helper.
37
+ config.error_notification_class = 'alert alert-danger'
38
+
39
+ # Method used to tidy up errors. Specify any Rails Array method.
40
+ # :first lists the first message for each field.
41
+ # :to_sentence to list all errors for each field.
42
+ config.error_method = :to_sentence
43
+
44
+ # add validation classes to `input_field`
45
+ config.input_field_error_class = 'is-invalid'
46
+ config.input_field_valid_class = 'is-valid'
47
+
48
+
49
+ # vertical forms
50
+ #
51
+ # vertical default_wrapper
52
+ config.wrappers :vertical_form, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
53
+ b.use :html5
54
+ b.use :placeholder
55
+ b.optional :maxlength
56
+ b.optional :minlength
57
+ b.optional :pattern
58
+ b.optional :min_max
59
+ b.optional :readonly
60
+ b.use :label, class: 'form-control-label'
61
+ b.use :input, class: 'form-control', error_class: 'is-invalid', valid_class: 'is-valid'
62
+ b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback' }
63
+ b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
64
+ end
65
+
66
+ # vertical input for boolean
67
+ config.wrappers :vertical_boolean, tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
68
+ b.use :html5
69
+ b.optional :readonly
70
+ b.wrapper :form_check_wrapper, tag: 'div', class: 'form-check' do |bb|
71
+ bb.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid'
72
+ bb.use :label, class: 'form-check-label'
73
+ bb.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback' }
74
+ bb.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
75
+ end
76
+ end
77
+
78
+ # vertical input for radio buttons and check boxes
79
+ config.wrappers :vertical_collection, item_wrapper_class: 'form-check', tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
80
+ b.use :html5
81
+ b.optional :readonly
82
+ b.wrapper :legend_tag, tag: 'legend', class: 'col-form-label pt-0' do |ba|
83
+ ba.use :label_text
84
+ end
85
+ b.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid'
86
+ b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
87
+ b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
88
+ end
89
+
90
+ # vertical input for inline radio buttons and check boxes
91
+ config.wrappers :vertical_collection_inline, item_wrapper_class: 'form-check form-check-inline', tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
92
+ b.use :html5
93
+ b.optional :readonly
94
+ b.wrapper :legend_tag, tag: 'legend', class: 'col-form-label pt-0' do |ba|
95
+ ba.use :label_text
96
+ end
97
+ b.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid'
98
+ b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
99
+ b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
100
+ end
101
+
102
+ # vertical file input
103
+ config.wrappers :vertical_file, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
4
104
  b.use :html5
5
105
  b.use :placeholder
106
+ b.optional :maxlength
107
+ b.optional :minlength
108
+ b.optional :readonly
6
109
  b.use :label
7
- b.wrapper tag: 'div', class: 'controls' do |ba|
8
- ba.use :input
9
- ba.use :error, wrap_with: { tag: 'span', class: 'help-inline' }
10
- ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
110
+ b.use :input, class: 'form-control-file', error_class: 'is-invalid', valid_class: 'is-valid'
111
+ b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
112
+ b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
113
+ end
114
+
115
+ # vertical multi select
116
+ config.wrappers :vertical_multi_select, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
117
+ b.use :html5
118
+ b.optional :readonly
119
+ b.use :label, class: 'form-control-label'
120
+ b.wrapper tag: 'div', class: 'd-flex flex-row justify-content-between align-items-center' do |ba|
121
+ ba.use :input, class: 'form-control mx-1', error_class: 'is-invalid', valid_class: 'is-valid'
11
122
  end
123
+ b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
124
+ b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
12
125
  end
13
126
 
14
- config.wrappers :prepend, tag: 'div', class: "control-group", error_class: 'error' do |b|
127
+ # vertical range input
128
+ config.wrappers :vertical_range, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
15
129
  b.use :html5
16
130
  b.use :placeholder
131
+ b.optional :readonly
132
+ b.optional :step
17
133
  b.use :label
18
- b.wrapper tag: 'div', class: 'controls' do |input|
19
- input.wrapper tag: 'div', class: 'input-prepend' do |prepend|
20
- prepend.use :input
134
+ b.use :input, class: 'form-control-range', error_class: 'is-invalid', valid_class: 'is-valid'
135
+ b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
136
+ b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
137
+ end
138
+
139
+
140
+ # horizontal forms
141
+ #
142
+ # horizontal default_wrapper
143
+ config.wrappers :horizontal_form, tag: 'div', class: 'form-group row', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
144
+ b.use :html5
145
+ b.use :placeholder
146
+ b.optional :maxlength
147
+ b.optional :minlength
148
+ b.optional :pattern
149
+ b.optional :min_max
150
+ b.optional :readonly
151
+ b.use :label, class: 'col-sm-3 col-form-label'
152
+ b.wrapper :grid_wrapper, tag: 'div', class: 'col-sm-9' do |ba|
153
+ ba.use :input, class: 'form-control', error_class: 'is-invalid', valid_class: 'is-valid'
154
+ ba.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback' }
155
+ ba.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
156
+ end
157
+ end
158
+
159
+ # horizontal input for boolean
160
+ config.wrappers :horizontal_boolean, tag: 'div', class: 'form-group row', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
161
+ b.use :html5
162
+ b.optional :readonly
163
+ b.wrapper tag: 'label', class: 'col-sm-3' do |ba|
164
+ ba.use :label_text
165
+ end
166
+ b.wrapper :grid_wrapper, tag: 'div', class: 'col-sm-9' do |wr|
167
+ wr.wrapper :form_check_wrapper, tag: 'div', class: 'form-check' do |bb|
168
+ bb.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid'
169
+ bb.use :label, class: 'form-check-label'
170
+ bb.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
171
+ bb.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
21
172
  end
22
- input.use :hint, wrap_with: { tag: 'span', class: 'help-block' }
23
- input.use :error, wrap_with: { tag: 'span', class: 'help-inline' }
24
173
  end
25
174
  end
26
175
 
27
- config.wrappers :append, tag: 'div', class: "control-group", error_class: 'error' do |b|
176
+ # horizontal input for radio buttons and check boxes
177
+ config.wrappers :horizontal_collection, item_wrapper_class: 'form-check', tag: 'div', class: 'form-group row', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
178
+ b.use :html5
179
+ b.optional :readonly
180
+ b.use :label, class: 'col-sm-3 form-control-label'
181
+ b.wrapper :grid_wrapper, tag: 'div', class: 'col-sm-9' do |ba|
182
+ ba.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid'
183
+ ba.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
184
+ ba.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
185
+ end
186
+ end
187
+
188
+ # horizontal input for inline radio buttons and check boxes
189
+ config.wrappers :horizontal_collection_inline, item_wrapper_class: 'form-check form-check-inline', tag: 'div', class: 'form-group row', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
190
+ b.use :html5
191
+ b.optional :readonly
192
+ b.use :label, class: 'col-sm-3 form-control-label'
193
+ b.wrapper :grid_wrapper, tag: 'div', class: 'col-sm-9' do |ba|
194
+ ba.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid'
195
+ ba.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
196
+ ba.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
197
+ end
198
+ end
199
+
200
+ # horizontal file input
201
+ config.wrappers :horizontal_file, tag: 'div', class: 'form-group row', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
28
202
  b.use :html5
29
203
  b.use :placeholder
30
- b.use :label
31
- b.wrapper tag: 'div', class: 'controls' do |input|
32
- input.wrapper tag: 'div', class: 'input-append' do |append|
33
- append.use :input
204
+ b.optional :maxlength
205
+ b.optional :minlength
206
+ b.optional :readonly
207
+ b.use :label, class: 'col-sm-3 form-control-label'
208
+ b.wrapper :grid_wrapper, tag: 'div', class: 'col-sm-9' do |ba|
209
+ ba.use :input, error_class: 'is-invalid', valid_class: 'is-valid'
210
+ ba.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
211
+ ba.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
212
+ end
213
+ end
214
+
215
+ # horizontal multi select
216
+ config.wrappers :horizontal_multi_select, tag: 'div', class: 'form-group row', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
217
+ b.use :html5
218
+ b.optional :readonly
219
+ b.use :label, class: 'col-sm-3 control-label'
220
+ b.wrapper :grid_wrapper, tag: 'div', class: 'col-sm-9' do |ba|
221
+ ba.wrapper tag: 'div', class: 'd-flex flex-row justify-content-between align-items-center' do |bb|
222
+ bb.use :input, class: 'form-control mx-1', error_class: 'is-invalid', valid_class: 'is-valid'
34
223
  end
35
- input.use :hint, wrap_with: { tag: 'span', class: 'help-block' }
36
- input.use :error, wrap_with: { tag: 'span', class: 'help-inline' }
224
+ ba.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
225
+ ba.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
226
+ end
227
+ end
228
+
229
+ # horizontal range input
230
+ config.wrappers :horizontal_range, tag: 'div', class: 'form-group row', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
231
+ b.use :html5
232
+ b.use :placeholder
233
+ b.optional :readonly
234
+ b.optional :step
235
+ b.use :label, class: 'col-sm-3 form-control-label'
236
+ b.wrapper :grid_wrapper, tag: 'div', class: 'col-sm-9' do |ba|
237
+ ba.use :input, class: 'form-control-range', error_class: 'is-invalid', valid_class: 'is-valid'
238
+ ba.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
239
+ ba.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
240
+ end
241
+ end
242
+
243
+
244
+ # inline forms
245
+ #
246
+ # inline default_wrapper
247
+ config.wrappers :inline_form, tag: 'span', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
248
+ b.use :html5
249
+ b.use :placeholder
250
+ b.optional :maxlength
251
+ b.optional :minlength
252
+ b.optional :pattern
253
+ b.optional :min_max
254
+ b.optional :readonly
255
+ b.use :label, class: 'sr-only'
256
+
257
+ b.use :input, class: 'form-control', error_class: 'is-invalid', valid_class: 'is-valid'
258
+ b.use :error, wrap_with: { tag: 'div', class: 'invalid-feedback' }
259
+ b.optional :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
260
+ end
261
+
262
+ # inline input for boolean
263
+ config.wrappers :inline_boolean, tag: 'span', class: 'form-check flex-wrap justify-content-start mr-sm-2', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
264
+ b.use :html5
265
+ b.optional :readonly
266
+ b.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid'
267
+ b.use :label, class: 'form-check-label'
268
+ b.use :error, wrap_with: { tag: 'div', class: 'invalid-feedback' }
269
+ b.optional :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
270
+ end
271
+
272
+
273
+ # bootstrap custom forms
274
+ #
275
+ # custom input for boolean
276
+ config.wrappers :custom_boolean, tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
277
+ b.use :html5
278
+ b.optional :readonly
279
+ b.wrapper :form_check_wrapper, tag: 'div', class: 'custom-control custom-checkbox' do |bb|
280
+ bb.use :input, class: 'custom-control-input', error_class: 'is-invalid', valid_class: 'is-valid'
281
+ bb.use :label, class: 'custom-control-label'
282
+ bb.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback' }
283
+ bb.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
284
+ end
285
+ end
286
+
287
+ config.wrappers :custom_boolean_switch, tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
288
+ b.use :html5
289
+ b.optional :readonly
290
+ b.wrapper :form_check_wrapper, tag: 'div', class: 'custom-control custom-checkbox-switch' do |bb|
291
+ bb.use :input, class: 'custom-control-input', error_class: 'is-invalid', valid_class: 'is-valid'
292
+ bb.use :label, class: 'custom-control-label'
293
+ bb.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback' }
294
+ bb.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
295
+ end
296
+ end
297
+
298
+ # custom input for radio buttons and check boxes
299
+ config.wrappers :custom_collection, item_wrapper_class: 'custom-control', tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
300
+ b.use :html5
301
+ b.optional :readonly
302
+ b.wrapper :legend_tag, tag: 'legend', class: 'col-form-label pt-0' do |ba|
303
+ ba.use :label_text
304
+ end
305
+ b.use :input, class: 'custom-control-input', error_class: 'is-invalid', valid_class: 'is-valid'
306
+ b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
307
+ b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
308
+ end
309
+
310
+ # custom input for inline radio buttons and check boxes
311
+ config.wrappers :custom_collection_inline, item_wrapper_class: 'custom-control custom-control-inline', tag: 'fieldset', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
312
+ b.use :html5
313
+ b.optional :readonly
314
+ b.wrapper :legend_tag, tag: 'legend', class: 'col-form-label pt-0' do |ba|
315
+ ba.use :label_text
316
+ end
317
+ b.use :input, class: 'custom-control-input', error_class: 'is-invalid', valid_class: 'is-valid'
318
+ b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
319
+ b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
320
+ end
321
+
322
+ # custom file input
323
+ config.wrappers :custom_file, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
324
+ b.use :html5
325
+ b.use :placeholder
326
+ b.optional :maxlength
327
+ b.optional :minlength
328
+ b.optional :readonly
329
+ b.use :label, class: 'form-control-label'
330
+ b.wrapper :custom_file_wrapper, tag: 'div', class: 'custom-file' do |ba|
331
+ ba.use :input, class: 'custom-file-input', error_class: 'is-invalid', valid_class: 'is-valid'
332
+ ba.use :label, class: 'custom-file-label'
333
+ ba.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback' }
37
334
  end
335
+ b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
336
+ end
337
+
338
+ # custom multi select
339
+ config.wrappers :custom_multi_select, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
340
+ b.use :html5
341
+ b.optional :readonly
342
+ b.use :label, class: 'form-control-label'
343
+ b.wrapper tag: 'div', class: 'd-flex flex-row justify-content-between align-items-center' do |ba|
344
+ ba.use :input, class: 'custom-select mx-1', error_class: 'is-invalid', valid_class: 'is-valid'
345
+ end
346
+ b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
347
+ b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
348
+ end
349
+
350
+ # custom range input
351
+ config.wrappers :custom_range, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
352
+ b.use :html5
353
+ b.use :placeholder
354
+ b.optional :readonly
355
+ b.optional :step
356
+ b.use :label, class: 'form-control-label'
357
+ b.use :input, class: 'custom-range', error_class: 'is-invalid', valid_class: 'is-valid'
358
+ b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
359
+ b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
360
+ end
361
+
362
+
363
+ # Input Group - custom component
364
+ # see example app and config at https://github.com/rafaelfranca/simple_form-bootstrap
365
+ # config.wrappers :input_group, tag: 'div', class: 'form-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
366
+ # b.use :html5
367
+ # b.use :placeholder
368
+ # b.optional :maxlength
369
+ # b.optional :minlength
370
+ # b.optional :pattern
371
+ # b.optional :min_max
372
+ # b.optional :readonly
373
+ # b.use :label, class: 'form-control-label'
374
+ # b.wrapper :input_group_tag, tag: 'div', class: 'input-group' do |ba|
375
+ # ba.optional :prepend
376
+ # ba.use :input, class: 'form-control', error_class: 'is-invalid', valid_class: 'is-valid'
377
+ # ba.optional :append
378
+ # end
379
+ # b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback d-block' }
380
+ # b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
381
+ # end
382
+
383
+
384
+ # Floating Labels form
385
+ #
386
+ # floating labels default_wrapper
387
+ config.wrappers :floating_labels_form, tag: 'div', class: 'form-label-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
388
+ b.use :html5
389
+ b.use :placeholder
390
+ b.optional :maxlength
391
+ b.optional :minlength
392
+ b.optional :pattern
393
+ b.optional :min_max
394
+ b.optional :readonly
395
+ b.use :input, class: 'form-control', error_class: 'is-invalid', valid_class: 'is-valid'
396
+ b.use :label, class: 'form-control-label'
397
+ b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback' }
398
+ b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
399
+ end
400
+
401
+ # custom multi select
402
+ config.wrappers :floating_labels_select, tag: 'div', class: 'form-label-group', error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
403
+ b.use :html5
404
+ b.optional :readonly
405
+ b.use :input, class: 'custom-select custom-select-lg', error_class: 'is-invalid', valid_class: 'is-valid'
406
+ b.use :label, class: 'form-control-label'
407
+ b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback' }
408
+ b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
38
409
  end
39
410
 
40
- # Wrappers for forms and inputs using the Twitter Bootstrap toolkit.
41
- # Check the Bootstrap docs (http://twitter.github.com/bootstrap)
42
- # to learn about the different styles for forms and inputs,
43
- # buttons and other elements.
44
- config.default_wrapper = :bootstrap
411
+
412
+ # The default wrapper to be used by the FormBuilder.
413
+ config.default_wrapper = :vertical_form
414
+
415
+ # Custom wrappers for input types. This should be a hash containing an input
416
+ # type as key and the wrapper that will be used for all inputs with specified type.
417
+ config.wrapper_mappings = {
418
+ boolean: :vertical_boolean,
419
+ check_boxes: :vertical_collection,
420
+ date: :vertical_multi_select,
421
+ datetime: :vertical_multi_select,
422
+ file: :vertical_file,
423
+ radio_buttons: :vertical_collection,
424
+ range: :vertical_range,
425
+ time: :vertical_multi_select
426
+ }
427
+
428
+ # enable custom form wrappers
429
+ # config.wrapper_mappings = {
430
+ # boolean: :custom_boolean,
431
+ # check_boxes: :custom_collection,
432
+ # date: :custom_multi_select,
433
+ # datetime: :custom_multi_select,
434
+ # file: :custom_file,
435
+ # radio_buttons: :custom_collection,
436
+ # range: :custom_range,
437
+ # time: :custom_multi_select
438
+ # }
45
439
  end