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

More cleanup between radio and check boxes inputs

This commit is contained in:
Carlos Antonio da Silva 2012-01-26 17:15:32 -02:00
parent 701f6eb4eb
commit 479306e846
2 changed files with 11 additions and 20 deletions

View file

@ -1,29 +1,16 @@
module SimpleForm
module Inputs
class CollectionCheckBoxesInput < CollectionRadioInput
def input
label_method, value_method = detect_collection_methods
protected
@builder.collection_check_boxes(
attribute_name, collection, value_method, label_method,
input_options, input_html_options, &collection_block_for_nested_boolean_style
)
end
private
# Checkbox components does not use the required html tag.
# See more info here - https://github.com/plataformatec/simple_form/issues/340#issuecomment-2871956
# Checkbox components do not use the required html tag.
# More info: https://github.com/plataformatec/simple_form/issues/340#issuecomment-2871956
def has_required?
false
end
def collection_block_for_nested_boolean_style
return unless nested_boolean_style?
proc do |label_for, text, value, html_options|
@builder.label(label_for, text) { @builder.check_box(attribute_name, html_options, value) }
end
def nested_boolean_style_item_tag(value, html_options)
@builder.check_box(attribute_name, html_options, value)
end
end
end

View file

@ -4,7 +4,7 @@ module SimpleForm
def input
label_method, value_method = detect_collection_methods
@builder.collection_radio(
@builder.send("collection_#{input_type}",
attribute_name, collection, value_method, label_method,
input_options, input_html_options, &collection_block_for_nested_boolean_style
)
@ -34,9 +34,13 @@ module SimpleForm
return unless nested_boolean_style?
proc do |label_for, text, value, html_options|
@builder.label(label_for, text) { @builder.radio_button(attribute_name, value, html_options) }
@builder.label(label_for, text) { nested_boolean_style_item_tag(value, html_options) }
end
end
def nested_boolean_style_item_tag(value, html_options)
@builder.radio_button(attribute_name, value, html_options)
end
end
end
end