Class: Webrat::Field
Overview
Instance Attribute Summary collapse
Attributes inherited from Element
#element
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Element
#inspect, load_all, #path
Constructor Details
#initialize(*args) ⇒ Field
Returns a new instance of Field.
59
60
61
62
|
# File 'lib/webrat/core/elements/field.rb', line 59
def initialize(*args)
super
@value = default_value
end
|
Instance Attribute Details
Returns the value of attribute value.
13
14
15
|
# File 'lib/webrat/core/elements/field.rb', line 13
def value
@value
end
|
Class Method Details
.field_class(element) ⇒ Object
.field_classes ⇒ Object
23
24
25
|
# File 'lib/webrat/core/elements/field.rb', line 23
def self.field_classes
@field_classes || []
end
|
.inherited(klass) ⇒ Object
27
28
29
30
31
|
# File 'lib/webrat/core/elements/field.rb', line 27
def self.inherited(klass)
@field_classes ||= []
@field_classes << klass
end
|
.load(session, element) ⇒ Object
33
34
35
36
|
# File 'lib/webrat/core/elements/field.rb', line 33
def self.load(session, element)
return nil if element.nil?
session.elements[Webrat::XML.xpath_to(element)] ||= field_class(element).new(session, element)
end
|
.xpath_search ⇒ Object
15
16
17
|
# File 'lib/webrat/core/elements/field.rb', line 15
def self.xpath_search
[".//button", ".//input", ".//textarea", ".//select"]
end
|
.xpath_search_excluding_hidden ⇒ Object
19
20
21
|
# File 'lib/webrat/core/elements/field.rb', line 19
def self.xpath_search_excluding_hidden
[".//button", ".//input[ @type != 'hidden']", ".//textarea", ".//select"]
end
|
Instance Method Details
#disabled? ⇒ Boolean
73
74
75
|
# File 'lib/webrat/core/elements/field.rb', line 73
def disabled?
@element.attributes.has_key?("disabled") && Webrat::XML.attribute(@element, "disabled") != 'false'
end
|
69
70
71
|
# File 'lib/webrat/core/elements/field.rb', line 69
def id
Webrat::XML.attribute(@element, "id")
end
|
#label_text ⇒ Object
64
65
66
67
|
# File 'lib/webrat/core/elements/field.rb', line 64
def label_text
return nil if labels.empty?
labels.first.text
end
|
#raise_error_if_disabled ⇒ Object
77
78
79
80
|
# File 'lib/webrat/core/elements/field.rb', line 77
def raise_error_if_disabled
return unless disabled?
raise DisabledFieldError.new("Cannot interact with disabled form element (#{self})")
end
|
#set(value) ⇒ Object
95
96
97
|
# File 'lib/webrat/core/elements/field.rb', line 95
def set(value)
@value = value
end
|
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/webrat/core/elements/field.rb', line 82
def to_param
return nil if disabled?
case Webrat.configuration.mode
when :rails
parse_rails_request_params("#{name}=#{escaped_value}")
when :merb
::Merb::Parse.query("#{name}=#{escaped_value}")
else
{ name => value }
end
end
|
99
100
101
|
# File 'lib/webrat/core/elements/field.rb', line 99
def unset
@value = default_value
end
|