include radiobutton to request data

master
Kanezoh 2021-06-17 14:10:53 +09:00
parent fe730164f3
commit 4ccbb38f4d
2 changed files with 28 additions and 1 deletions

View File

@ -62,7 +62,7 @@ describe "Mechanize Form test" do
checkbox.click
checkbox.checked?.should eq true
end
it "doesn't include request data if checkbox isn't checked" do
it "doesn't included in request data if checkbox isn't checked" do
form.request_data.should contain("remember_me=on")
checkbox.uncheck
form.request_data.should_not contain("remember_me=")
@ -96,5 +96,11 @@ describe "Mechanize Form test" do
radiobuttons[1].checked.should eq true
radiobuttons[0].checked.should eq false
end
it "doesn't included in request data if checkbox isn't checked" do
radiobuttons[0].check
form.request_data.should contain "contact=email"
radiobuttons[0].uncheck
form.request_data.should_not contain "contact"
end
end
end

View File

@ -105,6 +105,27 @@ class MechanizeCr::Form
successful_controls << elm
end
end
radio_groups = Hash(String, Array(FormContent::RadioButton)).new
radiobuttons.each do |radio|
name = radio.name
radio_groups[name] = Array(FormContent::RadioButton).new unless radio_groups.has_key?(name)
radio_groups[name] << radio
end
radio_groups.each_value do |g|
checked = g.select(&.checked)
if checked.uniq.size > 1
#values = checked.map(&.value).join(', ').inspect
#name = checked.first.name.inspect
#raise Mechanize::Error,
# "radiobuttons #{values} are checked in the #{name} group, " \
# "only one is allowed"
raise MechanizeCr::Error.new
else
successful_controls << checked.first unless checked.empty?
end
end
successful_controls.each do |ctrl|
value = ctrl.query_value
next if value[0] == ""