-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
Consider the following:
use HTML::Form;
use Data::Dumper;
$Data::Dumper::Indent = $Data::Dumper::Terse = 1;
my ($form) = HTML::Form->parse( <<'HTML', 'https://example.com' );
<form>
<select id="id-language" name="language">
<option id="id-english" value="English"> English </option>
<option id="id-klingon" value="Klingon" selected> Klingon </option>
</select>
<input class="green" id="id-happy" name="mood" value="happy" type="radio" checked>
<input class="red" id="id-sad" name="mood" value="sad" type="radio">
</form>
HTML
for my $id ( qw( id-language id-klingon id-happy id-sad ) ) {
my $input = $form->find_input( "#$id" );
say "$id is ", Dumper( $input );
}
Results are:
id-language is bless( {
'type' => 'option',
'option_id' => 'id-english',
'current' => 1,
'idx' => 1,
'id' => 'id-language',
'name' => 'language',
'menu' => [
{
'value' => 'English',
'name' => 'English'
},
{
'value' => 'Klingon',
'seen' => 1,
'name' => 'Klingon'
}
]
}, 'HTML::Form::ListInput' )
id-klingon is undef
id-happy is bless( {
'menu' => [
{
'name' => '',
'seen' => 1,
'value' => 'happy'
},
{
'name' => '',
'value' => 'sad'
}
],
'class' => 'green',
'current' => 0,
'type' => 'radio',
'name' => 'mood',
'id' => 'id-happy'
}, 'HTML::Form::ListInput' )
id-sad is undef
This demonstrates that:
Good: If a HTML::Form::ListInput is created from a <select> tag, its ID attribute is taken from the id attribute of the <select> and the ids in the <option>s are ignored.
Less good: for radio buttons, there is no enclosing tag around the <input>s, and HTML::Form takes the ID attribute from the first <input> tag and applies it to the whole HTML::Form::ListInput object. I don't think that makes sense. It seems to me that an HTML::Form::ListInput from a set of radio button inputs should have no ID at all. If this IS intended behavior, then I think that's something that should be explained in the docs.
Metadata
Metadata
Assignees
Labels
No labels