Class | Mechanize::Form::SelectList |
In: |
lib/mechanize/form/select_list.rb
|
Parent: | MultiSelectList |
This class represents a select list or drop down box in a Form. Set the value for the list by calling SelectList#value=. SelectList contains a list of Option that were found. After finding the correct option, set the select lists value to the option value:
selectlist.value = selectlist.options.first.value
Options can also be selected by "clicking" or selecting them. See Option
# File lib/mechanize/form/select_list.rb, line 10 10: def initialize node 11: super 12: if selected_options.length > 1 13: selected_options.reverse[1..selected_options.length].each do |o| 14: o.unselect 15: end 16: end 17: end
Find one option on this select list with criteria Example:
select_list.option_with(:value => '1').value = 'foo'
# File lib/mechanize/form/select_list.rb, line 38 38: def option_with criteria 39: f = options_with(criteria).first 40: yield f if block_given? 41: f 42: end
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/select_list.rb, line 25 25: def options_with criteria 26: criteria = {:name => criteria} if String === criteria 27: f = @options.find_all do |thing| 28: criteria.all? { |k,v| v === thing.send(k) } 29: end 30: yield f if block_given? 31: f 32: end
# File lib/mechanize/form/select_list.rb, line 63 63: def query_value 64: value ? [[name, value]] : nil 65: end
# File lib/mechanize/form/select_list.rb, line 44 44: def value 45: value = super 46: if value.length > 0 47: value.last 48: elsif @options.length > 0 49: @options.first.value 50: else 51: nil 52: end 53: end