simple_form 3.0.4 → 3.1.0.rc1
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 +4 -4
- data/CHANGELOG.md +32 -43
- data/MIT-LICENSE +1 -1
- data/README.md +146 -71
- data/lib/generators/simple_form/install_generator.rb +2 -2
- data/lib/generators/simple_form/templates/README +3 -4
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +19 -3
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +83 -22
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +1 -1
- data/lib/generators/simple_form/templates/config/locales/simple_form.en.yml +7 -2
- data/lib/simple_form.rb +38 -6
- data/lib/simple_form/action_view_extensions/form_helper.rb +1 -1
- data/lib/simple_form/components/errors.rb +27 -5
- data/lib/simple_form/components/hints.rb +2 -2
- data/lib/simple_form/components/html5.rb +1 -1
- data/lib/simple_form/components/label_input.rb +20 -2
- data/lib/simple_form/components/labels.rb +9 -5
- data/lib/simple_form/components/maxlength.rb +1 -1
- data/lib/simple_form/components/min_max.rb +1 -1
- data/lib/simple_form/components/pattern.rb +1 -1
- data/lib/simple_form/components/placeholders.rb +2 -2
- data/lib/simple_form/components/readonly.rb +1 -1
- data/lib/simple_form/form_builder.rb +92 -59
- data/lib/simple_form/helpers.rb +5 -5
- data/lib/simple_form/inputs/base.rb +34 -12
- data/lib/simple_form/inputs/block_input.rb +1 -1
- data/lib/simple_form/inputs/boolean_input.rb +23 -13
- data/lib/simple_form/inputs/collection_input.rb +32 -9
- data/lib/simple_form/inputs/collection_radio_buttons_input.rb +6 -11
- data/lib/simple_form/inputs/collection_select_input.rb +4 -2
- data/lib/simple_form/inputs/date_time_input.rb +12 -2
- 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 +5 -4
- data/lib/simple_form/inputs/password_input.rb +4 -2
- 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 -2
- data/lib/simple_form/inputs/text_input.rb +4 -2
- data/lib/simple_form/railtie.rb +7 -0
- data/lib/simple_form/tags.rb +7 -0
- data/lib/simple_form/version.rb +1 -1
- data/lib/simple_form/wrappers.rb +1 -0
- data/lib/simple_form/wrappers/builder.rb +5 -5
- data/lib/simple_form/wrappers/leaf.rb +28 -0
- data/lib/simple_form/wrappers/many.rb +5 -6
- data/lib/simple_form/wrappers/root.rb +1 -1
- data/lib/simple_form/wrappers/single.rb +5 -3
- data/test/action_view_extensions/builder_test.rb +2 -2
- data/test/components/label_test.rb +1 -1
- data/test/form_builder/association_test.rb +17 -0
- data/test/form_builder/error_notification_test.rb +1 -1
- data/test/form_builder/error_test.rb +51 -32
- data/test/form_builder/general_test.rb +2 -2
- data/test/form_builder/input_field_test.rb +21 -37
- data/test/form_builder/label_test.rb +24 -1
- data/test/form_builder/wrapper_test.rb +67 -0
- data/test/generators/simple_form_generator_test.rb +2 -2
- data/test/inputs/boolean_input_test.rb +50 -2
- data/test/inputs/collection_check_boxes_input_test.rb +40 -11
- data/test/inputs/collection_radio_buttons_input_test.rb +76 -17
- data/test/inputs/collection_select_input_test.rb +108 -3
- data/test/inputs/datetime_input_test.rb +105 -38
- data/test/inputs/discovery_test.rb +12 -1
- data/test/inputs/grouped_collection_select_input_test.rb +36 -0
- data/test/inputs/string_input_test.rb +20 -0
- data/test/simple_form_test.rb +8 -0
- data/test/support/discovery_inputs.rb +12 -2
- data/test/support/misc_helpers.rb +46 -8
- data/test/support/models.rb +49 -24
- metadata +7 -7
@@ -21,16 +21,19 @@ module SimpleForm
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
def label
|
24
|
+
def label(wrapper_options = nil)
|
25
|
+
label_options = merge_wrapper_options(label_html_options, wrapper_options)
|
26
|
+
|
25
27
|
if generate_label_for_attribute?
|
26
|
-
@builder.label(label_target, label_text,
|
28
|
+
@builder.label(label_target, label_text, label_options)
|
27
29
|
else
|
28
|
-
template.label_tag(nil, label_text,
|
30
|
+
template.label_tag(nil, label_text, label_options)
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
32
34
|
def label_text
|
33
|
-
SimpleForm.label_text
|
35
|
+
label_text = options[:label_text] || SimpleForm.label_text
|
36
|
+
label_text.call(html_escape(raw_label_text), required_label_text, options[:label].present?).strip.html_safe
|
34
37
|
end
|
35
38
|
|
36
39
|
def label_target
|
@@ -46,6 +49,7 @@ module SimpleForm
|
|
46
49
|
if options.key?(:input_html) && options[:input_html].key?(:id)
|
47
50
|
label_options[:for] = options[:input_html][:id]
|
48
51
|
end
|
52
|
+
|
49
53
|
label_options
|
50
54
|
end
|
51
55
|
|
@@ -62,7 +66,7 @@ module SimpleForm
|
|
62
66
|
|
63
67
|
# First check labels translation and then human attribute name.
|
64
68
|
def label_translation #:nodoc:
|
65
|
-
if SimpleForm.translate_labels && (translated_label =
|
69
|
+
if SimpleForm.translate_labels && (translated_label = translate_from_namespace(:labels))
|
66
70
|
translated_label
|
67
71
|
elsif object.class.respond_to?(:human_attribute_name)
|
68
72
|
object.class.human_attribute_name(reflection_or_attribute_name.to_s)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module SimpleForm
|
2
2
|
module Components
|
3
3
|
module MinMax
|
4
|
-
def min_max
|
4
|
+
def min_max(wrapper_options = nil)
|
5
5
|
if numeric_validator = find_numericality_validator
|
6
6
|
validator_options = numeric_validator.options
|
7
7
|
input_html_options[:min] ||= minimum_value(validator_options)
|
@@ -2,14 +2,14 @@ module SimpleForm
|
|
2
2
|
module Components
|
3
3
|
# Needs to be enabled in order to do automatic lookups.
|
4
4
|
module Placeholders
|
5
|
-
def placeholder
|
5
|
+
def placeholder(wrapper_options = nil)
|
6
6
|
input_html_options[:placeholder] ||= placeholder_text
|
7
7
|
nil
|
8
8
|
end
|
9
9
|
|
10
10
|
def placeholder_text
|
11
11
|
placeholder = options[:placeholder]
|
12
|
-
placeholder.is_a?(String) ? placeholder :
|
12
|
+
placeholder.is_a?(String) ? placeholder : translate_from_namespace(:placeholders)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -2,7 +2,7 @@ module SimpleForm
|
|
2
2
|
module Components
|
3
3
|
# Needs to be enabled in order to do automatic lookups.
|
4
4
|
module Readonly
|
5
|
-
def readonly
|
5
|
+
def readonly(wrapper_options = nil)
|
6
6
|
if readonly_attribute? && !has_readonly?
|
7
7
|
input_html_options[:readonly] ||= true
|
8
8
|
input_html_classes << :readonly
|
@@ -8,8 +8,8 @@ module SimpleForm
|
|
8
8
|
|
9
9
|
# When action is create or update, we still should use new and edit
|
10
10
|
ACTIONS = {
|
11
|
-
create
|
12
|
-
update
|
11
|
+
'create' => 'new',
|
12
|
+
'update' => 'edit'
|
13
13
|
}
|
14
14
|
|
15
15
|
ATTRIBUTE_COMPONENTS = [:html5, :min_max, :maxlength, :placeholder, :pattern, :readonly]
|
@@ -106,18 +106,13 @@ module SimpleForm
|
|
106
106
|
# Some inputs, as :time_zone and :country accepts a :priority option. If none is
|
107
107
|
# given SimpleForm.time_zone_priority and SimpleForm.country_priority are used respectively.
|
108
108
|
#
|
109
|
-
def input(attribute_name, options={}, &block)
|
109
|
+
def input(attribute_name, options = {}, &block)
|
110
110
|
options = @defaults.deep_dup.deep_merge(options) if @defaults
|
111
|
-
input = find_input(attribute_name, options, &block)
|
112
111
|
|
113
|
-
|
114
|
-
|
115
|
-
name.respond_to?(:render) ? name : SimpleForm.wrapper(name)
|
116
|
-
else
|
117
|
-
wrapper
|
118
|
-
end
|
112
|
+
input = find_input(attribute_name, options, &block)
|
113
|
+
wrapper = find_wrapper(input.input_type, options)
|
119
114
|
|
120
|
-
|
115
|
+
wrapper.render input
|
121
116
|
end
|
122
117
|
alias :attribute :input
|
123
118
|
|
@@ -135,14 +130,17 @@ module SimpleForm
|
|
135
130
|
# <input class="string required" id="user_name" maxlength="100"
|
136
131
|
# name="user[name]" type="text" value="Carlos" />
|
137
132
|
#
|
138
|
-
def input_field(attribute_name, options={})
|
139
|
-
components = (wrapper.components & ATTRIBUTE_COMPONENTS)
|
140
|
-
|
133
|
+
def input_field(attribute_name, options = {})
|
141
134
|
options = options.dup
|
142
|
-
options[:input_html] = options.except(:as, :collection, :label_method, :value_method, *
|
135
|
+
options[:input_html] = options.except(:as, :boolean_style, :collection, :label_method, :value_method, *ATTRIBUTE_COMPONENTS)
|
143
136
|
options = @defaults.deep_dup.deep_merge(options) if @defaults
|
144
137
|
|
145
|
-
|
138
|
+
input = find_input(attribute_name, options)
|
139
|
+
wrapper = find_wrapper(input.input_type, options)
|
140
|
+
components = (wrapper.components.map(&:namespace) & ATTRIBUTE_COMPONENTS) + [:input]
|
141
|
+
components = components.map { |component| SimpleForm::Wrappers::Leaf.new(component) }
|
142
|
+
|
143
|
+
SimpleForm::Wrappers::Root.new(components, wrapper.options.merge(wrapper: false)).render input
|
146
144
|
end
|
147
145
|
|
148
146
|
# Helper for dealing with association selects/radios, generating the
|
@@ -173,7 +171,7 @@ module SimpleForm
|
|
173
171
|
#
|
174
172
|
# Please note that the association helper is currently only tested with Active Record. Depending on the ORM you are using your mileage may vary.
|
175
173
|
#
|
176
|
-
def association(association, options={}, &block)
|
174
|
+
def association(association, options = {}, &block)
|
177
175
|
options = options.dup
|
178
176
|
|
179
177
|
return simple_fields_for(*[association,
|
@@ -185,31 +183,9 @@ module SimpleForm
|
|
185
183
|
raise "Association #{association.inspect} not found" unless reflection
|
186
184
|
|
187
185
|
options[:as] ||= :select
|
188
|
-
options[:collection] ||= options
|
189
|
-
|
190
|
-
|
191
|
-
reflection.klass.where(conditions).order(reflection.options[:order])
|
192
|
-
}
|
193
|
-
|
194
|
-
attribute = case reflection.macro
|
195
|
-
when :belongs_to
|
196
|
-
(reflection.respond_to?(:options) && reflection.options[:foreign_key]) || :"#{reflection.name}_id"
|
197
|
-
when :has_one
|
198
|
-
raise ArgumentError, ":has_one associations are not supported by f.association"
|
199
|
-
else
|
200
|
-
if options[:as] == :select
|
201
|
-
html_options = options[:input_html] ||= {}
|
202
|
-
html_options[:multiple] = true unless html_options.key?(:multiple)
|
203
|
-
end
|
204
|
-
|
205
|
-
# Force the association to be preloaded for performance.
|
206
|
-
if options[:preload] != false && object.respond_to?(association)
|
207
|
-
target = object.send(association)
|
208
|
-
target.to_a if target.respond_to?(:to_a)
|
209
|
-
end
|
210
|
-
|
211
|
-
:"#{reflection.name.to_s.singularize}_ids"
|
212
|
-
end
|
186
|
+
options[:collection] ||= fetch_association_collection(reflection, options)
|
187
|
+
|
188
|
+
attribute = build_association_attribute(reflection, association, options)
|
213
189
|
|
214
190
|
input(attribute, options.merge(reflection: reflection))
|
215
191
|
end
|
@@ -244,7 +220,7 @@ module SimpleForm
|
|
244
220
|
# f.error :name
|
245
221
|
# f.error :name, id: "cool_error"
|
246
222
|
#
|
247
|
-
def error(attribute_name, options={})
|
223
|
+
def error(attribute_name, options = {})
|
248
224
|
options = options.dup
|
249
225
|
|
250
226
|
options[:error_html] = options.except(:error_tag, :error_prefix, :error_method)
|
@@ -261,7 +237,7 @@ module SimpleForm
|
|
261
237
|
#
|
262
238
|
# f.full_error :token #=> <span class="error">Token is invalid</span>
|
263
239
|
#
|
264
|
-
def full_error(attribute_name, options={})
|
240
|
+
def full_error(attribute_name, options = {})
|
265
241
|
options = options.dup
|
266
242
|
|
267
243
|
options[:error_prefix] ||= if object.class.respond_to?(:human_attribute_name)
|
@@ -283,7 +259,7 @@ module SimpleForm
|
|
283
259
|
# f.hint :name, id: "cool_hint"
|
284
260
|
# f.hint "Don't forget to accept this"
|
285
261
|
#
|
286
|
-
def hint(attribute_name, options={})
|
262
|
+
def hint(attribute_name, options = {})
|
287
263
|
options = options.dup
|
288
264
|
|
289
265
|
options[:hint_html] = options.except(:hint_tag, :hint)
|
@@ -334,7 +310,7 @@ module SimpleForm
|
|
334
310
|
# f.error_notification message: 'Something went wrong'
|
335
311
|
# f.error_notification id: 'user_error_message', class: 'form_error'
|
336
312
|
#
|
337
|
-
def error_notification(options={})
|
313
|
+
def error_notification(options = {})
|
338
314
|
SimpleForm::ErrorNotification.new(self, options).render
|
339
315
|
end
|
340
316
|
|
@@ -466,15 +442,56 @@ module SimpleForm
|
|
466
442
|
@lookup_action ||= begin
|
467
443
|
action = template.controller && template.controller.action_name
|
468
444
|
return unless action
|
469
|
-
action = action.
|
445
|
+
action = action.to_s
|
470
446
|
ACTIONS[action] || action
|
471
447
|
end
|
472
448
|
end
|
473
449
|
|
474
450
|
private
|
475
451
|
|
452
|
+
def fetch_association_collection(reflection, options)
|
453
|
+
options.fetch(:collection) do
|
454
|
+
relation = reflection.klass.all
|
455
|
+
|
456
|
+
if reflection.respond_to?(:scope) && reflection.scope
|
457
|
+
relation = reflection.klass.instance_exec(&reflection.scope)
|
458
|
+
else
|
459
|
+
order = reflection.options[:order]
|
460
|
+
conditions = reflection.options[:conditions]
|
461
|
+
conditions = object.instance_exec(&conditions) if conditions.respond_to?(:call)
|
462
|
+
|
463
|
+
relation = relation.where(conditions)
|
464
|
+
relation = relation.order(order) if relation.respond_to?(:order)
|
465
|
+
end
|
466
|
+
|
467
|
+
relation
|
468
|
+
end
|
469
|
+
end
|
470
|
+
|
471
|
+
def build_association_attribute(reflection, association, options)
|
472
|
+
case reflection.macro
|
473
|
+
when :belongs_to
|
474
|
+
(reflection.respond_to?(:options) && reflection.options[:foreign_key]) || :"#{reflection.name}_id"
|
475
|
+
when :has_one
|
476
|
+
raise ArgumentError, ":has_one associations are not supported by f.association"
|
477
|
+
else
|
478
|
+
if options[:as] == :select
|
479
|
+
html_options = options[:input_html] ||= {}
|
480
|
+
html_options[:multiple] = true unless html_options.key?(:multiple)
|
481
|
+
end
|
482
|
+
|
483
|
+
# Force the association to be preloaded for performance.
|
484
|
+
if options[:preload] != false && object.respond_to?(association)
|
485
|
+
target = object.send(association)
|
486
|
+
target.to_a if target.respond_to?(:to_a)
|
487
|
+
end
|
488
|
+
|
489
|
+
:"#{reflection.name.to_s.singularize}_ids"
|
490
|
+
end
|
491
|
+
end
|
492
|
+
|
476
493
|
# Find an input based on the attribute name.
|
477
|
-
def find_input(attribute_name, options={}, &block)
|
494
|
+
def find_input(attribute_name, options = {}, &block)
|
478
495
|
column = find_attribute_column(attribute_name)
|
479
496
|
input_type = default_input_type(attribute_name, column, options)
|
480
497
|
|
@@ -488,7 +505,7 @@ module SimpleForm
|
|
488
505
|
# Attempt to guess the better input type given the defined options. By
|
489
506
|
# default alwayls fallback to the user :as option, or to a :select when a
|
490
507
|
# collection is given.
|
491
|
-
def default_input_type(attribute_name, column, options)
|
508
|
+
def default_input_type(attribute_name, column, options)
|
492
509
|
return options[:as].to_sym if options[:as]
|
493
510
|
return :select if options[:collection]
|
494
511
|
custom_type = find_custom_type(attribute_name.to_s) and return custom_type
|
@@ -513,24 +530,24 @@ module SimpleForm
|
|
513
530
|
end
|
514
531
|
end
|
515
532
|
|
516
|
-
def find_custom_type(attribute_name)
|
533
|
+
def find_custom_type(attribute_name)
|
517
534
|
SimpleForm.input_mappings.find { |match, type|
|
518
535
|
attribute_name =~ match
|
519
536
|
}.try(:last) if SimpleForm.input_mappings
|
520
537
|
end
|
521
538
|
|
522
|
-
def file_method?(attribute_name)
|
539
|
+
def file_method?(attribute_name)
|
523
540
|
file = @object.send(attribute_name) if @object.respond_to?(attribute_name)
|
524
541
|
file && SimpleForm.file_methods.any? { |m| file.respond_to?(m) }
|
525
542
|
end
|
526
543
|
|
527
|
-
def find_attribute_column(attribute_name)
|
544
|
+
def find_attribute_column(attribute_name)
|
528
545
|
if @object.respond_to?(:column_for_attribute)
|
529
546
|
@object.column_for_attribute(attribute_name)
|
530
547
|
end
|
531
548
|
end
|
532
549
|
|
533
|
-
def find_association_reflection(association)
|
550
|
+
def find_association_reflection(association)
|
534
551
|
if @object.class.respond_to?(:reflect_on_association)
|
535
552
|
@object.class.reflect_on_association(association)
|
536
553
|
end
|
@@ -543,7 +560,7 @@ module SimpleForm
|
|
543
560
|
# b) Or use the found mapping
|
544
561
|
# 2) If not, fallbacks to #{input_type}Input
|
545
562
|
# 3) If not, fallbacks to SimpleForm::Inputs::#{input_type}Input
|
546
|
-
def find_mapping(input_type)
|
563
|
+
def find_mapping(input_type)
|
547
564
|
discovery_cache[input_type] ||=
|
548
565
|
if mapping = self.class.mappings[input_type]
|
549
566
|
mapping_override(mapping) || mapping
|
@@ -554,13 +571,29 @@ module SimpleForm
|
|
554
571
|
end
|
555
572
|
end
|
556
573
|
|
557
|
-
|
558
|
-
|
574
|
+
# Attempts to find a wrapper mapping. It follows the following rules:
|
575
|
+
#
|
576
|
+
# 1) It tries to find a wrapper for the current form
|
577
|
+
# 2) If not, it tries to find a config
|
578
|
+
def find_wrapper_mapping(input_type)
|
579
|
+
if options[:wrapper_mappings] && options[:wrapper_mappings][input_type]
|
580
|
+
options[:wrapper_mappings][input_type]
|
581
|
+
else
|
582
|
+
SimpleForm.wrapper_mappings && SimpleForm.wrapper_mappings[input_type]
|
583
|
+
end
|
584
|
+
end
|
585
|
+
|
586
|
+
def find_wrapper(input_type, options)
|
587
|
+
if name = options[:wrapper] || find_wrapper_mapping(input_type)
|
588
|
+
name.respond_to?(:render) ? name : SimpleForm.wrapper(name)
|
589
|
+
else
|
590
|
+
wrapper
|
591
|
+
end
|
559
592
|
end
|
560
593
|
|
561
594
|
# If cache_discovery is enabled, use the class level cache that persists
|
562
595
|
# between requests, otherwise use the instance one.
|
563
|
-
def discovery_cache
|
596
|
+
def discovery_cache
|
564
597
|
if SimpleForm.cache_discovery
|
565
598
|
self.class.discovery_cache
|
566
599
|
else
|
@@ -568,14 +601,14 @@ module SimpleForm
|
|
568
601
|
end
|
569
602
|
end
|
570
603
|
|
571
|
-
def mapping_override(klass)
|
604
|
+
def mapping_override(klass)
|
572
605
|
name = klass.name
|
573
606
|
if name =~ /^SimpleForm::Inputs/
|
574
607
|
attempt_mapping name.split("::").last, Object
|
575
608
|
end
|
576
609
|
end
|
577
610
|
|
578
|
-
def attempt_mapping(mapping, at)
|
611
|
+
def attempt_mapping(mapping, at)
|
579
612
|
return if SimpleForm.inputs_discovery == false && at == Object
|
580
613
|
|
581
614
|
begin
|
data/lib/simple_form/helpers.rb
CHANGED
@@ -3,10 +3,10 @@ module SimpleForm
|
|
3
3
|
# For instance, disabled cannot be turned on automatically, it requires the
|
4
4
|
# user to explicitly pass the option disabled: true so it may work.
|
5
5
|
module Helpers
|
6
|
-
autoload :Autofocus,
|
7
|
-
autoload :Disabled,
|
8
|
-
autoload :Readonly,
|
9
|
-
autoload :Required,
|
10
|
-
autoload :Validators,
|
6
|
+
autoload :Autofocus, 'simple_form/helpers/autofocus'
|
7
|
+
autoload :Disabled, 'simple_form/helpers/disabled'
|
8
|
+
autoload :Readonly, 'simple_form/helpers/readonly'
|
9
|
+
autoload :Required, 'simple_form/helpers/required'
|
10
|
+
autoload :Validators, 'simple_form/helpers/validators'
|
11
11
|
end
|
12
12
|
end
|
@@ -1,10 +1,12 @@
|
|
1
1
|
require 'simple_form/i18n_cache'
|
2
2
|
require 'active_support/core_ext/string/output_safety'
|
3
|
+
require 'action_view/helpers'
|
3
4
|
|
4
5
|
module SimpleForm
|
5
6
|
module Inputs
|
6
7
|
class Base
|
7
8
|
include ERB::Util
|
9
|
+
include ActionView::Helpers::TranslationHelper
|
8
10
|
|
9
11
|
extend I18nCache
|
10
12
|
|
@@ -45,7 +47,7 @@ module SimpleForm
|
|
45
47
|
end
|
46
48
|
|
47
49
|
# Always enabled.
|
48
|
-
enable :hint
|
50
|
+
enable :hint
|
49
51
|
|
50
52
|
# Usually disabled, needs to be enabled explicitly passing true as option.
|
51
53
|
disable :maxlength, :placeholder, :pattern, :min_max
|
@@ -53,14 +55,14 @@ module SimpleForm
|
|
53
55
|
def initialize(builder, attribute_name, column, input_type, options = {})
|
54
56
|
super
|
55
57
|
|
56
|
-
options
|
57
|
-
@builder
|
58
|
-
@attribute_name
|
59
|
-
@column
|
60
|
-
@input_type
|
61
|
-
@reflection
|
62
|
-
@options
|
63
|
-
@required
|
58
|
+
options = options.dup
|
59
|
+
@builder = builder
|
60
|
+
@attribute_name = attribute_name
|
61
|
+
@column = column
|
62
|
+
@input_type = input_type
|
63
|
+
@reflection = options.delete(:reflection)
|
64
|
+
@options = options.reverse_merge!(self.class.default_options)
|
65
|
+
@required = calculate_required
|
64
66
|
|
65
67
|
# Notice that html_options_for receives a reference to input_html_classes.
|
66
68
|
# This means that classes added dynamically to input_html_classes will
|
@@ -79,7 +81,7 @@ module SimpleForm
|
|
79
81
|
end
|
80
82
|
end
|
81
83
|
|
82
|
-
def input
|
84
|
+
def input(wrapper_options = nil)
|
83
85
|
raise NotImplementedError
|
84
86
|
end
|
85
87
|
|
@@ -167,7 +169,7 @@ module SimpleForm
|
|
167
169
|
# email: 'E-mail.'
|
168
170
|
#
|
169
171
|
# Take a look at our locale example file.
|
170
|
-
def
|
172
|
+
def translate_from_namespace(namespace, default = '')
|
171
173
|
model_names = lookup_model_names.dup
|
172
174
|
lookups = []
|
173
175
|
|
@@ -176,13 +178,33 @@ module SimpleForm
|
|
176
178
|
model_names.shift
|
177
179
|
|
178
180
|
lookups << :"#{joined_model_names}.#{lookup_action}.#{reflection_or_attribute_name}"
|
181
|
+
lookups << :"#{joined_model_names}.#{lookup_action}.#{reflection_or_attribute_name}_html"
|
179
182
|
lookups << :"#{joined_model_names}.#{reflection_or_attribute_name}"
|
183
|
+
lookups << :"#{joined_model_names}.#{reflection_or_attribute_name}_html"
|
180
184
|
end
|
181
185
|
lookups << :"defaults.#{lookup_action}.#{reflection_or_attribute_name}"
|
186
|
+
lookups << :"defaults.#{lookup_action}.#{reflection_or_attribute_name}_html"
|
182
187
|
lookups << :"defaults.#{reflection_or_attribute_name}"
|
188
|
+
lookups << :"defaults.#{reflection_or_attribute_name}_html"
|
183
189
|
lookups << default
|
184
190
|
|
185
|
-
|
191
|
+
t(lookups.shift, scope: :"#{i18n_scope}.#{namespace}", default: lookups).presence
|
192
|
+
end
|
193
|
+
|
194
|
+
def merge_wrapper_options(options, wrapper_options)
|
195
|
+
if wrapper_options
|
196
|
+
options.merge(wrapper_options) do |_, oldval, newval|
|
197
|
+
if Array === oldval
|
198
|
+
oldval + Array(newval)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
else
|
202
|
+
options
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
def i18n_scope
|
207
|
+
SimpleForm.i18n_scope
|
186
208
|
end
|
187
209
|
end
|
188
210
|
end
|