Subject: | Constraint conditions don't work when using nested field names [PATCH] |
I have a form with a constraint that I want to enable only if another
form field hasn't a specific value. The condition is not fullfilled when
that other form field is a nested field.
Example form:
- elements:
- type: Block
nested_name: nested1
elements:
- type: Text
name: item1
- type: text
name: item2
constraints:
- type: +CustomConstraint
when:
field: nested1.item1
value: PF
not: 1
I traced the cause of the problem to the _process_when method of
HTML::FormFu::Constraint. It does work only when the "field" value is a
simple name and it doesn't when the value is a nested name. My knowledge
of FormFu internals is very limited, but it looks like the easy fix is
to use get_nested_hash_value to get the value for the field, like in
other parts of the code.
Subject: | HTML-FormFu-0.03005-constraint-when-nested-fieldname.patch |
--- HTML-FormFu-0.03005/lib/HTML/FormFu/Constraint.pm.orig 2008-09-04 17:31:01.000000000 +0300
+++ HTML-FormFu-0.03005/lib/HTML/FormFu/Constraint.pm 2008-10-13 18:34:07.000000000 +0300
@@ -124,7 +124,7 @@
}
# nothing to constrain if field doesn't exist
- my $when_field_value = $params->{$when_field};
+ my $when_field_value = $self->get_nested_hash_value( $params, $when_field );
return 0 if !defined $when_field_value;
# a compare value must be defined