[html-formfu] Repeatable constraints

Doug Orleans dougorleans at gmail.com
Mon Dec 7 17:38:46 GMT 2009


I'm having more woes with Repeatable and increment_field_names = 0,
this time with constraints:

use HTML::FormFu;

my $form = HTML::FormFu->new;
$form->elements({ type => 'Repeatable', increment_field_names => 0,
                  elements => [ { name => 'quantity',
				  constraint => 'Number' } ] });

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

$form->process( { quantity => [ 23, 'foobar' ] } );
print $form->render;

This puts an error message on both inputs, not just the second one:

<form action="" method="post">
<div>
<div class="text error error_constraint_number">
<span class="error_message error_constraint_number">This field must be
a number</span>
<input name="quantity" type="text" value="23" />
</div>
</div>
<div>
<div class="text error error_constraint_number">
<span class="error_message error_constraint_number">This field must be
a number</span>
<input name="quantity" type="text" value="foobar" />
</div>
</div>
</form>

Also, I'm having a hard time figuring out how to make a constraint
requiring that at least one of the repeated fields is non-empty,
without making all of them be required.  Any ideas?

Thanks,
--Doug Orleans
dougorleans at gmail.com



More information about the HTML-FormFu mailing list