[html-formfu] Constraint on a joined field (CompoundJoin)

Carl Franks fireartist at gmail.com
Mon Aug 18 13:29:42 BST 2008


2008/8/18 Moritz Onken <onken at houseofdesign.de>:
>
> Am 02.08.2008 um 10:14 schrieb Moritz Onken:
>
>> Added a second test (actually renamed the first one to
>> constraint_compoundjoin.t)
>> repeatable_compoundjoin.t tests a join block in a nested repeatable block.
>> I can't find the right field names.
>>
>> If I render the form the field names are "nested.nested.end_1.enddate_1"
>> which is
>> awkward. I also tried nested.end_1.enddate_1 and nested.end_1.enddate. No
>> luck yet
>>
>> any ideas?
>>
>> both tests are in svn xt/
>
> Hi Carl,
>
> did you have a look at this test?

I did reply, but here it is again, in case it didn't get through to the list:.
(short answer is: there is a couple of ways to work around it, but it
can't be fixed)
...

Filters are run before Constraints.
So by the time the 'enddate' Required constraint tries to run, the
CompoundJoin filter has already munged the hashref into a string.

I think the only way around this, is to instead attach a constraint to
the Multi block, which checks the filtered value is logically correct.

Alternatively, I suppose you could create a new Required constraint,
which instead checks the value was present in the initial input,
rather than the value that's fed to the constraint.
Something like this should work:

package HTML::FormFu::Constraint::PreFilterRequired;

use strict;
use base 'HTML::FormFu::Constraint';

sub constrain_value {
   my ( $self ) = @_;

   my $form  = $self->form;
   my $name  = $self->parent->nested_name;
   my $value = $form->get_nested_hash_value( $form->input, $name );

   return defined $value && length $value;
}

1;



More information about the HTML-FormFu mailing list