From 479306e8464db4a8a4537406d00f26025d4ff6f6 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Thu, 26 Jan 2012 17:15:32 -0200 Subject: [PATCH] More cleanup between radio and check boxes inputs --- .../inputs/collection_check_boxes_input.rb | 23 ++++--------------- .../inputs/collection_radio_input.rb | 8 +++++-- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/lib/simple_form/inputs/collection_check_boxes_input.rb b/lib/simple_form/inputs/collection_check_boxes_input.rb index 12eb6feb..575712a8 100644 --- a/lib/simple_form/inputs/collection_check_boxes_input.rb +++ b/lib/simple_form/inputs/collection_check_boxes_input.rb @@ -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 diff --git a/lib/simple_form/inputs/collection_radio_input.rb b/lib/simple_form/inputs/collection_radio_input.rb index 7d0c2f2a..e29ebfaf 100644 --- a/lib/simple_form/inputs/collection_radio_input.rb +++ b/lib/simple_form/inputs/collection_radio_input.rb @@ -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