Sha256: e09d7cc0940aed26c2e767345671b0a4a289d19eb8723fbc3531f3bf3489c9b5

Contents?: true

Size: 1.09 KB

Versions: 4

Compression:

Stored size: 1.09 KB

Contents

class Mechanize
  class Form
    # This class represents a field in a form.  It handles the following input
    # tags found in a form:
    # text, password, hidden, int, textarea
    #
    # To set the value of a field, just use the value method:
    # field.value = "foo"
    class Field
      attr_accessor :name, :value, :node

      def initialize node, value = node['value']
        @node = node
        @name = Util.html_unescape(node['name'])
        @value = if value.is_a? String
                   Util.html_unescape(value)
                 else
                   value
                 end
      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
    end

    class Text     < Field; end
    class Textarea < Field; end
    class Hidden   < Field; end
  end
end

Version data entries

4 entries across 4 versions & 3 rubygems

Version Path
aai10-mechanize-2.0.1.0 lib/mechanize/form/field.rb
neocoin-mechanize-2.0.2 lib/mechanize/form/field.rb
mechanize-2.0.1 lib/mechanize/form/field.rb
mechanize-2.0 lib/mechanize/form/field.rb