Sha256: 59e2eff251c8fe5cef1f44f5119e8d40d9e9b1e3e77d90edf0a7b2c7ab4a0e9d

Contents?: true

Size: 1.57 KB

Versions: 3

Compression:

Stored size: 1.57 KB

Contents

module Druid
  module Elements
    class SelectList < Element

      def self.finders
        super + [:value, :text, :label]
      end

      def [](idx)
        options[idx]
      end

      def options
        element.options.map { |e| Druid::Elements::Option.new(e)}
      end

      #
      # Select a value from the list
      #
      def select(value)
        element.select(value)
      end

      #
      # Select the options whose value attribute matches the Given
      # string
      #
      def select_value(value)
        element.select_value(value)
      end

      #
      # @return [Array<String>] An array of strings representing the text of the currently selected options.
      #
      def selected_options
        element.selected_options.map { |e| e.text }.compact
      end

      #
      # @return [Array<String>] An array of strings representing the value of the currently selected options.
      def selected_values
        element.selected_options.map { |e| e.value }.compact
      end

      #
      # Returns true if the select list has one or more options where text or label matches the given value.
      #
      # @param [String, Regexp] value A value
      # @return [Boolean]
      def include? value
        element.include? value
      end

      #
      # Returns true if any of the selected options' text or label match the given value.
      # @param [String, Regexp] value A value
      # @return [Boolean]
      def selected? value
        element.selected? value
      end
    end

    Druid::Elements.tag_to_class[:select] = Druid::Elements::SelectList
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
druid-ts-1.2.2 lib/druid/elements/select_list.rb
druid-ts-1.2.1 lib/druid/elements/select_list.rb
druid-ts-1.2.0 lib/druid/elements/select_list.rb