Sha256: df3a3611713b662b1cddb75bc1456aa3f8379514d470eb62e86bc2889d4f6642

Contents?: true

Size: 1.77 KB

Versions: 116

Compression:

Stored size: 1.77 KB

Contents

# frozen_string_literal: true

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

116 entries across 116 versions & 1 rubygems

Version Path
effective_bootstrap-1.19.13 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-1.19.12 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-1.19.11 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-1.19.10 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-1.19.9 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-1.19.8 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-1.19.7 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-1.19.6 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-1.19.5 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-1.19.4 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-1.19.3 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-1.19.2 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-1.19.1 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-1.19.0 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-1.18.7 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-1.18.4 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-1.18.3 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-1.18.2 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-1.18.1 app/models/effective/form_inputs/check_box.rb
effective_bootstrap-1.18.0 app/models/effective/form_inputs/check_box.rb