Data-FormValidator-ErrMsgs-JavaScript
view release on metacpan or search on metacpan
lib/Data/FormValidator/ErrMsgs/JavaScript.pm view on Meta::CPAN
A closure could then be created which passing in the arguments
you want.
=cut
sub dfv_js_error_msgs {
my $self = shift;
my $controls = shift || {};
if (defined $controls and ref $controls ne 'HASH') {
die "$0: parameter passed to msgs must be a hash ref";
}
# Allow msgs to be called more than one to accumulate error messages
$self->{msgs} ||= {};
$self->{msgs} = { %{ $self->{msgs} }, %$controls };
my %profile = (
prefix => '',
%{ $self->{msgs} },
# XXX Should maybe have some javascript quoting on the field name
format => qq{<script type="text/javascript">dfv_error_msg('%s');</script>},
);
my %msgs = ();
# Add invalid messages to hash
# look at all the constraints, look up their messages (or provide a default)
# add field + formatted constraint message to hash
if ($self->has_invalid) {
my $invalid = $self->invalid;
for my $i ( keys %$invalid ) {
$msgs{$i} = sprintf $profile{format},$i;
}
}
# Add missing messages, if any
if ($self->has_missing) {
my $missing = $self->missing;
for my $m (@$missing) {
$msgs{$m} = sprintf $profile{format},$m;
}
}
my $msgs_ref = Data::FormValidator::Results::prefix_hash($profile{prefix},\%msgs);
if (! $self->success) {
$msgs_ref->{ $profile{any_errors} } = 1 if defined $profile{any_errors};
}
return $msgs_ref;
}
=head1 FUTURE
If you like this extension to Data::FormValidator, give me some feedback
on the Data::FormValidator list and we'll work out a stable interface.
L<http://lists.sourceforge.net/lists/listinfo/cascade-dataform>
=head1 AUTHOR
Mark Stosberg, C<< <mark at summersault.com> >>
=head1 BUGS
Please report any bugs or feature requests to
C<bug-data-formvalidator-errmsgs-javascript at rt.cpan.org>, or through the web interface at
L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Data-FormValidator-ErrMsgs-JavaScript>.
I will be notified, and then you'll automatically be notified of progress on
your bug as I make changes.
=head1 SEE ALSO
L<Data::FormValidator>
L<http://search.cpan.org/dist/Data-FormValidator-ErrMsgs-JavaScript>
=head1 COPYRIGHT & LICENSE
Copyright 2005 Mark Stosberg, all rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=cut
1; # End of Data::FormValidator::ErrMsgs::JavaScript
( run in 0.409 second using v1.01-cache-2.11-cpan-4991d5b9bd9 )