Class: Mechanize::Form::SelectList

Inherits:
MultiSelectList show all
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.options.first.value

Options can also be selected by “clicking” or selecting them. See Option

Instance Attribute Summary

Attributes inherited from MultiSelectList

#options

Attributes inherited from Field

#name, #node

Instance Method Summary collapse

Methods inherited from MultiSelectList

#option, #select_all, #select_none, #selected_options

Methods included from ElementMatcher

#elements_with

Methods inherited from Field

#<=>, #dom_id

Constructor Details

#initialize(node) ⇒ SelectList

Returns a new instance of SelectList.



8
9
10
11
12
13
14
15
# File 'lib/mechanize/form/select_list.rb', line 8

def initialize node
  super
  if selected_options.length > 1
    selected_options.reverse[1..selected_options.length].each do |o|
      o.unselect
    end
  end
end

Instance Method Details

#query_valueObject



36
37
38
# File 'lib/mechanize/form/select_list.rb', line 36

def query_value
  value ? [[name, value]] : nil
end

#valueObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/mechanize/form/select_list.rb', line 17

def value
  value = super
  if value.length > 0
    value.last
  elsif @options.length > 0
    @options.first.value
  else
    nil
  end
end

#value=(new) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/mechanize/form/select_list.rb', line 28

def value=(new)
  if new != new.to_s and new.respond_to? :first
    super([new.first])
  else
    super([new.to_s])
  end
end