FAQ
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

Search Discussions

  • Carl Franks at Apr 1, 2008 at 2:17 pm

    On 31/03/2008, Peter Williams 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
  • Peter Williams at Apr 1, 2008 at 4:04 pm

    Carl Franks wrote:
    On 31/03/2008, Peter Williams 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
    Carl, thank you for your response. I'm still a little confused if
    repeat can actually be called before process since it will be
    automatically called inside process with a default value of 1.

    I understand now that calling repeat after process doesn't work, but
    calling it before process also doesn't work since the repeat count will
    be overwritten when it is automatically called during process. When
    repeat is called during process, it's called with a default count of 1,
    or with the value of the counter_name field which will only be present
    when submitting a form.

    Therefore, when retrieving a form, the only way I was able to repeat the
    correct number of times, was to manually add in the counter_name
    parameter to the request object. This works, but is ugly. Perhaps as a
    fix, repeat should only be called in process if it hasn't already been
    called or if counter_name has a count.

    Thanks again for your help,
    Pete

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouphtml-formfu @
categoriesperl, catalyst
postedMar 31, '08 at 10:46p
activeApr 1, '08 at 4:04p
posts3
users2
websitemetacpan.org...

2 users in discussion

Peter Williams: 2 posts Carl Franks: 1 post

People

Translate

site design / logo © 2022 Grokbase