Sha256: 531890f1aa05e368b69919a273433b41b9cd3747947c4e34cf40d0e19afc8abb

Contents?: true

Size: 1.23 KB

Versions: 12

Compression:

Stored size: 1.23 KB

Contents

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={}, &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
          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
      end
    end
  end
end

Trestle::Form::Builder.register(:collection_radio_buttons, Trestle::Form::Fields::CollectionRadioButtons)

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
trestle-0.10.0 lib/trestle/form/fields/collection_radio_buttons.rb
trestle-0.10.0.pre2 lib/trestle/form/fields/collection_radio_buttons.rb
trestle-0.10.0.pre lib/trestle/form/fields/collection_radio_buttons.rb
trestle-0.9.8 lib/trestle/form/fields/collection_radio_buttons.rb
trestle-0.9.7 lib/trestle/form/fields/collection_radio_buttons.rb
trestle-0.9.6 lib/trestle/form/fields/collection_radio_buttons.rb
trestle-0.9.5 lib/trestle/form/fields/collection_radio_buttons.rb
trestle-0.9.4 lib/trestle/form/fields/collection_radio_buttons.rb
trestle-0.9.3 lib/trestle/form/fields/collection_radio_buttons.rb
trestle-0.9.2 lib/trestle/form/fields/collection_radio_buttons.rb
trestle-0.9.1 lib/trestle/form/fields/collection_radio_buttons.rb
trestle-0.9.0 lib/trestle/form/fields/collection_radio_buttons.rb