Sha256: ddfcb8e3825c2f5abd9a8ab9d30c7b2da8367cf33487861bdbb10df6a756e08d

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

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

      def to_html
        bootstrap_wrapping do
          hidden_field_html <<
          "".html_safe <<
          [label_with_nested_checkbox, hint_html].join("\n").html_safe
        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 - ["form-group"] + ["checkbox"]).join(" ")
        end
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
formtastic-bootstrap-3.1.0 lib/formtastic-bootstrap/inputs/boolean_input.rb