lib/trestle/form/fields/collection_radio_buttons.rb in trestle-0.8.13 vs lib/trestle/form/fields/collection_radio_buttons.rb in trestle-0.9.0

- old
+ new

@@ -1,23 +1,33 @@ module Trestle class Form module Fields class CollectionRadioButtons < Field + include RadioButtonHelpers + attr_reader :collection, :value_method, :text_method, :html_options - def initialize(builder, template, name, collection, value_method, text_method, options={}, html_options={}) - super(builder, template, name, options) + def initialize(builder, template, name, collection, value_method, text_method, options={}, html_options={}, &block) + super(builder, template, name, options, &block) @collection, @value_method, @text_method = collection, value_method, text_method @html_options = default_html_options.merge(html_options) end def field - content_tag(:div, class: "radio-buttons") do - builder.raw_collection_radio_buttons(name, collection, value_method, text_method, options, html_options) do |b| - b.label(class: "radio-inline") { b.radio_button + b.text } + builder.raw_collection_radio_buttons(name, collection, value_method, text_method, options, html_options) do |b| + if block + block.call(b) + else + content_tag(:div, class: default_wrapper_class) do + b.radio_button(class: input_class) + b.label(class: label_class) { b.text } + end end end + end + + def defaults + super.merge(inline: true) end def default_html_options Trestle::Options.new end