class 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
Public Class Methods
Source
# File lib/mechanize/form/multi_select_list.rb, line 20 def initialize node value = [] @options = node.search('option').map { |n| Mechanize::Form::Option.new(n, self) } super node, value end
Calls superclass method
Mechanize::Form::Field::new
Public Instance Methods
Source
# File lib/mechanize/form/multi_select_list.rb, line 30
Find one option on this select list with criteria
Example:
select_list.option_with(:value => '1').value = 'foo'
Source
# File lib/mechanize/form/multi_select_list.rb, line 39
Same as option_with
but raises an ElementNotFoundError if no button matches criteria
Source
# File lib/mechanize/form/multi_select_list.rb, line 55 elements_with :option
Find all options on this select list with criteria
Example:
select_list.options_with(:value => /1|2/).each do |field| field.value = '20' end
Source
# File lib/mechanize/form/multi_select_list.rb, line 57 def query_value value ? value.map { |v| [name, v] } : '' end
Source
# File lib/mechanize/form/multi_select_list.rb, line 68 def select_all @value = [] options.each(&:tick) end
Select all options
Source
# File lib/mechanize/form/multi_select_list.rb, line 62 def select_none @value = [] options.each(&:untick) end
Select no options
Source
# File lib/mechanize/form/multi_select_list.rb, line 74 def selected_options @options.find_all(&:selected?) end
Get a list of all selected options
Source
# File lib/mechanize/form/multi_select_list.rb, line 90 def value @value + selected_options.map(&:value) end
Source
# File lib/mechanize/form/multi_select_list.rb, line 78 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