Extract the wrapper options merge behavior to their own module
This make easier to share the same behavior between all the components
This commit is contained in:
parent
ed1862036c
commit
3992cfc57d
|
@ -23,7 +23,7 @@ module SimpleForm
|
|||
|
||||
def label(context=nil)
|
||||
if context
|
||||
label_options = merged_label_options(context.options)
|
||||
label_options = merge_wrapper_options(label_html_options, context.options)
|
||||
else
|
||||
label_options = label_html_options
|
||||
end
|
||||
|
@ -81,14 +81,6 @@ module SimpleForm
|
|||
def generate_label_for_attribute?
|
||||
true
|
||||
end
|
||||
|
||||
def merged_label_options(context_options)
|
||||
label_html_options.merge(context_options) do |_, oldval, newval|
|
||||
if Array === oldval
|
||||
oldval + Array(newval)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,10 +3,11 @@ module SimpleForm
|
|||
# For instance, disabled cannot be turned on automatically, it requires the
|
||||
# user to explicitly pass the option disabled: true so it may work.
|
||||
module Helpers
|
||||
autoload :Autofocus, 'simple_form/helpers/autofocus'
|
||||
autoload :Disabled, 'simple_form/helpers/disabled'
|
||||
autoload :Readonly, 'simple_form/helpers/readonly'
|
||||
autoload :Required, 'simple_form/helpers/required'
|
||||
autoload :Validators, 'simple_form/helpers/validators'
|
||||
autoload :Autofocus, 'simple_form/helpers/autofocus'
|
||||
autoload :Disabled, 'simple_form/helpers/disabled'
|
||||
autoload :Readonly, 'simple_form/helpers/readonly'
|
||||
autoload :Required, 'simple_form/helpers/required'
|
||||
autoload :Validators, 'simple_form/helpers/validators'
|
||||
autoload :WrapperOptions, 'simple_form/helpers/wrapper_options'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
module SimpleForm
|
||||
module Helpers
|
||||
module WrapperOptions
|
||||
private
|
||||
|
||||
def merge_wrapper_options(options, context_options)
|
||||
options.merge(context_options) do |_, oldval, newval|
|
||||
if Array === oldval
|
||||
oldval + Array(newval)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -13,6 +13,7 @@ module SimpleForm
|
|||
include SimpleForm::Helpers::Readonly
|
||||
include SimpleForm::Helpers::Required
|
||||
include SimpleForm::Helpers::Validators
|
||||
include SimpleForm::Helpers::WrapperOptions
|
||||
|
||||
include SimpleForm::Components::Errors
|
||||
include SimpleForm::Components::Hints
|
||||
|
@ -184,14 +185,6 @@ module SimpleForm
|
|||
|
||||
I18n.t(lookups.shift, scope: :"simple_form.#{namespace}", default: lookups).presence
|
||||
end
|
||||
|
||||
def merged_input_options(context_options)
|
||||
input_html_options.merge(context_options) do |_, oldval, newval|
|
||||
if Array === oldval
|
||||
oldval + Array(newval)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@ module SimpleForm
|
|||
class BooleanInput < Base
|
||||
def input(context=nil)
|
||||
if context
|
||||
merged_input_options = merged_input_options(context.options)
|
||||
merged_input_options = merge_wrapper_options(input_html_options, context.options)
|
||||
else
|
||||
merged_input_options = input_html_options
|
||||
end
|
||||
|
@ -28,7 +28,7 @@ module SimpleForm
|
|||
html_options[:class].push(:checkbox)
|
||||
|
||||
if context
|
||||
merged_input_options = merged_input_options(context.options)
|
||||
merged_input_options = merge_wrapper_options(input_html_options, context.options)
|
||||
else
|
||||
merged_input_options = input_html_options
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ module SimpleForm
|
|||
label_method, value_method = detect_collection_methods
|
||||
|
||||
if context
|
||||
merged_input_options = merged_input_options(context.options)
|
||||
merged_input_options = merge_wrapper_options(input_html_options, context.options)
|
||||
else
|
||||
merged_input_options = input_html_options
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ module SimpleForm
|
|||
label_method, value_method = detect_collection_methods
|
||||
|
||||
if context
|
||||
merged_input_options = merged_input_options(context.options)
|
||||
merged_input_options = merge_wrapper_options(input_html_options, context.options)
|
||||
else
|
||||
merged_input_options = input_html_options
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@ module SimpleForm
|
|||
class DateTimeInput < Base
|
||||
def input(context=nil)
|
||||
if context
|
||||
merged_input_options = merged_input_options(context.options)
|
||||
merged_input_options = merge_wrapper_options(input_html_options, context.options)
|
||||
else
|
||||
merged_input_options = input_html_options
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@ module SimpleForm
|
|||
class FileInput < Base
|
||||
def input(context=nil)
|
||||
if context
|
||||
merged_input_options = merged_input_options(context.options)
|
||||
merged_input_options = merge_wrapper_options(input_html_options, context.options)
|
||||
else
|
||||
merged_input_options = input_html_options
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ module SimpleForm
|
|||
label_method, value_method = detect_collection_methods
|
||||
|
||||
if context
|
||||
merged_input_options = merged_input_options(context.options)
|
||||
merged_input_options = merge_wrapper_options(input_html_options, context.options)
|
||||
else
|
||||
merged_input_options = input_html_options
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ module SimpleForm
|
|||
|
||||
def input(context=nil)
|
||||
if context
|
||||
merged_input_options = merged_input_options(context.options)
|
||||
merged_input_options = merge_wrapper_options(input_html_options, context.options)
|
||||
else
|
||||
merged_input_options = input_html_options
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@ module SimpleForm
|
|||
end
|
||||
|
||||
if context
|
||||
merged_input_options = merged_input_options(context.options)
|
||||
merged_input_options = merge_wrapper_options(input_html_options, context.options)
|
||||
else
|
||||
merged_input_options = input_html_options
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ module SimpleForm
|
|||
|
||||
def input(context=nil)
|
||||
if context
|
||||
merged_input_options = merged_input_options(context.options)
|
||||
merged_input_options = merge_wrapper_options(input_html_options, context.options)
|
||||
else
|
||||
merged_input_options = input_html_options
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@ module SimpleForm
|
|||
class PriorityInput < CollectionSelectInput
|
||||
def input(context=nil)
|
||||
if context
|
||||
merged_input_options = merged_input_options(context.options)
|
||||
merged_input_options = merge_wrapper_options(input_html_options, context.options)
|
||||
else
|
||||
merged_input_options = input_html_options
|
||||
end
|
||||
|
|
|
@ -10,7 +10,7 @@ module SimpleForm
|
|||
end
|
||||
|
||||
if context
|
||||
merged_input_options = merged_input_options(context.options)
|
||||
merged_input_options = merge_wrapper_options(input_html_options, context.options)
|
||||
else
|
||||
merged_input_options = input_html_options
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ module SimpleForm
|
|||
|
||||
def input(context=nil)
|
||||
if context
|
||||
merged_input_options = merged_input_options(context.options)
|
||||
merged_input_options = merge_wrapper_options(input_html_options, context.options)
|
||||
else
|
||||
merged_input_options = input_html_options
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue