Subject: | Compound Field Bug |
Date: | Thu, 13 Jan 2011 09:12:41 +0800 |
To: | bug-HTML-FormHandler [...] rt.cpan.org |
From: | John Maslanik <maz [...] mlx.net> |
Summary:
Subfields of a compound field do not validate if all subfields of a
compound are blank.
Version:
0.32005 (latest)
How to reproduce:
Create a compound field with sub fields, make one of the sub fields
"required", process the form with the compound field and all of the sub
fields blank, the form will pass validation even though the "required"
subfield is blank.
Details:
I tracked the problem down to the validate_field sub in
FormHandler:Validate line 54. $field->input_defined is called at line
71 which is defined in HTML::FormHandler::Field line 516. input_defined
then returns the results for has_some_value which is defined in
HTML::FormHandler::Validate::Actions line 148. As you can see if you
examine the has_some_value function, 0 is returned if the value is a has
and non of the members contain a value, which is the case for a compound
field with none of the subfields filled in. This prevents the
$field->_fields_validate function in HTML::FormHandler::Validate from
being called which would validate all the subfields.
Proposed Solution:
Add the following:
elsif ( $field->DOES('HTML::FormHandler::Field::Repeatable') ) { }
on line 67 of HTML::FormHandler::Validate right after the line that reads:
elsif ( $field->DOES('HTML::FormHandler::Field::Compound') ) { }
Attached is a test that exhibits the bug:
Message body is not shown because sender requested not to inline it.