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'
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
41:
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 52 52: elements_with :option
# File lib/mechanize/form/multi_select_list.rb, line 54 54: def query_value 55: value ? value.map { |v| [name, v] } : '' 56: end
Select all options
# File lib/mechanize/form/multi_select_list.rb, line 65 65: def select_all 66: @value = [] 67: options.each { |o| o.tick } 68: end
Select no options
# File lib/mechanize/form/multi_select_list.rb, line 59 59: def select_none 60: @value = [] 61: options.each { |o| o.untick } 62: end
Get a list of all selected options
# File lib/mechanize/form/multi_select_list.rb, line 71 71: def selected_options 72: @options.find_all { |o| o.selected? } 73: end
# File lib/mechanize/form/multi_select_list.rb, line 87 87: def value 88: value = [] 89: value.concat @value 90: value.concat selected_options.map { |o| o.value } 91: value 92: end
# File lib/mechanize/form/multi_select_list.rb, line 75 75: def value=(values) 76: select_none 77: [values].flatten.each do |value| 78: option = options.find { |o| o.value == value } 79: if option.nil? 80: @value.push(value) 81: else 82: option.select 83: end 84: end 85: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.