[Html-widget] Patch to fix RadioGroup implicit In Constraint for value or label == 0

Ted Carnahan ted at tedcarnahan.com
Wed May 17 18:57:44 CEST 2006


Turns out that Select has the same problem.  The attached patch 
incorporates the previous one - ignore it.

Ted Carnahan wrote:

> Includes a few tests.  Enjoy!
>
> - Ted
>
>------------------------------------------------------------------------
>
>Index: lib/HTML/Widget/Element.pm
>===================================================================
>--- lib/HTML/Widget/Element.pm	(revision 31)
>+++ lib/HTML/Widget/Element.pm	(working copy)
>@@ -148,7 +148,7 @@
> 
> sub mk_label {
>     my ( $self, $w, $name, $comment, $errors ) = @_;
>-    return undef unless $name;
>+    return undef unless defined $name;
>     my $for = $self->attributes->{id} || $self->id($w);
>     my $id  = $for . '_label';
>     my $e   = HTML::Element->new( 'label', for => $for, id => $id );
>Index: lib/HTML/Widget/Element/RadioGroup.pm
>===================================================================
>--- lib/HTML/Widget/Element/RadioGroup.pm	(revision 31)
>+++ lib/HTML/Widget/Element/RadioGroup.pm	(working copy)
>@@ -86,7 +86,7 @@
>     }
>     
>     my %seen;
>-    my @uniq = grep { $seen{$_}++ == 0 ? $_ : 0 } @{ $self->values };
>+    my @uniq = grep { ! $seen{$_} ++ } @{ $self->values };    
>     
>     $w->constraint( 'In', $name )->in( @uniq )
>         if @uniq;
>Index: t/element_radiogroup_implicit_in_constraint.t
>===================================================================
>--- t/element_radiogroup_implicit_in_constraint.t	(revision 31)
>+++ t/element_radiogroup_implicit_in_constraint.t	(working copy)
>@@ -1,4 +1,4 @@
>-use Test::More tests => 5;
>+use Test::More tests => 8;
> 
> use_ok('HTML::Widget');
> 
>@@ -7,7 +7,7 @@
> 
> my $w = HTML::Widget->new;
> 
>-$w->element( 'RadioGroup', 'foo' )->values([ 1, 2 ]);
>+$w->element( 'RadioGroup', 'foo' )->values([ 0, 1, 2 ]);
> $w->element( 'RadioGroup', 'bar' )->values([ 3, 4 ]);
> 
> 
>@@ -17,13 +17,18 @@
> 
>     my $f = $w->process($query);
> 
>+    my @constraints = $w->get_constraints;
>+    cmp_ok(scalar(@constraints), '==', 2, 'Two implicit IN constraints');
>+    cmp_ok(scalar(@{$constraints[0]->_in()}), '==', 3, 'Three keys for constraint 0');
>+    cmp_ok(scalar(@{$constraints[1]->_in()}), '==', 2, 'Two keys for constraint 1');
>+
>     ok( $f->valid('foo') );
>     ok( ! $f->valid('bar') );
>     
>     ok( $f->has_errors( 'bar' ) );
> 
>     is( "$f", <<EOF, 'XML output is filled out form' );
>-<form id="widget" method="post"><fieldset><span><label for="widget_foo_1" id="widget_foo_1_label"><input checked="checked" class="radio" id="widget_foo_1" name="foo" type="radio" value="1" />1</label><label for="widget_foo_2" id="widget_foo_2_label"><input class="radio" id="widget_foo_2" name="foo" type="radio" value="2" />2</label></span><span><label for="widget_bar_1" id="widget_bar_1_label"><input class="radio" id="widget_bar_1" name="bar" type="radio" value="3" />3</label><label for="widget_bar_2" id="widget_bar_2_label"><input class="radio" id="widget_bar_2" name="bar" type="radio" value="4" />4</label></span><span class="error_messages" id="widget_bar_errors"><span class="in_errors" id="widget_bar_error_in">Invalid Input</span></span></fieldset></form>
>+<form id="widget" method="post"><fieldset><span><label for="widget_foo_1" id="widget_foo_1_label"><input class="radio" id="widget_foo_1" name="foo" type="radio" value="0" />0</label><label for="widget_foo_2" id="widget_foo_2_label"><input checked="checked" class="radio" id="widget_foo_2" name="foo" type="radio" value="1" />1</label><label for="widget_foo_3" id="widget_foo_3_label"><input class="radio" id="widget_foo_3" name="foo" type="radio" value="2" />2</label></span><span><label for="widget_bar_1" id="widget_bar_1_label"><input class="radio" id="widget_bar_1" name="bar" type="radio" value="3" />3</label><label for="widget_bar_2" id="widget_bar_2_label"><input class="radio" id="widget_bar_2" name="bar" type="radio" value="4" />4</label></span><span class="error_messages" id="widget_bar_errors"><span class="in_errors" id="widget_bar_error_in">Invalid Input</span></span></fieldset></form>
> EOF
> }
> 
>  
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Html-widget mailing list
>Html-widget at lists.rawmode.org
>http://lists.rawmode.org/cgi-bin/mailman/listinfo/html-widget
>  
>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: zero_values_radiogroup_select.patch
Url: http://lists.rawmode.org/pipermail/html-widget/attachments/20060517/bdc7c4ef/attachment.diff 


More information about the Html-widget mailing list