Sha256: b985236c3a60b2db500bdf96b8ffed9ccee653abd5d829e21238b617bb802bb7

Contents?: true

Size: 1.83 KB

Versions: 4

Compression:

Stored size: 1.83 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,
                                    tag: @tag,
                                    **attribs.delete_if{ |k,v| [:tag, :name].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,
                            tag: 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

4 entries across 4 versions & 1 rubygems

Version Path
coprl-3.0.0.beta.4 lib/coprl/presenters/dsl/components/multi_select.rb
coprl-3.0.0.beta.3 lib/coprl/presenters/dsl/components/multi_select.rb
coprl-3.0.0.beta.2 lib/coprl/presenters/dsl/components/multi_select.rb
coprl-3.0.0.beta.1 lib/coprl/presenters/dsl/components/multi_select.rb