XXX: reverse radio options
authorMischa Poslawsky <mischa@mediadesign.nl>
Fri, 22 Aug 2008 18:15:46 +0000 (20:15 +0200)
committerMischa Poslawsky <mischa@mediadesign.nl>
Fri, 22 Aug 2008 19:37:44 +0000 (21:37 +0200)
lib/HTML/Form/Simple.pm
t/html.t

index 33da2b65f34854ce7e2fbc8510b7ee4dae9b5df2..59f0e4c705ef890325397f55181e5ced41f1816e 100644 (file)
@@ -171,7 +171,7 @@ sub select {
 
 sub radio {
        my $self = shift;
 
 sub radio {
        my $self = shift;
-       my ($name, $label, $rows, $attr) = $self->_attr(3, @_);
+       my ($name, $rows, $label, $attr) = $self->_attr(3, @_);
 
        if (not defined $rows) {
                if (defined $label) {
 
        if (not defined $rows) {
                if (defined $label) {
@@ -237,7 +237,7 @@ HTML::Form::Simple - Generate HTML form elements
                        msg => 'Textarea default', {rows => 4, style => 'background:red'}
                ) ],
                [ Gender => join ' or ', $input->radio(
                        msg => 'Textarea default', {rows => 4, style => 'background:red'}
                ) ],
                [ Gender => join ' or ', $input->radio(
-                       sex => ['m', 'f']
+                       sex => [qw(m f)], [qw(Male Female)]
                ) ],
                [ Colour => scalar $input->select(
                        favcolour => [qw(Blue Green Red)], 'Green'
                ) ],
                [ Colour => scalar $input->select(
                        favcolour => [qw(Blue Green Red)], 'Green'
@@ -252,12 +252,6 @@ HTML::Form::Simple - Generate HTML form elements
 
 =over
 
 
 =over
 
-=item C<radio>|C<check> parameter order
-
-Row options (hash ref details) are inconsistent:
-on labels for C<check>, on values for C<radio>.
-Make behaviour more logical.
-
 =item C<default()> method
 
        $input->hidden(foo => $input->default('foo'));
 =item C<default()> method
 
        $input->hidden(foo => $input->default('foo'));
index 89f82a1356c78e2522247c4cb9d9a3c65c1a94aa..757b248dbd825400b4e2e4a12cc723d802c84822 100644 (file)
--- a/t/html.t
+++ b/t/html.t
@@ -5,7 +5,7 @@ use warnings;
 
 use Test::More;
 
 
 use Test::More;
 
-plan tests => 65;
+plan tests => 66;
 
 use_ok('HTML::Form::Simple');
 
 
 use_ok('HTML::Form::Simple');
 
@@ -312,14 +312,14 @@ is_deeply(
 
 is(
        $form->radio(foo => 'test'),
 
 is(
        $form->radio(foo => 'test'),
-       '<label><input id="foo_1" name="foo" type="radio" value="1"> test</label>',
+       '<input id="foo_test" name="foo" type="radio" value="test">',
        'radio method'
 );
 
 is(
        'radio method'
 );
 
 is(
-       $form->radio(foo => undef, 2),
-       '<input id="foo_2" name="foo" type="radio" value="2">',
-       'labelless radio'
+       $form->radio(foo => undef, 'test'),
+       '<label><input id="foo_1" name="foo" type="radio" value="1"> test</label>',
+       'labeled radio'
 );
 
 is(
 );
 
 is(
@@ -330,15 +330,24 @@ is(
 
 is_deeply(
        [ $form->radio(undef, ['', '<">']) ],
 
 is_deeply(
        [ $form->radio(undef, ['', '<">']) ],
+       [
+               '<input type="radio" value="">',
+               '<input type="radio" value="&lt;&quot;>">',
+       ],
+       'multiple radios'
+);
+
+is_deeply(
+       [ $form->radio(undef, undef, ['', '<">']) ],
        [
                '<input type="radio" value="1">',
                '<label><input type="radio" value="2"> <"></label>',
        ],
        [
                '<input type="radio" value="1">',
                '<label><input type="radio" value="2"> <"></label>',
        ],
-       'multiple radios'
+       'multiple radio labels'
 );
 
 is_deeply(
 );
 
 is_deeply(
-       [ $form->radio(foo => 'test', ['foo', ''], {value => '', id => ''}) ],
+       [ $form->radio(foo => ['foo', ''], 'test', {value => '', id => ''}) ],
        [
                '<label><input name="foo" type="radio" value="foo"> test</label>',
                '<label><input checked name="foo" type="radio" value=""> test</label>',
        [
                '<label><input name="foo" type="radio" value="foo"> test</label>',
                '<label><input checked name="foo" type="radio" value=""> test</label>',
@@ -347,7 +356,7 @@ is_deeply(
 );
 
 is_deeply(
 );
 
 is_deeply(
-       [ $form->radio(foo => ['', 0], [0, 1, '']) ],
+       [ $form->radio(foo => [0, 1, ''], ['', 0]) ],
        [
                '<input id="foo_0" name="foo" type="radio" value="0">',
                '<label><input id="foo_1" name="foo" type="radio" value="1"> 0</label>',
        [
                '<input id="foo_0" name="foo" type="radio" value="0">',
                '<label><input id="foo_1" name="foo" type="radio" value="1"> 0</label>',
@@ -358,8 +367,8 @@ is_deeply(
 
 {
        # make sure arguments aren't modified
 
 {
        # make sure arguments aren't modified
-       my @args = (foo => [0, 1], [0, {value => 1}], {name => 0, value => 1});
-       my @orgs = (foo => [0, 1], [0, {value => 1}], {name => 0, value => 1});
+       my @args = (foo => [0, {value => 1}], [0, 1], {name => 0, value => 1});
+       my @orgs = (foo => [0, {value => 1}], [0, 1], {name => 0, value => 1});
        my @output = (
                '<label><input id="foo_0" name="foo" type="radio" value="0"> 0</label>',
                '<label><input checked id="foo_1" name="foo" type="radio" value="1"> 1</label>',
        my @output = (
                '<label><input id="foo_0" name="foo" type="radio" value="0"> 0</label>',
                '<label><input checked id="foo_1" name="foo" type="radio" value="1"> 1</label>',
@@ -375,7 +384,7 @@ is_deeply(
                [ $form->check(@args) ],
                [
                        '<label><input checked id="foo_1" name="foo" type="checkbox" value="1"> 0</label>',
                [ $form->check(@args) ],
                [
                        '<label><input checked id="foo_1" name="foo" type="checkbox" value="1"> 0</label>',
-                       '<label><input checked id="foo_2" name="foo" type="checkbox" value="2"> 1</label>',
+                       '<input checked id="foo_1" name="foo" type="checkbox" value="1">',
                ],
                'options var to check'
        );
                ],
                'options var to check'
        );
@@ -485,7 +494,7 @@ is(
 );
 
 is_deeply(
 );
 
 is_deeply(
-       [ $defform->radio(0 => undef, [1, 0]) ],
+       [ $defform->radio(0 => [1, 0]) ],
        [
                '<input id="0_1" name="0" type="radio" value="1">',
                '<input checked id="0_0" name="0" type="radio" value="0">',
        [
                '<input id="0_1" name="0" type="radio" value="1">',
                '<input checked id="0_0" name="0" type="radio" value="0">',