Sha256: fac034512da0ef70481b63e5048a3d3c997fb0e0699b95cf7cbc6fbc54c618f3

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

module SimpleForm
  class DefaultFormBuilder < SimpleForm::FormBuilder
    CHECKBOX_WRAPPER = :checkbox
    RADIO_WRAPPER = :radio

    map_type :datetime, to: SimpleForm::Inputs::DateTimePickerInput
    map_type :date,     to: SimpleForm::Inputs::DatePickerInput

    def checkbox(attribute_name, options = {}, &block)
      options[:wrapper] ||= self.class::CHECKBOX_WRAPPER
      options[:as] ||= :boolean
      input attribute_name, options, &block
    end

    def radio(attribute_name, options = {}, &block)
      options[:wrapper] ||= self.class::RADIO_WRAPPER
      input attribute_name, options, &block
    end

    def input(attribute_name, options = {}, &block)
      options[:wrapper] ||= self.class::CHECKBOX_WRAPPER if options[:as] == :boolean
      super
    end

    def collection_check_boxes(method, collection, value_method, text_method, options = {}, html_options = {}, &block)
      options[:collection_wrapper_tag] ||= :div
      options[:collection_wrapper_class] ||= 'form-group'
      options[:item_wrapper_tag] ||= :div
      options[:item_wrapper_class] ||= 'checkbox'

      if block_given?
        super
      else
        super do |input|
          input.label { input.check_box + input.text }
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
simple_form_bootstrap3-0.3.2 lib/simple_form/default_form_builder.rb