[html-formfu] Example of a simple repeatable field and button

Carl Franks fireartist at gmail.com
Mon Mar 16 09:18:54 GMT 2009


2009/3/14 Florent Angly <florent.angly at gmail.com>:
> Hi FormFu list,
>
> I have created a small Catalyst webapp that uses a form that is based on a
> FormFu YML configuration file. I would like to have some repeatable fields,
> along with a button to click in order generate more of these fields on the
> fly.
>
> I have read the Catalyst tutorial, the FormFu documentation, and I have some
> basic repeatable fields, but I seem to have problem with the logic of how to
> generate more repetitions of these fields from the webinterface.
>
> Can I even do that using only my FormFu config file, or would I need some
> extra logic in my Catalyst code? I asked the Catalyst list without
> success... Maybe the asking the FormFu experts on this list is a better
> place to ask.
>
> If someone could post a simple example of a simple FormFu config file with a
> simple repeatable field and button to add more of this field, it would be
> great!

Hi,

You will need code to piece it together, but you shouldn't need an
extra config file.
You need to decide whether you want this to work with AJAX, or not.
If AJAX, I'd probably suggest having a separate controller handle to handle it.
Use JS to keep the 'counter_name' [1] hidden field updated, and pass
that value in the AJAX call.
Then in your controller, do something like:

    $form->load_config_file('$file');
    $count = $c->request->param->{count};
    my $rep = $form->get_all_elements({ type => 'Repeatable' });
    my $new = $rep->repeat($count);
    my $html = join '', @$new;

[1] http://search.cpan.org/~cfranks/HTML-FormFu-0.03007/lib/HTML/FormFu/Element/Repeatable.pm#counter_name



More information about the HTML-FormFu mailing list