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

Carl Franks fireartist at gmail.com
Tue Apr 1 14:17:33 BST 2008


On 31/03/2008, Peter Williams <peter.williams at bowker.com> wrote:
> 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.

Pete,

$form->process() must be called after any other method that changes
the form, such as repeat().
(I think it's documented somewhere in svn, but not in the latest cpan release).

There was some discussion last week about how the catalyst actions
could handle this better, but I haven't had a chance to consider it
properly.

Cheers,
Carl



More information about the HTML-FormFu mailing list