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

Carl Franks fireartist at gmail.com
Tue Aug 5 10:15:37 BST 2008


2008/8/2 Moritz Onken <onken at houseofdesign.de>:
> Hi,
>
> I put a Required constraint on a field which is joined with another field.
> ->get_errors tells me that this field is required but it has a value and
> the joined field is filled with the joined value.
>
> Test is in svn xt/repeatable_compoundjoin.t

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