Sha256: 78660db00319261b5db11366a16de880597fd1b79e8f8f96e9eb3212c2802b0a

Contents?: true

Size: 1021 Bytes

Versions: 18

Compression:

Stored size: 1021 Bytes

Contents

# 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
class Mechanize::Form::SelectList < Mechanize::Form::MultiSelectList

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

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

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

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

end

Version data entries

18 entries across 18 versions & 4 rubygems

Version Path
mechanize-2.5.1 lib/mechanize/form/select_list.rb
mechanize-2.5 lib/mechanize/form/select_list.rb
mechanize-2.4 lib/mechanize/form/select_list.rb
frameworks-capybara-0.2.0.rc6 vendor/bundle/ruby/1.8/gems/mechanize-2.3/lib/mechanize/form/select_list.rb
frameworks-capybara-0.2.0.rc5 vendor/bundle/ruby/1.8/gems/mechanize-2.3/lib/mechanize/form/select_list.rb
frameworks-capybara-0.2.0.rc4 vendor/bundle/ruby/1.8/gems/mechanize-2.3/lib/mechanize/form/select_list.rb
frameworks-capybara-0.2.0.rc3 vendor/bundle/ruby/1.8/gems/mechanize-2.3/lib/mechanize/form/select_list.rb
frameworks-capybara-0.2.0.rc2 vendor/bundle/ruby/1.8/gems/mechanize-2.3/lib/mechanize/form/select_list.rb
mechanize-2.3 lib/mechanize/form/select_list.rb
mechanize-2.2.1 lib/mechanize/form/select_list.rb
mechanize-2.2 lib/mechanize/form/select_list.rb
mechanize-2.1.1 lib/mechanize/form/select_list.rb
domo-0.0.5 vendor/bundle/ruby/1.9.1/gems/mechanize-2.1/lib/mechanize/form/select_list.rb
diamond-mechanize-2.4 lib/mechanize/form/select_list.rb
diamond-mechanize-2.3 lib/mechanize/form/select_list.rb
diamond-mechanize-2.1 lib/mechanize/form/select_list.rb
mechanize-2.1 lib/mechanize/form/select_list.rb
mechanize-2.1.pre.1 lib/mechanize/form/select_list.rb