class 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 is used to maintain order for fields with Hash nodes
This fields value before it's sent through Util.html_unescape.
Public Class Methods
# File lib/mechanize/form/field.rb, line 28 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
# File lib/mechanize/form/field.rb, line 45 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
Shorthand for node.at
.
See also Nokogiri::XML::Node#at for details.
# File lib/mechanize/form/field.rb, line 95
Shorthand for node.at_css
.
See also Nokogiri::XML::Node#at_css for details.
# File lib/mechanize/form/field.rb, line 102
Shorthand for node.at_xpath
.
See also Nokogiri::XML::Node#at_xpath for details.
# File lib/mechanize/form/field.rb, line 115 def_delegators :node, :search, :css, :xpath, :at, :at_css, :at_xpath
Shorthand for node.css
.
See also Nokogiri::XML::Node#css for details.
# File lib/mechanize/form/field.rb, line 81
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 69 def dom_class node['class'] end
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 63 def dom_id node['id'] end
# File lib/mechanize/form/field.rb, line 41 def query_value [[@name, @value || '']] end
Shorthand for node.search
.
See Nokogiri::XML::Node#search for details.
# File lib/mechanize/form/field.rb, line 74
Shorthand for node.xpath
.
See also Nokogiri::XML::Node#xpath for details.
# File lib/mechanize/form/field.rb, line 88