Sha256: 662a001a71b35b599b9798f3c269463d4dd6625bc04f06bb14bcffdb53cc62fa

Contents?: true

Size: 1.48 KB

Versions: 58

Compression:

Stored size: 1.48 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, class: 'form-group custom-control custom-checkbox' + (inline? ? ' custom-control-inline' : ''))
        else
          content_tag(:div, yield, class: 'form-check' + (inline? ? ' form-check-inline' : ''))
        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

58 entries across 58 versions & 1 rubygems

Version Path
effective_bootstrap-0.0.19 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-0.0.18 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-0.0.17 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-0.0.16 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-0.0.15 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-0.0.14 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-0.0.13 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-0.0.12 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-0.0.11 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-0.0.10 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-0.0.9 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-0.0.8 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-0.0.7 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-0.0.6 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-0.0.5 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-0.0.4 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-0.0.3 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-0.0.2 app/models/effective/form_inputs/check_box.rb