simple_form 2.1.3 → 3.0.0.rc
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -50
- data/README.md +140 -116
- data/lib/generators/simple_form/install_generator.rb +4 -4
- data/lib/generators/simple_form/templates/README +2 -2
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +13 -13
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +16 -16
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +3 -3
- data/lib/simple_form/action_view_extensions/builder.rb +1 -320
- data/lib/simple_form/action_view_extensions/form_helper.rb +2 -9
- data/lib/simple_form/components/errors.rb +1 -7
- data/lib/simple_form/components/hints.rb +2 -7
- data/lib/simple_form/components/html5.rb +5 -2
- data/lib/simple_form/components/labels.rb +4 -4
- data/lib/simple_form/components/maxlength.rb +1 -8
- data/lib/simple_form/components/pattern.rb +2 -2
- data/lib/simple_form/components.rb +1 -1
- data/lib/simple_form/error_notification.rb +2 -2
- data/lib/simple_form/form_builder.rb +148 -50
- data/lib/simple_form/helpers.rb +1 -1
- data/lib/simple_form/inputs/base.rb +3 -10
- data/lib/simple_form/inputs/block_input.rb +1 -1
- data/lib/simple_form/inputs/boolean_input.rb +6 -6
- data/lib/simple_form/inputs/collection_input.rb +7 -7
- data/lib/simple_form/inputs/numeric_input.rb +0 -6
- data/lib/simple_form/inputs/password_input.rb +0 -1
- data/lib/simple_form/inputs/string_input.rb +0 -1
- data/lib/simple_form/railtie.rb +7 -0
- data/lib/simple_form/tags.rb +61 -0
- data/lib/simple_form/version.rb +1 -1
- data/lib/simple_form/wrappers/builder.rb +5 -29
- data/lib/simple_form/wrappers/many.rb +1 -1
- data/lib/simple_form/wrappers/root.rb +1 -1
- data/lib/simple_form/wrappers.rb +1 -1
- data/lib/simple_form.rb +39 -47
- data/test/action_view_extensions/builder_test.rb +75 -95
- data/test/action_view_extensions/form_helper_test.rb +25 -16
- data/test/components/label_test.rb +46 -46
- data/test/form_builder/association_test.rb +39 -29
- data/test/form_builder/button_test.rb +4 -4
- data/test/form_builder/error_notification_test.rb +8 -8
- data/test/form_builder/error_test.rb +18 -65
- data/test/form_builder/general_test.rb +60 -74
- data/test/form_builder/hint_test.rb +23 -29
- data/test/form_builder/input_field_test.rb +12 -12
- data/test/form_builder/label_test.rb +6 -16
- data/test/form_builder/wrapper_test.rb +21 -21
- data/test/inputs/boolean_input_test.rb +23 -35
- data/test/inputs/collection_check_boxes_input_test.rb +61 -55
- data/test/inputs/collection_radio_buttons_input_test.rb +76 -79
- data/test/inputs/collection_select_input_test.rb +70 -51
- data/test/inputs/datetime_input_test.rb +17 -11
- data/test/inputs/disabled_test.rb +10 -10
- data/test/inputs/discovery_test.rb +4 -4
- data/test/inputs/file_input_test.rb +1 -1
- data/test/inputs/general_test.rb +12 -12
- data/test/inputs/grouped_collection_select_input_test.rb +20 -20
- data/test/inputs/hidden_input_test.rb +3 -2
- data/test/inputs/numeric_input_test.rb +3 -3
- data/test/inputs/priority_input_test.rb +9 -3
- data/test/inputs/readonly_test.rb +12 -12
- data/test/inputs/required_test.rb +5 -5
- data/test/inputs/string_input_test.rb +15 -25
- data/test/inputs/text_input_test.rb +1 -1
- data/test/support/misc_helpers.rb +46 -24
- data/test/support/mock_controller.rb +6 -6
- data/test/support/models.rb +62 -64
- data/test/test_helper.rb +20 -24
- metadata +37 -23
- data/lib/simple_form/core_ext/hash.rb +0 -16
|
@@ -12,18 +12,18 @@ module SimpleForm
|
|
|
12
12
|
# b.optional :placeholder
|
|
13
13
|
#
|
|
14
14
|
# # Use a component with specific wrapper options
|
|
15
|
-
# b.use :error, :
|
|
15
|
+
# b.use :error, wrap_with: { tag: "span", class: "error" }
|
|
16
16
|
#
|
|
17
17
|
# # Use a set of components by wrapping them in a tag+class.
|
|
18
|
-
# b.wrapper :
|
|
18
|
+
# b.wrapper tag: "div", class: "another" do |ba|
|
|
19
19
|
# ba.use :label
|
|
20
20
|
# ba.use :input
|
|
21
21
|
# end
|
|
22
22
|
#
|
|
23
23
|
# # Use a set of components by wrapping them in a tag+class.
|
|
24
24
|
# # This wrapper is identified by :label_input, which means it can
|
|
25
|
-
# # be turned off on demand with `f.input :name, :
|
|
26
|
-
# b.wrapper :label_input, :
|
|
25
|
+
# # be turned off on demand with `f.input :name, label_input: false`
|
|
26
|
+
# b.wrapper :label_input, tag: "div", class: "another" do |ba|
|
|
27
27
|
# ba.use :label
|
|
28
28
|
# ba.use :input
|
|
29
29
|
# end
|
|
@@ -32,7 +32,7 @@ module SimpleForm
|
|
|
32
32
|
# The builder also accepts default options at the root level. This is usually
|
|
33
33
|
# used if you want a component to be disabled by default:
|
|
34
34
|
#
|
|
35
|
-
# config.wrappers :
|
|
35
|
+
# config.wrappers hint: false do |b|
|
|
36
36
|
# b.use :hint
|
|
37
37
|
# b.use :label_input
|
|
38
38
|
# end
|
|
@@ -46,18 +46,6 @@ module SimpleForm
|
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
def use(name, options=nil, &block)
|
|
49
|
-
if block_given?
|
|
50
|
-
ActiveSupport::Deprecation.warn "Passing a block to use is deprecated. " \
|
|
51
|
-
"Please use wrapper instead of use."
|
|
52
|
-
return wrapper(name, options, &block)
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
if options && options.keys != [:wrap_with]
|
|
56
|
-
ActiveSupport::Deprecation.warn "Passing :tag, :class and others to use is deprecated. " \
|
|
57
|
-
"Please invoke b.use #{name.inspect}, :wrap_with => #{options.inspect} instead."
|
|
58
|
-
options = { :wrap_with => options }
|
|
59
|
-
end
|
|
60
|
-
|
|
61
49
|
if options && wrapper = options[:wrap_with]
|
|
62
50
|
@components << Single.new(name, wrapper)
|
|
63
51
|
else
|
|
@@ -66,18 +54,6 @@ module SimpleForm
|
|
|
66
54
|
end
|
|
67
55
|
|
|
68
56
|
def optional(name, options=nil, &block)
|
|
69
|
-
if block_given?
|
|
70
|
-
ActiveSupport::Deprecation.warn "Passing a block to optional is deprecated. " \
|
|
71
|
-
"Please use wrapper instead of optional."
|
|
72
|
-
return wrapper(name, options, &block)
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
if options && options.keys != [:wrap_with]
|
|
76
|
-
ActiveSupport::Deprecation.warn "Passing :tag, :class and others to optional is deprecated. " \
|
|
77
|
-
"Please invoke b.optional #{name.inspect}, :wrap_with => #{options.inspect} instead."
|
|
78
|
-
options = { :wrap_with => options }
|
|
79
|
-
end
|
|
80
|
-
|
|
81
57
|
@options[name] = false
|
|
82
58
|
use(name, options, &block)
|
|
83
59
|
end
|
|
@@ -23,7 +23,7 @@ module SimpleForm
|
|
|
23
23
|
private
|
|
24
24
|
|
|
25
25
|
def html_classes(input, options)
|
|
26
|
-
css = options[:wrapper_class] ? Array
|
|
26
|
+
css = options[:wrapper_class] ? Array(options[:wrapper_class]) : @defaults[:class]
|
|
27
27
|
css += SimpleForm.additional_classes_for(:wrapper) do
|
|
28
28
|
input.additional_classes + [input.input_class]
|
|
29
29
|
end
|
data/lib/simple_form/wrappers.rb
CHANGED
data/lib/simple_form.rb
CHANGED
|
@@ -18,6 +18,12 @@ module SimpleForm
|
|
|
18
18
|
autoload :Inputs
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
+
def self.eager_load!
|
|
22
|
+
super
|
|
23
|
+
SimpleForm::Inputs.eager_load!
|
|
24
|
+
SimpleForm::Components.eager_load!
|
|
25
|
+
end
|
|
26
|
+
|
|
21
27
|
## CONFIGURATION OPTIONS
|
|
22
28
|
|
|
23
29
|
# Method used to tidy up errors.
|
|
@@ -34,11 +40,11 @@ module SimpleForm
|
|
|
34
40
|
|
|
35
41
|
# Series of attemps to detect a default label method for collection.
|
|
36
42
|
mattr_accessor :collection_label_methods
|
|
37
|
-
@@collection_label_methods = [
|
|
43
|
+
@@collection_label_methods = [:to_label, :name, :title, :to_s]
|
|
38
44
|
|
|
39
45
|
# Series of attemps to detect a default value method for collection.
|
|
40
46
|
mattr_accessor :collection_value_methods
|
|
41
|
-
@@collection_value_methods = [
|
|
47
|
+
@@collection_value_methods = [:id, :to_s]
|
|
42
48
|
|
|
43
49
|
# You can wrap a collection of radio/check boxes in a pre-defined tag, defaulting to none.
|
|
44
50
|
mattr_accessor :collection_wrapper_tag
|
|
@@ -49,7 +55,7 @@ module SimpleForm
|
|
|
49
55
|
@@collection_wrapper_class = nil
|
|
50
56
|
|
|
51
57
|
# You can wrap each item in a collection of radio/check boxes with a tag,
|
|
52
|
-
# defaulting to
|
|
58
|
+
# defaulting to span. Please note that when using :boolean_style = :nested,
|
|
53
59
|
# SimpleForm will force this option to be a :label.
|
|
54
60
|
mattr_accessor :item_wrapper_tag
|
|
55
61
|
@@item_wrapper_tag = :span
|
|
@@ -62,25 +68,25 @@ module SimpleForm
|
|
|
62
68
|
mattr_accessor :label_text
|
|
63
69
|
@@label_text = lambda { |label, required| "#{required} #{label}" }
|
|
64
70
|
|
|
65
|
-
# You can define the class to
|
|
71
|
+
# You can define the class to be used on all labels. Defaults to none.
|
|
66
72
|
mattr_accessor :label_class
|
|
67
73
|
@@label_class = nil
|
|
68
74
|
|
|
69
75
|
# Define the way to render check boxes / radio buttons with labels.
|
|
70
|
-
# :
|
|
71
|
-
# :
|
|
76
|
+
# inline: input + label (default)
|
|
77
|
+
# nested: label > input
|
|
72
78
|
mattr_accessor :boolean_style
|
|
73
79
|
@@boolean_style = :inline
|
|
74
80
|
|
|
75
|
-
# You can define the class to
|
|
81
|
+
# You can define the class to be used on all forms. Default is simple_form.
|
|
76
82
|
mattr_accessor :form_class
|
|
77
83
|
@@form_class = :simple_form
|
|
78
84
|
|
|
79
|
-
# You can define which elements should obtain additional classes
|
|
85
|
+
# You can define which elements should obtain additional classes.
|
|
80
86
|
mattr_accessor :generate_additional_classes_for
|
|
81
87
|
@@generate_additional_classes_for = [:wrapper, :label, :input]
|
|
82
88
|
|
|
83
|
-
# Whether attributes are required by default
|
|
89
|
+
# Whether attributes are required by default or not.
|
|
84
90
|
mattr_accessor :required_by_default
|
|
85
91
|
@@required_by_default = true
|
|
86
92
|
|
|
@@ -90,7 +96,7 @@ module SimpleForm
|
|
|
90
96
|
|
|
91
97
|
# Collection of methods to detect if a file type was given.
|
|
92
98
|
mattr_accessor :file_methods
|
|
93
|
-
@@file_methods = [
|
|
99
|
+
@@file_methods = [:mounted_as, :file?, :public_filename]
|
|
94
100
|
|
|
95
101
|
# Custom mappings for input types. This should be a hash containing a regexp
|
|
96
102
|
# to match as key, and the input type that will be used when the field name
|
|
@@ -100,7 +106,7 @@ module SimpleForm
|
|
|
100
106
|
|
|
101
107
|
# Custom wrappers for input types. This should be a hash containing an input
|
|
102
108
|
# type as key and the wrapper that will be used for all inputs with specified type.
|
|
103
|
-
# e.g { :
|
|
109
|
+
# e.g { string: :string_wrapper, boolean: :boolean_wrapper }
|
|
104
110
|
mattr_accessor :wrapper_mappings
|
|
105
111
|
@@wrapper_mappings = nil
|
|
106
112
|
|
|
@@ -112,9 +118,9 @@ module SimpleForm
|
|
|
112
118
|
mattr_accessor :country_priority
|
|
113
119
|
@@country_priority = nil
|
|
114
120
|
|
|
115
|
-
# Maximum size allowed for inputs.
|
|
121
|
+
# DEPRECATED: Maximum size allowed for inputs.
|
|
116
122
|
mattr_accessor :default_input_size
|
|
117
|
-
@@default_input_size =
|
|
123
|
+
@@default_input_size = nil
|
|
118
124
|
|
|
119
125
|
# When off, do not use translations in labels. Disabling translation in
|
|
120
126
|
# hints and placeholders can be done manually in the wrapper API.
|
|
@@ -125,14 +131,22 @@ module SimpleForm
|
|
|
125
131
|
mattr_accessor :inputs_discovery
|
|
126
132
|
@@inputs_discovery = true
|
|
127
133
|
|
|
128
|
-
# Cache SimpleForm inputs discovery
|
|
134
|
+
# Cache SimpleForm inputs discovery.
|
|
129
135
|
mattr_accessor :cache_discovery
|
|
130
136
|
@@cache_discovery = defined?(Rails) && !Rails.env.development?
|
|
131
137
|
|
|
132
|
-
# Adds a class to each generated button, mostly for compatiblity
|
|
138
|
+
# Adds a class to each generated button, mostly for compatiblity.
|
|
133
139
|
mattr_accessor :button_class
|
|
134
140
|
@@button_class = 'button'
|
|
135
141
|
|
|
142
|
+
# Override the default ActiveModelHelper behaviour of wrapping the input.
|
|
143
|
+
# This gets taken care of semantically by adding an error class to the wrapper tag
|
|
144
|
+
# containing the input.
|
|
145
|
+
mattr_accessor :field_error_proc
|
|
146
|
+
@@field_error_proc = proc do |html_tag, instance_tag|
|
|
147
|
+
html_tag
|
|
148
|
+
end
|
|
149
|
+
|
|
136
150
|
## WRAPPER CONFIGURATION
|
|
137
151
|
# The default wrapper to be used by the FormBuilder.
|
|
138
152
|
mattr_accessor :default_wrapper
|
|
@@ -168,7 +182,7 @@ module SimpleForm
|
|
|
168
182
|
SimpleForm::Wrappers::Root.new(builder.to_a, options)
|
|
169
183
|
end
|
|
170
184
|
|
|
171
|
-
wrappers :
|
|
185
|
+
wrappers class: :input, hint_class: :field_with_hint, error_class: :field_with_errors do |b|
|
|
172
186
|
b.use :html5
|
|
173
187
|
|
|
174
188
|
b.use :min_max
|
|
@@ -178,47 +192,25 @@ module SimpleForm
|
|
|
178
192
|
b.optional :readonly
|
|
179
193
|
|
|
180
194
|
b.use :label_input
|
|
181
|
-
b.use :hint, :
|
|
182
|
-
b.use :error, :
|
|
183
|
-
end
|
|
184
|
-
|
|
185
|
-
## SETUP
|
|
186
|
-
|
|
187
|
-
DEPRECATED = %w(hint_tag hint_class error_tag error_class error_notification_id wrapper_tag wrapper_class wrapper_error_class components html5)
|
|
188
|
-
@@deprecated = []
|
|
189
|
-
|
|
190
|
-
DEPRECATED.each do |method|
|
|
191
|
-
class_eval "def self.#{method}=(*); @@deprecated << :#{method}=; end"
|
|
192
|
-
class_eval "def self.#{method}; deprecation_warn 'SimpleForm.#{method} is deprecated and has no effect'; end"
|
|
193
|
-
end
|
|
194
|
-
|
|
195
|
-
def self.translate=(value)
|
|
196
|
-
deprecation_warn "SimpleForm.translate= is disabled in favor of translate_labels="
|
|
197
|
-
self.translate_labels = value
|
|
195
|
+
b.use :hint, wrap_with: { tag: :span, class: :hint }
|
|
196
|
+
b.use :error, wrap_with: { tag: :span, class: :error }
|
|
198
197
|
end
|
|
199
198
|
|
|
200
|
-
def self.
|
|
201
|
-
|
|
202
|
-
self.translate_labels
|
|
199
|
+
def self.additional_classes_for(component)
|
|
200
|
+
generate_additional_classes_for.include?(component) ? yield : []
|
|
203
201
|
end
|
|
204
202
|
|
|
205
|
-
|
|
206
|
-
ActiveSupport::Deprecation.warn "[SIMPLE_FORM] #{message}", caller
|
|
207
|
-
end
|
|
203
|
+
## SETUP
|
|
208
204
|
|
|
209
|
-
def self.
|
|
210
|
-
|
|
205
|
+
def self.default_input_size=(*)
|
|
206
|
+
ActiveSupport::Deprecation.warn "[SIMPLE_FORM] SimpleForm.default_input_size= is deprecated and has no effect", caller
|
|
211
207
|
end
|
|
212
208
|
|
|
213
209
|
# Default way to setup SimpleForm. Run rails generate simple_form:install
|
|
214
210
|
# to create a fresh initializer with all configuration values.
|
|
215
211
|
def self.setup
|
|
216
212
|
yield self
|
|
217
|
-
|
|
218
|
-
unless @@deprecated.empty?
|
|
219
|
-
raise "[SIMPLE FORM] Your SimpleForm initializer file is using the following methods: #{@@deprecated.to_sentence}. " <<
|
|
220
|
-
"Those methods are part of the outdated configuration API. Updating to the new API is easy and fast. " <<
|
|
221
|
-
"Check for more info here: https://github.com/plataformatec/simple_form/wiki/Upgrading-to-Simple-Form-2.0"
|
|
222
|
-
end
|
|
223
213
|
end
|
|
224
214
|
end
|
|
215
|
+
|
|
216
|
+
require 'simple_form/railtie' if defined?(Rails)
|