mirror of
https://github.com/heartcombo/simple_form.git
synced 2022-11-09 12:19:26 -05:00
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
16 changed files with 36 additions and 35 deletions
|
@ -23,7 +23,7 @@ module SimpleForm
|
||||||
|
|
||||||
def label(context=nil)
|
def label(context=nil)
|
||||||
if context
|
if context
|
||||||
label_options = merged_label_options(context.options)
|
label_options = merge_wrapper_options(label_html_options, context.options)
|
||||||
else
|
else
|
||||||
label_options = label_html_options
|
label_options = label_html_options
|
||||||
end
|
end
|
||||||
|
@ -81,14 +81,6 @@ module SimpleForm
|
||||||
def generate_label_for_attribute?
|
def generate_label_for_attribute?
|
||||||
true
|
true
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,10 +3,11 @@ module SimpleForm
|
||||||
# For instance, disabled cannot be turned on automatically, it requires the
|
# For instance, disabled cannot be turned on automatically, it requires the
|
||||||
# user to explicitly pass the option disabled: true so it may work.
|
# user to explicitly pass the option disabled: true so it may work.
|
||||||
module Helpers
|
module Helpers
|
||||||
autoload :Autofocus, 'simple_form/helpers/autofocus'
|
autoload :Autofocus, 'simple_form/helpers/autofocus'
|
||||||
autoload :Disabled, 'simple_form/helpers/disabled'
|
autoload :Disabled, 'simple_form/helpers/disabled'
|
||||||
autoload :Readonly, 'simple_form/helpers/readonly'
|
autoload :Readonly, 'simple_form/helpers/readonly'
|
||||||
autoload :Required, 'simple_form/helpers/required'
|
autoload :Required, 'simple_form/helpers/required'
|
||||||
autoload :Validators, 'simple_form/helpers/validators'
|
autoload :Validators, 'simple_form/helpers/validators'
|
||||||
|
autoload :WrapperOptions, 'simple_form/helpers/wrapper_options'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
15
lib/simple_form/helpers/wrapper_options.rb
Normal file
15
lib/simple_form/helpers/wrapper_options.rb
Normal file
|
@ -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::Readonly
|
||||||
include SimpleForm::Helpers::Required
|
include SimpleForm::Helpers::Required
|
||||||
include SimpleForm::Helpers::Validators
|
include SimpleForm::Helpers::Validators
|
||||||
|
include SimpleForm::Helpers::WrapperOptions
|
||||||
|
|
||||||
include SimpleForm::Components::Errors
|
include SimpleForm::Components::Errors
|
||||||
include SimpleForm::Components::Hints
|
include SimpleForm::Components::Hints
|
||||||
|
@ -184,14 +185,6 @@ module SimpleForm
|
||||||
|
|
||||||
I18n.t(lookups.shift, scope: :"simple_form.#{namespace}", default: lookups).presence
|
I18n.t(lookups.shift, scope: :"simple_form.#{namespace}", default: lookups).presence
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,7 @@ module SimpleForm
|
||||||
class BooleanInput < Base
|
class BooleanInput < Base
|
||||||
def input(context=nil)
|
def input(context=nil)
|
||||||
if context
|
if context
|
||||||
merged_input_options = merged_input_options(context.options)
|
merged_input_options = merge_wrapper_options(input_html_options, context.options)
|
||||||
else
|
else
|
||||||
merged_input_options = input_html_options
|
merged_input_options = input_html_options
|
||||||
end
|
end
|
||||||
|
@ -28,7 +28,7 @@ module SimpleForm
|
||||||
html_options[:class].push(:checkbox)
|
html_options[:class].push(:checkbox)
|
||||||
|
|
||||||
if context
|
if context
|
||||||
merged_input_options = merged_input_options(context.options)
|
merged_input_options = merge_wrapper_options(input_html_options, context.options)
|
||||||
else
|
else
|
||||||
merged_input_options = input_html_options
|
merged_input_options = input_html_options
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,7 +5,7 @@ module SimpleForm
|
||||||
label_method, value_method = detect_collection_methods
|
label_method, value_method = detect_collection_methods
|
||||||
|
|
||||||
if context
|
if context
|
||||||
merged_input_options = merged_input_options(context.options)
|
merged_input_options = merge_wrapper_options(input_html_options, context.options)
|
||||||
else
|
else
|
||||||
merged_input_options = input_html_options
|
merged_input_options = input_html_options
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,7 +5,7 @@ module SimpleForm
|
||||||
label_method, value_method = detect_collection_methods
|
label_method, value_method = detect_collection_methods
|
||||||
|
|
||||||
if context
|
if context
|
||||||
merged_input_options = merged_input_options(context.options)
|
merged_input_options = merge_wrapper_options(input_html_options, context.options)
|
||||||
else
|
else
|
||||||
merged_input_options = input_html_options
|
merged_input_options = input_html_options
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,7 @@ module SimpleForm
|
||||||
class DateTimeInput < Base
|
class DateTimeInput < Base
|
||||||
def input(context=nil)
|
def input(context=nil)
|
||||||
if context
|
if context
|
||||||
merged_input_options = merged_input_options(context.options)
|
merged_input_options = merge_wrapper_options(input_html_options, context.options)
|
||||||
else
|
else
|
||||||
merged_input_options = input_html_options
|
merged_input_options = input_html_options
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,7 @@ module SimpleForm
|
||||||
class FileInput < Base
|
class FileInput < Base
|
||||||
def input(context=nil)
|
def input(context=nil)
|
||||||
if context
|
if context
|
||||||
merged_input_options = merged_input_options(context.options)
|
merged_input_options = merge_wrapper_options(input_html_options, context.options)
|
||||||
else
|
else
|
||||||
merged_input_options = input_html_options
|
merged_input_options = input_html_options
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,7 +5,7 @@ module SimpleForm
|
||||||
label_method, value_method = detect_collection_methods
|
label_method, value_method = detect_collection_methods
|
||||||
|
|
||||||
if context
|
if context
|
||||||
merged_input_options = merged_input_options(context.options)
|
merged_input_options = merge_wrapper_options(input_html_options, context.options)
|
||||||
else
|
else
|
||||||
merged_input_options = input_html_options
|
merged_input_options = input_html_options
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,7 +5,7 @@ module SimpleForm
|
||||||
|
|
||||||
def input(context=nil)
|
def input(context=nil)
|
||||||
if context
|
if context
|
||||||
merged_input_options = merged_input_options(context.options)
|
merged_input_options = merge_wrapper_options(input_html_options, context.options)
|
||||||
else
|
else
|
||||||
merged_input_options = input_html_options
|
merged_input_options = input_html_options
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,7 +11,7 @@ module SimpleForm
|
||||||
end
|
end
|
||||||
|
|
||||||
if context
|
if context
|
||||||
merged_input_options = merged_input_options(context.options)
|
merged_input_options = merge_wrapper_options(input_html_options, context.options)
|
||||||
else
|
else
|
||||||
merged_input_options = input_html_options
|
merged_input_options = input_html_options
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,7 +5,7 @@ module SimpleForm
|
||||||
|
|
||||||
def input(context=nil)
|
def input(context=nil)
|
||||||
if context
|
if context
|
||||||
merged_input_options = merged_input_options(context.options)
|
merged_input_options = merge_wrapper_options(input_html_options, context.options)
|
||||||
else
|
else
|
||||||
merged_input_options = input_html_options
|
merged_input_options = input_html_options
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,7 @@ module SimpleForm
|
||||||
class PriorityInput < CollectionSelectInput
|
class PriorityInput < CollectionSelectInput
|
||||||
def input(context=nil)
|
def input(context=nil)
|
||||||
if context
|
if context
|
||||||
merged_input_options = merged_input_options(context.options)
|
merged_input_options = merge_wrapper_options(input_html_options, context.options)
|
||||||
else
|
else
|
||||||
merged_input_options = input_html_options
|
merged_input_options = input_html_options
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,7 +10,7 @@ module SimpleForm
|
||||||
end
|
end
|
||||||
|
|
||||||
if context
|
if context
|
||||||
merged_input_options = merged_input_options(context.options)
|
merged_input_options = merge_wrapper_options(input_html_options, context.options)
|
||||||
else
|
else
|
||||||
merged_input_options = input_html_options
|
merged_input_options = input_html_options
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,7 +5,7 @@ module SimpleForm
|
||||||
|
|
||||||
def input(context=nil)
|
def input(context=nil)
|
||||||
if context
|
if context
|
||||||
merged_input_options = merged_input_options(context.options)
|
merged_input_options = merge_wrapper_options(input_html_options, context.options)
|
||||||
else
|
else
|
||||||
merged_input_options = input_html_options
|
merged_input_options = input_html_options
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue