class Mechanize::Form::Field

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

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

field.value = "foo"

Attributes

name[RW]
node[RW]
type[RW]
value[RW]

Public Class Methods

new(node, value = node['value']) click to toggle source
# File lib/mechanize/form/field.rb, line 19
def initialize node, value = node['value']
  @node = node
  @name = Mechanize::Util.html_unescape(node['name'])
  @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 35
def <=> other
  return 0 if self == other
  return 1 if Hash === node
  return -1 if Hash === other.node
  node <=> other.node
end
dom_class() click to toggle source

This method is a shortcut to get field’s DOM id. Common usage: form.field_with(:#dom_class => “foo”)

# File lib/mechanize/form/field.rb, line 50
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 44
def dom_id
  node['id']
end
query_value() click to toggle source
# File lib/mechanize/form/field.rb, line 31
def query_value
  [[@name, @value || '']]
end