[html-formfu] Select options not populating when inside a repeatable element

Peter Williams peter.williams at bowker.com
Mon Mar 31 22:46:55 BST 2008


I am currently experiencing a problem where a select element's options
are not being populated when inside a repeatable element.  This occurs
when the repeat method is called after process and the options are
populated by options_from_model.  If I hard code the values for the
options, this problem does not occur.  For example, assume the
following form definition:

   - type: Repeatable
     nested_name: order_lines
     elements:
       - type: Hidden
         name: order_line_id

       - type: Select
         name: rc_order_line_status_code
         label: Order Line Status
         model_config:
           DBIC:
             resultset: RcOrderLineStatus
             id_column: rc_order_line_status_code
             label_column: description
--

Then, assume the following Catalyst code is executed:

...
$form->process( $c->request );
$form->get_element({ type => 'Repeatable' })->repeat(2);

Now, the order_lines element does properly get repeated twice in this 
example, however, rc_order_line_status_code contains no options.  If I 
comment out $form->get_element({ type => 'Repeatable' })->repeat(2), 
then the select box is properly populated.  Therefore, this problem only 
occurs when repeat is called a subsequent time after it is initially 
called in process.  Is this behavior a bug, or by design?

Looking at the source in HTML::FormFu::Element::Repeatable.pm, I was 
able to create a temporary workaround that will populate repeated select 
boxes by changing the following code in the repeat method from:

     if ( $self->_original_elements ) {

         # repeat() has already been called
         $children = $self->_original_elements;
     }
     else {

         $children = $self->_elements;
         $self->_original_elements($children);
     }

to:

#    if ( $self->_original_elements ) {
#
#        # repeat() has already been called
#        $children = $self->_original_elements;
#    }
#    else {

         $children = $self->_elements;
         $self->_original_elements($children);
#    }

Any help in solving this problem would be greatly appreciated.

Thanks,
Pete



More information about the HTML-FormFu mailing list