On Mon, 20 Mar 2006 10:53:11 +0100, ADSJ wrote:

> The HTML-specification allows checkbox-elements to share the same
> name¹, so I guess Checkbox.pm ought to do something similar to
> Radio.pm for id-attributes?

There was no response to this, so I've cooked up a crude patch that
makes Checkbox.pm do what Radio.pm does.

It should perhaps be done in a better/more general way?


  Best regards,

    Adam

-- 
                                                          Adam Sjøgren
                                                    [EMAIL PROTECTED]

*** Checkbox.pm.orig	2006-06-20 14:46:47.000000000 +0200
--- Checkbox.pm	2006-06-20 14:47:38.000000000 +0200
***************
*** 42,47 ****
--- 42,82 ----
  
      $value = ref $value eq 'ARRAY' ? shift @$value : $value;
  
+     my $name = $self->name;
+ 
+     # Search for multiple checkboxes with the same name
+     my $multi = 0;
+     my @elements;
+     push @elements, [ $w, $w->{_elements} ] if $w->{_elements};
+     if ( $w->{_embedded} ) {
+         for my $embedded ( @{ $w->{_embedded} } ) {
+             push @elements, [ $embedded, $embedded->{_elements} ]
+               if $embedded->{_elements};
+         }
+     }
+     for my $e (@elements) {
+         my $widget   = $e->[0];
+         my $elements = $e->[1];
+         for my $element (@$elements) {
+             next if $element eq $self;
+             if ( $element->isa('HTML::Widget::Element::Checkbox') ) {
+                 if ( $element->name eq $name ) {
+                     $multi++;
+                 }
+             }
+         }
+     }
+ 
+     # Generate unique id
+     if ($multi) {
+         $w->{_shash}          ||= {};
+         $w->{_stash}->{checkbox} ||= {};
+         my $num = ++$w->{_stash}->{checkbox}->{$name};
+         my $id = $self->id( $w, "$name\_$num" );
+         $self->attributes( {} ) unless $self->attributes;
+         $self->attributes->{id} ||= $id;
+     }
+ 
      my $checked = ( defined $value && $value eq $self->value ) ? 'checked' : undef;
      $checked = 'checked' if ( !defined $value && $self->checked );
      $value   = $self->value;
_______________________________________________
List: [email protected]
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/

Reply via email to