class Mechanize::Form::MultiSelectList
This class represents a select list where multiple values can be selected. #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
Calls superclass method
Mechanize::Form::Field.new
# File lib/mechanize/form/multi_select_list.rb, line 19 def initialize node value = [] @options = node.search('option').map { |n| Mechanize::Form::Option.new(n, self) } 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 37
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 54 elements_with :option
query_value()
click to toggle source
# File lib/mechanize/form/multi_select_list.rb, line 56 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 67 def select_all @value = [] options.each(&:tick) end
select_none()
click to toggle source
Select no options
# File lib/mechanize/form/multi_select_list.rb, line 61 def select_none @value = [] options.each(&:untick) end
selected_options()
click to toggle source
Get a list of all selected options
# File lib/mechanize/form/multi_select_list.rb, line 73 def selected_options @options.find_all(&:selected?) end
value()
click to toggle source
# File lib/mechanize/form/multi_select_list.rb, line 89 def value @value + selected_options.map(&:value) end
value=(values)
click to toggle source
# File lib/mechanize/form/multi_select_list.rb, line 77 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