Sha256: 705b795a6858a21f3abf2c0405230c436979454326089a75493767edec579f0f

Contents?: true

Size: 1.74 KB

Versions: 132

Compression:

Stored size: 1.74 KB

Contents

module Effective
  module FormInputs
    class CheckBox < Effective::FormInput

      def to_html(&block)
        case layout
        when :horizontal
          build_wrapper do
            content_tag(:div, '', class: 'col-sm-2') + content_tag(:div, build_content(&block), class: 'col-sm-10')
          end
        else
          build_content(&block)
        end
      end

      def build_content(&block)
        build_check_box_wrap { build_input(&block) + build_label + build_feedback + build_hint }
      end

      def build_check_box_wrap(&block)
        if custom?
          content_tag(:div, yield, options[:wrapper])
        else
          content_tag(:div, yield, options[:wrapper])
        end
      end

      def wrapper_options
        if custom? && inline?
          { class: 'form-group custom-control custom-checkbox custom-control-inline' }
        elsif custom?
          { class: 'form-group custom-control custom-checkbox' }
        elsif inline?
          { class: 'form-check form-check-inline' }
        else
          { class: 'form-check' }
        end
      end

      def label_options
        if custom?
          { class: 'custom-control-label' }
        else
          { class: 'form-check-label' }
        end
      end

      def input_html_options
        if custom?
          { class: 'custom-control-input', id: unique_id }
        else
          { class: 'form-check-input', id: unique_id }
        end
      end

      private

      def inline? # default false
        return @inline unless @inline.nil?
        @inline = ((options[:input] || {}).delete(:inline) == true)
      end

      def custom? # default true
        return @custom unless @custom.nil?
        @custom = (options.delete(:custom) != false)
      end

    end
  end
end

Version data entries

132 entries across 132 versions & 1 rubygems

Version Path
effective_bootstrap-0.9.47 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-0.9.46 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-0.9.45 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-0.9.44 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-0.9.43 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-0.9.42 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-0.9.41 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-0.9.40 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-0.9.39 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-0.9.38 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-0.9.37 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-0.9.36 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-0.9.35 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-0.9.34 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-0.9.33 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-0.9.32 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-0.9.31 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-0.9.30 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-0.9.29 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-0.9.28 app/models/effective/form_inputs/check_box.rb