Sha256: d7f0e1a7ad6b49d368afe108cd4c18b7c684658134168acf21992e736da0a502

Contents?: true

Size: 1.2 KB

Versions: 22

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

module Phlexi
  module Form
    module Components
      class CollectionCheckboxes < Base
        include Concerns::HandlesInput
        include Concerns::HandlesArrayInput
        include Concerns::AcceptsChoices

        def view_template
          div(**attributes.slice(:id, :class)) do
            field.repeated(choices.values) do |builder|
              render builder.hidden_field_tag if builder.index == 0

              field = builder.field(
                label: choices[builder.key],
                # We set the attributes here so they are applied to all input components even if the user decides to use a block
                input_attributes: {
                  checked_value: builder.key,
                  include_hidden: false,
                  checked: selected?(builder.key)
                }
              )
              if block_given?
                yield field
              else
                render field.checkbox_tag
                render field.label_tag
              end
            end
          end
        end

        protected

        def build_attributes
          super
          attributes[:multiple] = true
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
phlexi-form-0.8.3 lib/phlexi/form/components/collection_checkboxes.rb
phlexi-form-0.8.2 lib/phlexi/form/components/collection_checkboxes.rb
phlexi-form-0.8.1 lib/phlexi/form/components/collection_checkboxes.rb
phlexi-form-0.8.0 lib/phlexi/form/components/collection_checkboxes.rb
phlexi-form-0.7.2 lib/phlexi/form/components/collection_checkboxes.rb
phlexi-form-0.7.1 lib/phlexi/form/components/collection_checkboxes.rb
phlexi-form-0.7.0 lib/phlexi/form/components/collection_checkboxes.rb
phlexi-form-0.6.2 lib/phlexi/form/components/collection_checkboxes.rb
phlexi-form-0.6.1 lib/phlexi/form/components/collection_checkboxes.rb
phlexi-form-0.6.0 lib/phlexi/form/components/collection_checkboxes.rb
phlexi-form-0.5.11 lib/phlexi/form/components/collection_checkboxes.rb
phlexi-form-0.5.10 lib/phlexi/form/components/collection_checkboxes.rb
phlexi-form-0.5.9 lib/phlexi/form/components/collection_checkboxes.rb
phlexi-form-0.5.8 lib/phlexi/form/components/collection_checkboxes.rb
phlexi-form-0.5.7 lib/phlexi/form/components/collection_checkboxes.rb
phlexi-form-0.5.6 lib/phlexi/form/components/collection_checkboxes.rb
phlexi-form-0.5.5 lib/phlexi/form/components/collection_checkboxes.rb
phlexi-form-0.5.4 lib/phlexi/form/components/collection_checkboxes.rb
phlexi-form-0.5.3 lib/phlexi/form/components/collection_checkboxes.rb
phlexi-form-0.5.2 lib/phlexi/form/components/collection_checkboxes.rb