Sha256: 716da587c271a3da0f7e85192e3c7de47a77a0e742bee83a74ab366abcbeab68

Contents?: true

Size: 1.27 KB

Versions: 12

Compression:

Stored size: 1.27 KB

Contents

##
# 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"

class Mechanize::Form::Field
  attr_accessor :name, :value, :node, :type

  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

  def query_value
    [[@name, @value || '']]
  end

  def <=> other
    return 0 if self == other
    return 1 if Hash === node
    return -1 if Hash === other.node
    node <=> other.node
  end

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

  # This method is a shortcut to get field's DOM id.
  # Common usage: form.field_with(:dom_class => "foo")
  def dom_class
    node['class']
  end

  def inspect # :nodoc:
    "[%s:0x%x type: %s name: %s value: %s]" % [
      self.class.name.sub(/Mechanize::Form::/, '').downcase,
      object_id, @type, @name, @value
    ]
  end

end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
mechanize-2.5.1 lib/mechanize/form/field.rb
mechanize-2.5 lib/mechanize/form/field.rb
mechanize-2.4 lib/mechanize/form/field.rb
frameworks-capybara-0.2.0.rc6 vendor/bundle/ruby/1.8/gems/mechanize-2.3/lib/mechanize/form/field.rb
frameworks-capybara-0.2.0.rc5 vendor/bundle/ruby/1.8/gems/mechanize-2.3/lib/mechanize/form/field.rb
frameworks-capybara-0.2.0.rc4 vendor/bundle/ruby/1.8/gems/mechanize-2.3/lib/mechanize/form/field.rb
frameworks-capybara-0.2.0.rc3 vendor/bundle/ruby/1.8/gems/mechanize-2.3/lib/mechanize/form/field.rb
frameworks-capybara-0.2.0.rc2 vendor/bundle/ruby/1.8/gems/mechanize-2.3/lib/mechanize/form/field.rb
mechanize-2.3 lib/mechanize/form/field.rb
mechanize-2.2.1 lib/mechanize/form/field.rb
mechanize-2.2 lib/mechanize/form/field.rb
mechanize-2.1.1 lib/mechanize/form/field.rb