Class: Mechanize::Form::SelectList
- Inherits:
-
MultiSelectList
- Object
- Field
- MultiSelectList
- Mechanize::Form::SelectList
- Defined in:
- lib/mechanize/form/select_list.rb
Overview
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..first.value
Options can also be selected by “clicking” or selecting them. See Option
Instance Attribute Summary
Attributes inherited from MultiSelectList
Attributes inherited from Field
#index, #name, #node, #raw_value, #type
Instance Method Summary collapse
-
#initialize(node) ⇒ SelectList
constructor
A new instance of SelectList.
- #query_value ⇒ Object
- #value ⇒ Object
- #value=(new_value) ⇒ Object
Methods inherited from MultiSelectList
#option, #select_all, #select_none, #selected_options
Methods included from ElementMatcher
Methods inherited from Field
#<=>, #dom_class, #dom_id, #inspect
Constructor Details
#initialize(node) ⇒ SelectList
Returns a new instance of SelectList.
12 13 14 15 16 17 18 19 |
# File 'lib/mechanize/form/select_list.rb', line 12 def initialize node super if .length > 1 .reverse[1...length].each do |o| o.unselect end end end |
Instance Method Details
#query_value ⇒ Object
40 41 42 |
# File 'lib/mechanize/form/select_list.rb', line 40 def query_value value ? [[name, value]] : nil end |
#value ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/mechanize/form/select_list.rb', line 21 def value value = super if value.length > 0 value.last elsif @options.length > 0 @options.first.value else nil end end |
#value=(new_value) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/mechanize/form/select_list.rb', line 32 def value=(new_value) if new_value != new_value.to_s and new_value.respond_to? :first super([new_value.first]) else super([new_value.to_s]) end end |