2012-01-26 18:53:16 +00:00
|
|
|
module SimpleForm
|
|
|
|
module Inputs
|
2012-01-27 18:30:19 +00:00
|
|
|
class CollectionRadioButtonsInput < CollectionInput
|
2012-01-26 18:53:16 +00:00
|
|
|
def input
|
|
|
|
label_method, value_method = detect_collection_methods
|
|
|
|
|
2012-01-26 19:15:32 +00:00
|
|
|
@builder.send("collection_#{input_type}",
|
2012-01-26 18:53:16 +00:00
|
|
|
attribute_name, collection, value_method, label_method,
|
|
|
|
input_options, input_html_options, &collection_block_for_nested_boolean_style
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def input_options
|
|
|
|
options = super
|
|
|
|
apply_default_collection_options!(options)
|
|
|
|
options
|
|
|
|
end
|
|
|
|
|
2012-01-26 19:11:10 +00:00
|
|
|
protected
|
|
|
|
|
|
|
|
def apply_default_collection_options!(options)
|
|
|
|
unless options.key?(:item_wrapper_tag)
|
|
|
|
options[:item_wrapper_tag] = SimpleForm.item_wrapper_tag
|
|
|
|
end
|
2012-01-27 18:09:45 +00:00
|
|
|
options[:item_wrapper_class] = [
|
|
|
|
item_wrapper_class, options[:item_wrapper_class], SimpleForm.item_wrapper_class
|
|
|
|
].compact.presence
|
|
|
|
|
2012-01-26 19:11:10 +00:00
|
|
|
unless options.key?(:collection_wrapper_tag)
|
|
|
|
options[:collection_wrapper_tag] = SimpleForm.collection_wrapper_tag
|
|
|
|
end
|
|
|
|
options[:collection_wrapper_class] = [
|
|
|
|
options[:collection_wrapper_class], SimpleForm.collection_wrapper_class
|
|
|
|
].compact.presence
|
|
|
|
end
|
2012-01-26 18:53:16 +00:00
|
|
|
|
2012-01-27 18:09:45 +00:00
|
|
|
def item_wrapper_class
|
|
|
|
"radio"
|
|
|
|
end
|
|
|
|
|
2012-01-26 18:53:16 +00:00
|
|
|
def collection_block_for_nested_boolean_style
|
|
|
|
return unless nested_boolean_style?
|
|
|
|
|
|
|
|
proc do |label_for, text, value, html_options|
|
2012-01-27 18:09:45 +00:00
|
|
|
@builder.radio_button(attribute_name, value, html_options) + text
|
2012-01-26 18:53:16 +00:00
|
|
|
end
|
|
|
|
end
|
2012-01-26 19:15:32 +00:00
|
|
|
|
2012-01-26 21:30:45 +00:00
|
|
|
# Do not attempt to generate label[for] attributes by default, unless an
|
|
|
|
# explicit html option is given. This avoids generating labels pointing to
|
|
|
|
# non existent fields.
|
|
|
|
def generate_label_for_attribute?
|
|
|
|
false
|
|
|
|
end
|
2012-01-26 18:53:16 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|