Sha256: 056744066ab26cdb5dffb144fbcde2cf22ab7e05c660c3fa71b4ac214077f616

Contents?: true

Size: 1.87 KB

Versions: 8

Compression:

Stored size: 1.87 KB

Contents

module Coprl
  module Presenters
    module DSL
      module Components
        class MultiSelect < Select

          def initialize(**attribs_, &block)
            super(type: :multi_select, **attribs_, &block)
            @required = attribs.delete(:required)
            @full_width = attribs.delete(:full_width){ true }
            @outlined = attribs.delete(:outlined){ true }
            @options = []
            expand!
          end

          def check_option(**attribs, &block)
            @options << CheckOption.new(parent: self,
                                    name: @name,
                                    input_tag: @input_tag,
                                    **attribs.delete_if{ |k,v| [:tag, :name, :input_tag].include?(k) }, &block)
          end

          class CheckOption < EventBase

            attr_reader :selected, :disabled

            def initialize(**attribs_, &block)
              super(type: :multi_select_option, **attribs_, &block)
              @value =     attribs.delete(:value)
              @text =      attribs.delete(:text)
              @selected =  attribs.delete(:selected){ true }
              @disabled =  attribs.delete(:disabled)
              self.checkbox(name: "#{attribs[:name]}[]",
                            value: @value,
                            text: @text,
                            input_tag: self.input_tag,
                            checked: @selected,
                            disabled: @disabled,
                            &block)
              expand!
            end

            def checkbox(**attributes, &block)
              return @checkbox if locked?
              @checkbox = Components::Checkbox.new(parent: self,
                                                   **attributes,
                                                   &block)
            end

          end

        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
coprl-3.0.0.beta.12 lib/coprl/presenters/dsl/components/multi_select.rb
coprl-3.0.0.beta.11 lib/coprl/presenters/dsl/components/multi_select.rb
coprl-3.0.0.beta.10 lib/coprl/presenters/dsl/components/multi_select.rb
coprl-3.0.0.beta.9 lib/coprl/presenters/dsl/components/multi_select.rb
coprl-3.0.0.beta.8 lib/coprl/presenters/dsl/components/multi_select.rb
coprl-3.0.0.beta.7 lib/coprl/presenters/dsl/components/multi_select.rb
coprl-3.0.0.beta.6 lib/coprl/presenters/dsl/components/multi_select.rb
coprl-3.0.0.beta.5 lib/coprl/presenters/dsl/components/multi_select.rb