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

View File

@ -1,14 +1,14 @@
class MechanizeCr::FormContent::Field class MechanizeCr::FormContent::Field
getter :node getter :node
property value : String property value : String?
getter name : String getter name : String
getter type : 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 @node = node
@name = node.fetch("name", "") @name = node.fetch("name", "")
@value = value || node.fetch("value", "") @value = value || node.fetch("value", nil)
@type = node.fetch("type", "") @type = node.fetch("type", "")
@raw_value = value @raw_value = value
end end