Class | Mechanize::Form::MultiSelectList |
In: |
lib/mechanize/form/multi_select_list.rb
|
Parent: | Field |
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'
options | [RW] |
# File lib/mechanize/form/multi_select_list.rb, line 14 14: def initialize node 15: value = [] 16: @options = [] 17: 18: # parse 19: node.search('option').each do |n| 20: option = Option.new(n, self) 21: @options << option 22: end 23: super(node, value) 24: end
# 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