1
0
Fork 0
mirror of https://github.com/heartcombo/simple_form.git synced 2022-11-09 12:19:26 -05:00

Define merge_wrapper_options in Base instead in a Helper

Helpers are related to HTML attributes. merge_wrapper_options is not
related to HTML
This commit is contained in:
Rafael Mendonça França 2014-03-11 19:19:13 -03:00
parent e9384fb4bd
commit 58220b2fa5
3 changed files with 17 additions and 26 deletions

View file

@ -3,11 +3,10 @@ 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 :WrapperOptions, 'simple_form/helpers/wrapper_options'
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'
end
end

View file

@ -1,19 +0,0 @@
module SimpleForm
module Helpers
module WrapperOptions
private
def merge_wrapper_options(options, context)
if context
options.merge(context.options) do |_, oldval, newval|
if Array === oldval
oldval + Array(newval)
end
end
else
options
end
end
end
end
end

View file

@ -13,7 +13,6 @@ 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
@ -185,6 +184,18 @@ module SimpleForm
I18n.t(lookups.shift, scope: :"simple_form.#{namespace}", default: lookups).presence
end
def merge_wrapper_options(options, context)
if context
options.merge(context.options) do |_, oldval, newval|
if Array === oldval
oldval + Array(newval)
end
end
else
options
end
end
end
end
end