[html-formfu] HTML::FormFu::Element::Repeatable questions

Will Hawes wdhawes at gmail.com
Tue Jul 29 10:34:45 BST 2008


The Repeatable docs state "repeat is automatically called during
$form->process, to ensure the initial child elements are correctly
setup".

So if you want more than one repetition, you have to call repeat()
after process(), otherwise process() reverts everything back to just
the one:

---
elements:
  - type: Repeatable
    id: repeater
    elements:
      - type: Text
        name: foo

my $repeater = $form->get_element({ name => 'repeater' });

# 5 repetitions
$repeater->repeat(5);

# repetitions overwritten, now just one
$form->process();

# 5 repetitions again
$repeater->repeat(5);

This is problematical if you want to modify (e.g. rename) some of the
repeated fields prior to calling process(), because they will be
removed when process() calls repeat(1). In my case I want to append a
database primary key value to the name of each repeated field, but the
same applies to any other modification.

I think it might be better if process() called repeat(1) only if
repeat() had not been called already, so you could call repeat() and
modify the generated elements prior to calling process(). I've tested
this briefly and it doesn't appear to have any unwanted side effects.

I'm happy to patch it if others are in agreement.

Thoughts?



More information about the HTML-FormFu mailing list