Open
Description
If a radio button's value is set to an empty string, HTML::Form uses the value of the first item in the radio's menu. Here's a sample program demonstrating the behavior:
#!/usr/bin/env perl
use 5.010;
use strict;
use warnings;
use HTML::Form;
my $form = HTML::Form->parse( <<'HTML', 'https://www.example.com' );
<form>
<input type="radio" name="foo" value="1">
<input type="radio" name="foo" value="2">
<input type="radio" name="foo" value="3">
</form>
HTML
my $input = $form->find_input('foo');
say "initial value='" . ($input->value() // 'undef') . "'";
$input->value('');
say "empty string value='" . ($input->value() // 'undef') . "'";
$input->value(undef);
say "undef value='" . ($input->value() // 'undef') . "'";
# Output:
# initial value='undef'
# empty string value='1'
# undef value='undef'
No matter what the initial value of the radio button is, setting it to an empty string always changes its value to the first item. It's not clear to me if this behavior is a bug, but I did find it surprising.
Metadata
Metadata
Assignees
Labels
No labels