Sha256: 91511d0ce98c3764e09dddc27e5766df8800b00d9e8fafc336d1064cb3a7c6d3

Contents?: true

Size: 1.28 KB

Versions: 3

Compression:

Stored size: 1.28 KB

Contents

module BulmaFormBuilder
  module Inputs
    module CheckBox
      extend ActiveSupport::Concern

      include Base

      included do
        def check_box_with_bulma(name, options = {}, checked_value = '1', unchecked_value = '0', &block)
          options = options.symbolize_keys!
          check_box_options = options.except(:class, :label, :label_class, :error_message, :help, :inline, :custom, :hide_label, :skip_label, :wrapper_class)
          wrapper_class = ['field', options[:wrapper_class]].compact

          content_tag(:div, class: wrapper_class) do
            checkbox = content_tag(:label, class: 'checkbox') do
              html = check_box_without_bulma(name, check_box_options, checked_value, unchecked_value)
              html.concat(check_box_label(name)) unless options[:skip_label]
              html.concat(generate_error(name)) if options[:error_message]
              html
            end

            if options[:help].present?
              checkbox.concat(content_tag(:p, options[:help], class: 'help'))
            end

            checkbox
          end
        end

        bulma_alias(:check_box)
      end

      private

      def check_box_label(name)
        content_tag(:span, object.class.human_attribute_name(name), class: 'control-label')
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bulma_form_builder-0.3.1 lib/bulma_form_builder/inputs/check_box.rb
bulma_form_builder-0.3.0 lib/bulma_form_builder/inputs/check_box.rb
bulma_form_builder-0.2.1 lib/bulma_form_builder/inputs/check_box.rb