my @options = map { ref $_ ? $_ : {value => $_} } @$rows;
+ my @return;
+
if ($attr->{type} eq 'select') {
delete $attr->{type};
if (defined $default) {
$_->{selected} = 1 if defined $_->{value} and $_->{value} eq $default;
}
}
- my @return = (
+ @return = (
$self->tag(select => $attr),
(map { $self->tag(option => $_) } @options),
'</select>',
);
- return wantarray ? @return : join('', @return);
}
else {
if (defined $attr->{id} and $attr->{id} ne '') {
- defined $_->{id} or defined $_->{value} and $_->{id} = $attr->{id}.'_'.$_->{value}
- for @options;
+ defined $_->{id}
+ or defined $_->{value} and $_->{id} = $attr->{id}.'_'.$_->{value}
+ for @options;
}
if (defined $attr->{label}) {
defined $_->{value} and not defined $_->{label}
}
}
$_ = {%$attr, %$_} for @options;
- my @return = map {
+ @return = map {
my $label = delete $_->{label};
defined $label && $label ne ''
? '<label>'.$self->tag(input => $_)." $label</label>"
: $self->tag(input => $_)
} @options;
- return wantarray ? @return : join('', @return);
}
+
+ return wantarray ? @return : join(defined $, ? $, : '', @return);
}
sub radio {
use Test::More;
-plan tests => 51;
+plan tests => 52;
use_ok('HTML::Form::Simple');
);
is(
- $form->radio(foo => undef, [2]), #TODO
+ $form->radio(foo => undef, 2),
'<input id="foo_2" name="foo" type="radio" value="2">',
'labelless radio'
);
'multiple checked checkboxes'
);
+{
+ local $, = ' | ';
+ is(
+ scalar $form->check(foo => [1, 0], {value => 0}),
+ join(' | ',
+ '<label><input id="foo_1" name="foo" type="checkbox" value="1"> 1</label>',
+ '<label><input id="foo_2" name="foo" type="checkbox" value="2"> 0</label>',
+ ),
+ 'merged checkboxes'
+ );
+}
+
is_deeply(
[ $form->check(undef, [{value => 4, type => 'radio'}], [1, 0, 0], {value => 3}) ],
[