# strip empty if it shouldn't be
defined $attr->{$_} and $attr->{$_} eq '' and delete $attr->{$_}
- for qw(id type class style);
+ for qw(id for type class style);
my $return = '<' . $tag;
$self->select($name, $rows, {%$attr, type => 'checkbox'});
}
+sub row {
+ my $self = shift;
+ my ($name, $contents, $attr) = $self->_attr(2, @_);
+
+ $contents = defined $contents && ref $contents ne 'HASH'
+ ? $self->quote($contents) : $self->text($name, $contents);
+ my $label = defined $attr->{label}
+ ? $self->quote(delete $attr->{label})
+ : defined $name ? $self->quote($name) : '';
+
+ return $self->tag(label => {for => $name, %$attr})
+ . $label
+ . '</label>'
+ . (defined $, ? $, : ' ')
+ . $contents
+ ;
+}
+
1;
__END__
use Test::More;
-plan tests => 76;
+plan tests => 80;
use_ok('HTML::Form::Simple');
'various checkboxes'
);
+# row
+
+is(
+ $form->row(undef),
+ '<label></label> <input type="text">',
+ 'empty row'
+);
+
+is(
+ $form->row('test'),
+ '<label for="test">test</label> <input id="test" name="test" type="text">',
+ 'standard row'
+);
+
+is(
+ $form->row('test', {type => 'password'}, {for => '', label => '"blah"'}),
+ '<label>"blah"</label> <input id="test" name="test" type="password">',
+ 'row options'
+);
+
+is(
+ $form->row('test', '"scalar"', {for => ''}),
+ '<label>test</label> "scalar"',
+ 'row scalar'
+);
+
# defaults
my $defform = HTML::Form::Simple->new({foo => '<">', '' => 'empty', 0 => 0});