Subject: | HTML::FormFu::Element::Repeatable - duplicating field value when changing from ->repeat(1) to ->repeat(2) |
Date: | Mon, 25 Nov 2013 14:29:33 -0800 |
To: | bug-HTML-FormFu [...] rt.cpan.org |
From: | Ian Baber <ian.baber [...] gmail.com> |
I'm building a form where the user needs to enter a section one or
more times, so I'm using Element::Repeatable. There is a submit
button to "add another section", causing the app to modify the form
adding a section, and redisplay it with all entered values. I'm not
using increment_field_names, the goal here is for the application to
get several parameters that are arrays of the same length, where each
represents one field in the repeating section ( e.g.
email="user@host","user@otherhost" type="work","personal" )
When there are 2 or more sections already in the form, this works as
expected, and all fields in the newly added repeating section are
blank.
However, if the repeating section is only exists once in the form, and
the "add another section" button is clicked, whatever values were
populated or entered in the first section are copied to the second
section. It looks like FormFu incorrectly handles the param value
when it is a scalar (only one value submitted by the client) and sets
that value on multiple elements. Adding extra hidden elements to the
form with the same name as the repeated elements is an effective
workaround, causing every param to always be read as an array of
values with an extra empty string at the end.