raise error when submit with invalid button

This commit is contained in:
Kanezoh 2021-06-29 20:21:44 +09:00
parent 0c4e5fefcf
commit 5631971347
2 changed files with 15 additions and 10 deletions

View File

@ -61,11 +61,11 @@ class MechanizeCr::Form
when "radio" when "radio"
radiobuttons << FormContent::RadioButton.new(html_node, self) radiobuttons << FormContent::RadioButton.new(html_node, self)
when "button" when "button"
buttons << FormContent::Button.new(html_node) buttons << FormContent::Button.new(html_node, @node)
when "submit" when "submit"
buttons << FormContent::SubmitButton.new(html_node) buttons << FormContent::SubmitButton.new(html_node, @node)
when"reset" when"reset"
buttons << FormContent::ResetButton.new(html_node) buttons << FormContent::ResetButton.new(html_node, @node)
when "text" when "text"
fields << FormContent::Text.new(html_node) fields << FormContent::Text.new(html_node)
when "hidden" when "hidden"
@ -130,13 +130,13 @@ class MechanizeCr::Form
# This method adds a button to the query. If the form needs to be # This method adds a button to the query. If the form needs to be
# submitted with multiple buttons, pass each button to this method. # submitted with multiple buttons, pass each button to this method.
def add_button_to_query(button) def add_button_to_query(button)
#unless button.node == @node unless button.form_node == @node
# message = "" #message = ""
# "#{button.inspect} does not belong to the same page as " \ # "#{button.inspect} does not belong to the same page as " \
# "the form #{@name.inspect} in #{@page.uri}" # "the form #{@name.inspect} in #{@page.uri}"
# message = "not a valid button"
# raise ArgumentError, message raise ArgumentError.new(message)
#end end
@clicked_buttons << button @clicked_buttons << button
end end

View File

@ -1,4 +1,9 @@
class MechanizeCr::FormContent::Button < MechanizeCr::FormContent::Field class MechanizeCr::FormContent::Button < MechanizeCr::FormContent::Field
getter form_node : Node | Myhtml::Node
def initialize(node : Node | Myhtml::Node, form_node : Node | Myhtml::Node, value=nil)
@form_node = form_node
super(node, value)
end
end end
require "./reset_button" require "./reset_button"
require "./submit_button" require "./submit_button"