allow nil to field value

master
Kanezoh 2021-06-16 23:19:58 +09:00
parent 6c2a942809
commit 601a12f1ee
2 changed files with 9 additions and 5 deletions

View File

@ -1,7 +1,7 @@
class MechanizeCr::FormContent::CheckBox < MechanizeCr::FormContent::Field
property :checked
def initialize(node : Node | Myhtml::Node, value = "")
def initialize(node : Node | Myhtml::Node, value = nil)
@checked = !!node["checked"]
super(node, value)
end
@ -22,4 +22,8 @@ class MechanizeCr::FormContent::CheckBox < MechanizeCr::FormContent::Field
def click
checked ? uncheck : check
end
def query_value
[@name, @value || "on"]
end
end

View File

@ -1,14 +1,14 @@
class MechanizeCr::FormContent::Field
getter :node
property value : String
property value : String?
getter name : String
getter type : String
getter raw_value : String
getter raw_value : String?
def initialize(node : Node | Myhtml::Node, value = "")
def initialize(node : Node | Myhtml::Node, value=nil)
@node = node
@name = node.fetch("name", "")
@value = value || node.fetch("value", "")
@value = value || node.fetch("value", nil)
@type = node.fetch("type", "")
@raw_value = value
end