[html-formfu] Re: problems with Repeatable Select and increment_fields_names = 0

Doug Orleans dougorleans at gmail.com
Mon Mar 8 20:21:57 GMT 2010


On Mon, Mar 8, 2010 at 2:36 PM, Doug Orleans <dougorleans at gmail.com> wrote:
> Yep, I just ran into the same problem with default_values.  (Change
> process to default_values in my previous bug report to reproduce.)
> Have you worked on this at all?

Turned out to be pretty easy to apply the same fix as before.  Here's
a patch against 0.06001:

*** /usr/local/share/perl/5.10.0/HTML/FormFu/Element/_Group.pm	2009-12-09
10:34:19.000000000 -0500
--- lib/HTML/FormFu/Element/_Group.pm	2010-03-08 15:19:01.000000000 -0500
***************
*** 320,339 ****
          ? $self->get_nested_hash_value( $self->form->input,
$self->nested_name )
          : undef;

!     if ( ( reftype($value) || '' ) eq 'ARRAY' ) {
!         my $elems = $self->form->get_fields({ nested_name =>
$self->nested_name });
!         if ( $#$elems ) {
!             # There are multiple fields with the same name; assume
!             # none are multi-value fields, i.e. only one selected
!             # option per field.  (Otherwise it might be ambiguous
!             # which option came from which field.)
!             for ( 0 .. @$elems - 1 ) {
!                 if ( $self == $elems->[$_] ) {
!                     # Use the value of the option actually selected in
!                     # this group.
!                     $value = $value->[$_];
!                 }
!             }
          }
      }

--- 320,332 ----
          ? $self->get_nested_hash_value( $self->form->input,
$self->nested_name )
          : undef;

!     my $i = $self->_index_in_group;
!     if ( defined $i ) {
!         if ( ( reftype($value) || '' ) eq 'ARRAY' ) {
!             $value = $value->[ $i ];
!         }
!         if ( ( reftype($default) || '' ) eq 'ARRAY' ) {
!             $default = $default->[ $i ];
          }
      }

***************
*** 359,364 ****
--- 352,374 ----
      return;
  }

+ sub _index_in_group {
+     my ( $self ) = @_;
+
+     my $elems = $self->form->get_fields({ nested_name =>
$self->nested_name });
+     if ( $#$elems ) {
+         # There are multiple fields with the same name; assume
+         # none are multi-value fields, i.e. only one selected
+         # option per field.  (Otherwise it might be ambiguous
+         # which option came from which field.)
+         for ( 0 .. @$elems - 1 ) {
+             if ( $self == $elems->[$_] ) {
+                 return $_;
+             }
+         }
+     }
+ }
+
  sub render_data_non_recursive {
      my ( $self, $args ) = @_;



More information about the HTML-FormFu mailing list