Hello!
I found myself having a Checkbox and an Input field and wanting to check
requiredness on the input field only if the Checkbox was selected.
Checkbox is defined as follows:
{
name => 'mycheckbox',
type => 'Checkbox',
value => '1',
}
The Input field has this constraint:
{
type => 'Required',
when => {
field => 'samehash',
value => '1',
not => 1,
},
}
This doesn't really work when the checbox is not submitted, as its value is
not defined and the when condition returns true. Since what I needed was to
check anyway, as I actually wanted the constraint NOT to be applied when the
checkbox was not selected, I had to patch the Constraint.pm code as per
attachment so when accepts now a:
always => 1
parameter which goes on with the check even if the value of the field to be
checked (the checkbox in my case) is unsubmitted (=>undef).
Let me know if this patch could be interesting to apply and I'll do (with doc
and test of course). Also, if you have a better name than "always"... ;-)
If what I'm doing is easy to achiever without the patch and I'm messing
something obvious, please tell me as well. :-D
Thanks,
Michele.
--
Michele Beltrame
http://www.cattlegrid.info/
ICQ 76660101 - MSN [EMAIL PROTECTED]
--- u/www/cheiron/cryo/Cryo/lib/HTML/FormFu/Constraint.pm
+++ home/mb/devel/formfu/trunk/HTML-FormFu/lib/HTML/FormFu/Constraint.pm
@@ -123,7 +123,7 @@
# nothing to constrain if field doesn't exist
my $when_field_value = $params->{$when_field};
- return 0 if !defined $when_field_value && $when->{always} != 1;
+ return 0 if !defined $when_field_value;
# a compare value must be defined
my @values;
_______________________________________________
HTML-FormFu mailing list
[email protected]
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu