Class: Mechanize::Form::MultiSelectList

### Home Classes Methods

### In Files

- lib/mechanize/form/multi_select_list.rb

### Parent

Mechanize::Form::Field

### Methods

- ::new
- #option_with
- #options_with
- #query_value
- #select_all
- #select_none
- #selected_options
- #value
- #value=

### Files

- EXAMPLES.rdoc
- GUIDE.rdoc
- LICENSE.rdoc
- Manifest.txt
- README.rdoc

### Class/Module Index

Quicksearch

- Mechanize
- Mechanize::ChunkedTerminationError
- Mechanize::ContentTypeError
- Mechanize::Cookie
- Mechanize::CookieCMethods
- Mechanize::CookieDeprecated
- Mechanize::CookieIMethods
- Mechanize::CookieJar
- Mechanize::CookieJarIMethods
- Mechanize::DirectorySaver
- Mechanize::Download
- Mechanize::ElementMatcher
- Mechanize::ElementNotFoundError
- Mechanize::Error
- Mechanize::File
- Mechanize::FileConnection
- Mechanize::FileRequest
- Mechanize::FileResponse
- Mechanize::FileSaver
- Mechanize::Form
- Mechanize::Form::Button
- Mechanize::Form::CheckBox
- Mechanize::Form::Field
- Mechanize::Form::FileUpload
- Mechanize::Form::Hidden
- Mechanize::Form::ImageButton
- Mechanize::Form::Keygen
- Mechanize::Form::MultiSelectList
- Mechanize::Form::Option
- Mechanize::Form::RadioButton
- Mechanize::Form::Reset
- Mechanize::Form::SelectList
- Mechanize::Form::Submit
- Mechanize::Form::Text
- Mechanize::Form::Textarea
- Mechanize::HTTP
- Mechanize::HTTP::Agent
- Mechanize::HTTP::AuthChallenge
- Mechanize::HTTP::AuthRealm
- Mechanize::HTTP::AuthStore
- Mechanize::HTTP::ContentDispositionParser
- Mechanize::HTTP::WWWAuthenticateParser
- Mechanize::Headers
- Mechanize::History
- Mechanize::Image
- Mechanize::Page
- Mechanize::Page::Base
- Mechanize::Page::Frame
- Mechanize::Page::Image
- Mechanize::Page::Label
- Mechanize::Page::Link
- Mechanize::Page::MetaRefresh
- Mechanize::Parser
- Mechanize::PluggableParser
- Mechanize::Prependable
- Mechanize::RedirectLimitReachedError
- Mechanize::RedirectNotGetOrHeadError
- Mechanize::ResponseCodeError
- Mechanize::ResponseReadError
- Mechanize::RobotsDisallowedError
- Mechanize::TestCase
- Mechanize::UnauthorizedError
- Mechanize::UnsupportedSchemeError
- Mechanize::Util
- Mechanize::XmlFile
- HTTP
- HTTP::CookieJar

No matching classes.

# Mechanize::Form::MultiSelectList

This class represents a select list where multiple values can be selected. MultiSelectList#value= accepts an array, and those values are used as values for the select list. For example, to select multiple values, simply do this:

    list.value = ['one', 'two']

Single values are still supported, so these two are the same:

    list.value = ['one']
    list.value = 'one'

### Attributes

options[RW]

### Public Class Methods

new(node) click to toggle source

    # File lib/mechanize/form/multi_select_list.rb, line 20
    def initialize node
      value = []
      @options = []

      # parse
      node.search('option').each do |n|
        @options << Mechanize::Form::Option.new(n, self)
      end

      super node, value
    end

### Public Instance Methods

option_with click to toggle source

Find one option on this select list with `criteria`

Example:

    select_list.option_with(:value => '1').value = 'foo'

    # File lib/mechanize/form/multi_select_list.rb, line 41

options_with click to toggle source

Find all options on this select list with `criteria`

Example:

    select_list.options_with(:value => /1|2/).each do |field|
      field.value = '20'
    end

    # File lib/mechanize/form/multi_select_list.rb, line 58
    elements_with :option

query_value() click to toggle source

    # File lib/mechanize/form/multi_select_list.rb, line 60
    def query_value
      value ? value.map { |v| [name, v] } : ''
    end

select_all() click to toggle source

Select all options

    # File lib/mechanize/form/multi_select_list.rb, line 71
    def select_all
      @value = []
      options.each { |o| o.tick }
    end

select_none() click to toggle source

Select no options

    # File lib/mechanize/form/multi_select_list.rb, line 65
    def select_none
      @value = []
      options.each { |o| o.untick }
    end

selected_options() click to toggle source

Get a list of all selected options

    # File lib/mechanize/form/multi_select_list.rb, line 77
    def selected_options
      @options.find_all { |o| o.selected? }
    end

value() click to toggle source

    # File lib/mechanize/form/multi_select_list.rb, line 93
    def value
      value = []
      value.concat @value
      value.concat selected_options.map { |o| o.value }
      value
    end

value=(values) click to toggle source

    # File lib/mechanize/form/multi_select_list.rb, line 81
    def value=(values)
      select_none
      [values].flatten.each do |value|
        option = options.find { |o| o.value == value }
        if option.nil?
          @value.push(value)
        else
          option.select
        end
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.