[html-formfu] constraint in repeatable

Josef Chladek josef.chladek at gmail.com
Sat Dec 19 11:37:47 GMT 2009


Am 19.12.2009 um 12:13 schrieb Carl Franks:

> 2009/12/19 Josef Chladek <josef.chladek at gmail.com>:
>> 
>> when I follow the changes described here:
>> http://lists.scsys.co.uk/pipermail/html-formfu/2009-January/001665.html
>> 
>> I get it working.
> 
> That's refering to $block->repeat() being called, which only happens during
> $form->model->default_values()
> ... so the question is why are you needing to call that *after* a form
> submission?
> 
> Generally, the logic should be:
> 
> if ( $form->submitted_and_valid ) {
>    $form->model->update;
> }
> elsif ( ! $form->submitted ) {
>    $form->default_values;
> }
> 
> What does your controller look like?

carl, thank

found the problem, I always called

$form->model->default_values

regardless if submitted or not, putting that in the not submitted part of the else made it work - thanks!

btw, I have 5 of those selects in the form, which need all to be present (which works now) AND should be unique. I can achieve this by making a unique constraint in the db and catch the error in an eval around $form->model->update. my problem: how can I force_error on the correct field? I can't seem to get the fields within the repeatable block. I normally do this like that:

$form->get_constraint('email')->force_errors(1);
$form->process;
$form->form_error_message('not saved');
$form->force_error_message(1);

how would I select the correct constraint (get_constraint) within the repeatable block? or is there an easier way to have unique select values within the repeatable block without evaling the db call?

thanks
josef


More information about the HTML-FormFu mailing list