[html-formfu] problems with Repeatable Select and increment_fields_names = 0

Doug Orleans dougorleans at gmail.com
Tue Dec 1 22:06:54 GMT 2009


I'm having problems with a Repeatable Select element and
increment_fields_names = 0:

use HTML::FormFu;
my $form = HTML::FormFu->new;
$form->elements({ type => 'Repeatable', increment_field_names => 0,
                  elements => [ { type => 'Number', name => 'quantity' },
                                { type => 'Select', name => 'product',
                                  values => [ 'apple', 'orange' ] }
                      ] });

my $rep = $form->get_element;
$rep->repeat(2);

$form->process( { quantity => [ 23, 42 ],
                  product => [ 'apple', 'orange' ] } );
print $form->render;


This produces:

<form action="" method="post">
<div>
<div class="number">
<input name="quantity" type="number" value="23" />
</div>
<div class="select">
<select name="product">
<option value="apple" selected="selected">Apple</option>
<option value="orange" selected="selected">Orange</option>
</select>
</div>
</div>
<div>
<div class="number">
<input name="quantity" type="number" value="42" />
</div>
<div class="select">
<select name="product">
<option value="apple" selected="selected">Apple</option>
<option value="orange" selected="selected">Orange</option>
</select>
</div>
</div>
</form>

Note that it sets the quantity input values correctly from the
quantity array, but the product select elements each get both values
from the product array.  Is this a bug?  Is there a way to set the
select values properly when using increment_field_names = 0 (i.e. the
query contains arrays), other than manually retrieving the elements
and setting their values individually?

Thanks,
--Doug Orleans
dougorleans at gmail.com



More information about the HTML-FormFu mailing list