[Catalyst] HTML-Widget result new add_error() method
Carl Franks
fireartist at gmail.com
Thu Mar 16 17:47:52 CET 2006
I've added a new add_error() method to HTML-Widget-Result
Internally, this uses a new HTML-Widget-Error-Custom package
Here's an example of use from the POD.
if ( ! $result->has_errors ) {
my $user = $result->valid('username');
my $pass = $result->valid('password');
if ( ! $app->login( $user, $pass ) ) {
$result->add_error({
name => 'password',
message => 'Incorrect Password',
});
}
}
In this example, the $result initially contains no errors. If the login()
is unsuccessful though, add_error() is used to add an error to the password
Element. If the user is shown the form again using $result->as_xml(),
they will be shown an appropriate error message alongside the password
field.
[snip]
With regards to this - I think if an error is added to, say field 'foo',
then $result->valid('foo') should return undef.
I think it would be strange that both these could return true:
$result->valid('foo')
$result->has_errors('foo')
Any disagreements?
Cheers,
Carl
More information about the Catalyst
mailing list