add form element comment

master
Kanezoh 2021-11-18 10:12:47 +09:00
parent a70e6eae90
commit fca04b29b9
5 changed files with 14 additions and 4 deletions

View File

@ -8,7 +8,7 @@ require "./form/button"
require "./form/select_list" require "./form/select_list"
require "./utils/element_matcher" require "./utils/element_matcher"
# THis class represents the form tag of html. # This class represents the form tag of html.
class Mechanize::Form class Mechanize::Form
include Mechanize::ElementMatcher include Mechanize::ElementMatcher
@ -68,7 +68,7 @@ class Mechanize::Form
elements_with "checkbox", "checkboxes" elements_with "checkbox", "checkboxes"
elements_with "button" elements_with "button"
# Returns all fields of type Textarea # Returns all fields of <input type="textarea">
def textareas def textareas
fields.select { |f| f.class == FormContent::Textarea }.map &.as(FormContent::Textarea) fields.select { |f| f.class == FormContent::Textarea }.map &.as(FormContent::Textarea)
end end

View File

@ -1,7 +1,14 @@
# This class represents <input> elements in the form.
class Mechanize::FormContent::Field class Mechanize::FormContent::Field
# returns field's 'value' attribute
property value : String? property value : String?
# returns field's 'name' attribute
getter name : String getter name : String
# returns field's 'type' attribute
getter type : String getter type : String
# returns field's 'value' attribute.
# value property is changeable, but this property stores raw value.
getter raw_value : String? getter raw_value : String?
getter node : Node | Lexbor::Node getter node : Node | Lexbor::Node
@ -17,12 +24,12 @@ class Mechanize::FormContent::Field
[@name, @value || ""] [@name, @value || ""]
end end
# returns DOM 'id' value # returns field's 'id' value
def dom_id def dom_id
node.fetch("id", "") node.fetch("id", "")
end end
# returns DOM 'class' value # returns field's 'class' value
def dom_class def dom_class
node.fetch("class", "") node.fetch("class", "")
end end

View File

@ -1,2 +1,3 @@
# This class represents <input type="hidden">
class Mechanize::FormContent::Hidden < Mechanize::FormContent::Field class Mechanize::FormContent::Hidden < Mechanize::FormContent::Field
end end

View File

@ -1,2 +1,3 @@
# This class represents <input type="text">
class Mechanize::FormContent::Text < Mechanize::FormContent::Field class Mechanize::FormContent::Text < Mechanize::FormContent::Field
end end

View File

@ -1,2 +1,3 @@
# This class represents <input type="textarea">
class Mechanize::FormContent::Textarea < Mechanize::FormContent::Field class Mechanize::FormContent::Textarea < Mechanize::FormContent::Field
end end