Sha256: e1d12ac58ce9a47e925e3fddb935a0b5d1ef276cacd9399c508ed5a1f04cd129

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

# TODO See if this can be refactored to make use of some of the Choices code.
module FormtasticRebootstrap
  module Inputs
    class BooleanInput < Formtastic::Inputs::BooleanInput
      include Base

      # Skip rendering of .form-label in #bootstrap_wrapping
      def render_label?
        true
      end

      def to_html
        bootstrap_wrapping do
          hidden_field_html <<
          check_box_html
        end
      end

      def hidden_field_html
        template.hidden_field_tag(
          input_html_options[:name],
          unchecked_value,
          :id => nil,
          :disabled => input_html_options[:disabled]
        )
      end

      def label_with_nested_checkbox
        builder.label(
          method,
          label_text_with_embedded_checkbox,
          label_html_options
        )
      end

      def checkbox_wrapping(&block)
        template.content_tag(:div,
          template.capture(&block).html_safe,
          wrapper_html_options
        )
      end

      def wrapper_html_options
        super.tap do |options|
          options[:class] = (options[:class].split + ["checkbox"]).join(" ")
        end
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
formtastic_rebootstrap-0.0.2 lib/formtastic_rebootstrap/inputs/boolean_input.rb
formtastic_rebootstrap-0.0.1 lib/formtastic_rebootstrap/inputs/boolean_input.rb