Class: Mechanize::Form::Field

### Home Classes Methods

### In Files

- lib/mechanize/form/field.rb

### Parent

Object

### Methods

- ::new
- #<=>
- #dom_class
- #dom_id
- #query_value

### Files

- EXAMPLES.rdoc
- GUIDE.rdoc
- LICENSE.rdoc
- Manifest.txt
- README.rdoc

### Class/Module Index

Quicksearch

- Mechanize
- Mechanize::ChunkedTerminationError
- Mechanize::ContentTypeError
- Mechanize::Cookie
- Mechanize::CookieCMethods
- Mechanize::CookieDeprecated
- Mechanize::CookieIMethods
- Mechanize::CookieJar
- Mechanize::CookieJarIMethods
- Mechanize::DirectorySaver
- Mechanize::Download
- Mechanize::ElementMatcher
- Mechanize::ElementNotFoundError
- Mechanize::Error
- Mechanize::File
- Mechanize::FileConnection
- Mechanize::FileRequest
- Mechanize::FileResponse
- Mechanize::FileSaver
- Mechanize::Form
- Mechanize::Form::Button
- Mechanize::Form::CheckBox
- Mechanize::Form::Field
- Mechanize::Form::FileUpload
- Mechanize::Form::Hidden
- Mechanize::Form::ImageButton
- Mechanize::Form::Keygen
- Mechanize::Form::MultiSelectList
- Mechanize::Form::Option
- Mechanize::Form::RadioButton
- Mechanize::Form::Reset
- Mechanize::Form::SelectList
- Mechanize::Form::Submit
- Mechanize::Form::Text
- Mechanize::Form::Textarea
- Mechanize::HTTP
- Mechanize::HTTP::Agent
- Mechanize::HTTP::AuthChallenge
- Mechanize::HTTP::AuthRealm
- Mechanize::HTTP::AuthStore
- Mechanize::HTTP::ContentDispositionParser
- Mechanize::HTTP::WWWAuthenticateParser
- Mechanize::Headers
- Mechanize::History
- Mechanize::Image
- Mechanize::Page
- Mechanize::Page::Base
- Mechanize::Page::Frame
- Mechanize::Page::Image
- Mechanize::Page::Label
- Mechanize::Page::Link
- Mechanize::Page::MetaRefresh
- Mechanize::Parser
- Mechanize::PluggableParser
- Mechanize::Prependable
- Mechanize::RedirectLimitReachedError
- Mechanize::RedirectNotGetOrHeadError
- Mechanize::ResponseCodeError
- Mechanize::ResponseReadError
- Mechanize::RobotsDisallowedError
- Mechanize::TestCase
- Mechanize::UnauthorizedError
- Mechanize::UnsupportedSchemeError
- Mechanize::Util
- Mechanize::XmlFile
- HTTP
- HTTP::CookieJar

No matching classes.

# Mechanize::Form::Field

This class represents a field in a form. It handles the following input tags found in a form:

- text

- password

- hidden

- int

- textarea

- keygen

To set the value of a field, just use the value method:

    field.value = "foo"

### Attributes

index[RW]

index is used to maintain order for fields with Hash nodes

name[RW]
node[RW]
raw_value[R]

This fields value before it's sent through Util.html_unescape.

type[RW]
value[RW]

### Public Class Methods

new(node, value = node['value']) click to toggle source

    # File lib/mechanize/form/field.rb, line 25
    def initialize node, value = node['value']
      @node = node
      @name = Mechanize::Util.html_unescape(node['name'])
      @raw_value = value
      @value = if value.is_a? String
                 Mechanize::Util.html_unescape(value)
               else
                 value
               end

      @type = node['type']
    end

### Public Instance Methods

<=>(other) click to toggle source

    # File lib/mechanize/form/field.rb, line 42
    def <=> other
      return 0 if self == other

      # If both are hashes, sort by index
      if Hash === node && Hash === other.node && index
        return index <=> other.index
      end

      # Otherwise put Hash based fields at the end
      return 1 if Hash === node
      return -1 if Hash === other.node

      # Finally let nokogiri determine sort order
      node <=> other.node
    end

dom_class() click to toggle source

This method is a shortcut to get field's DOM class. Common usage: form.field_with(:dom_class => "foo")

    # File lib/mechanize/form/field.rb, line 66
    def dom_class
      node['class']
    end

dom_id() click to toggle source

This method is a shortcut to get field's DOM id. Common usage: form.field_with(:dom_id => "foo")

    # File lib/mechanize/form/field.rb, line 60
    def dom_id
      node['id']
    end

query_value() click to toggle source

    # File lib/mechanize/form/field.rb, line 38
    def query_value
      [[@name, @value || '']]
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.