Sha256: 96add0d75fd133f94a3c65c7612644e0b3e7d7afbcbc2bb0d4099a69883f600e

Contents?: true

Size: 1.22 KB

Versions: 12

Compression:

Stored size: 1.22 KB

Contents

module Trestle
  class Form
    module Fields
      class CollectionCheckBoxes < Field
        include CheckBoxHelpers

        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_check_boxes(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.check_box(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_check_boxes, Trestle::Form::Fields::CollectionCheckBoxes)

Version data entries

12 entries across 12 versions & 1 rubygems

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