XXX: hidden array
authorMischa Poslawsky <mischa@mediadesign.nl>
Fri, 25 Jul 2008 23:42:51 +0000 (01:42 +0200)
committerMischa Poslawsky <mischa@mediadesign.nl>
Fri, 25 Jul 2008 23:42:51 +0000 (01:42 +0200)
lib/HTML/Form/Simple.pm
t/html.t

index bbeb6b6fbf1c6b49ebccca76b8a1573cc6cce452..e2a586d51987dc2914ea1b4c154caf2fff2dece7 100644 (file)
@@ -76,6 +76,11 @@ sub hidden {
                return wantarray ? @return : join(defined $, ? $, : '', @return);
        }
 
+       if (ref $value eq 'ARRAY') {
+               my @return = map { $self->hidden($name, $_, $attr) } @$value;
+               return wantarray ? @return : join(defined $, ? $, : '', @return);
+       }
+
        $attr->{name } = $name  if defined $name;
        $attr->{value} = $value if defined $value;
        $attr->{type} = 'hidden' unless defined $attr->{type};
index 3c6d8f4898b1284d9c061cf734535d95ca776dd3..a9ee150c42778b3b8a7a46d135c01fb661c0a15c 100644 (file)
--- a/t/html.t
+++ b/t/html.t
@@ -5,7 +5,7 @@ use warnings;
 
 use Test::More;
 
-plan tests => 53;
+plan tests => 55;
 
 use_ok('HTML::Form::Simple');
 
@@ -58,6 +58,15 @@ is(
        'hidden options'
 );
 
+is_deeply(
+       [ $form->hidden(foo => [1, 0], {class => 'test'}) ],
+       [
+               '<input class="test" name="foo" type="hidden" value="1">',
+               '<input class="test" name="foo" type="hidden" value="0">',
+       ],
+       'hidden array'
+);
+
 is_deeply(
        [ $form->hidden({2 => 0, 10 => 1}, {class => 'test'}) ],
        [
@@ -67,6 +76,19 @@ is_deeply(
        'hidden hash'
 );
 
+{
+       local $, = "\n";
+       is(
+               scalar $form->hidden({2 => [1, 0], 10 => 2}, {class => 'test'}),
+               join("\n",
+                       '<input class="test" name="10" type="hidden" value="2">',
+                       '<input class="test" name="2" type="hidden" value="1">',
+                       '<input class="test" name="2" type="hidden" value="0">',
+               ),
+               'scalar hiddens'
+       );
+}
+
 # submit
 
 is(