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'
# File lib/mechanize/form/multi_select_list.rb, line 26 26: def query_value 27: value ? value.collect { |v| [name, v] } : '' 28: end
Select all options
# File lib/mechanize/form/multi_select_list.rb, line 37 37: def select_all 38: @value = [] 39: options.each { |o| o.tick } 40: end
Select no options
# File lib/mechanize/form/multi_select_list.rb, line 31 31: def select_none 32: @value = [] 33: options.each { |o| o.untick } 34: end
Get a list of all selected options
# File lib/mechanize/form/multi_select_list.rb, line 43 43: def selected_options 44: @options.find_all { |o| o.selected? } 45: end
# File lib/mechanize/form/multi_select_list.rb, line 59 59: def value 60: value = [] 61: value.push(*@value) 62: value.push(*selected_options.collect { |o| o.value }) 63: value 64: end
# File lib/mechanize/form/multi_select_list.rb, line 47 47: def value=(values) 48: select_none 49: [values].flatten.each do |value| 50: option = options.find { |o| o.value == value } 51: if option.nil? 52: @value.push(value) 53: else 54: option.select 55: end 56: end 57: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.