Subject: | Custom Missing Messages Support |
While working DFV into Handel, it became apparent that the missing field messages are geared towards being display right next to the field in question, and not em masse at the top of the page; where 5 "Missing" messages mean nothing to the user.
After being sick of me complaining, Matt Trout tossed together the start of this patch. I tweaked it somewhat to deal with a default within the missing hash.
In a nutshell, this patch:
- Allows you to use the old style missing format:
'myprofile' => {
missing => 'Custom Missing!'
}
- Allows you to create a hash containing a custom message per field:
'myprofile' => {
missing => {
default => 'Custom Missing',
myfield => 'The field 'myfield' cannot be empty...'
}
}
When using a hash, of no entry for a field is found, the default key/value is used. IF that is not found, 'Missing' is used.
--- Results.pm.orig Wed Aug 31 22:27:27 2005
+++ Results.pm Wed Sep 14 17:40:28 2005
@@ -584,7 +584,9 @@
if ($self->has_missing) {
my $missing = $self->missing;
for my $m (@$missing) {
- $msgs{$m} = _error_msg_fmt($profile{format},$profile{missing});
+ $msgs{$m} = _error_msg_fmt($profile{format},
+ (ref $profile{missing} eq 'HASH' ?
+ ($profile{missing}->{$m} || $profile{missing}->{default} || 'Missing') : $profile{missing}));
}
}