Validation::Class, Mojolicious::Lite and HTML5 Form Field Rendering
This screencast shows how easy it is to create a web application form with HTML5 form fields and client and server-side validation using Mojolicious::Lite, Validation::Class and Validation::Class::Plugin::FormFields. #cpan #perl #mojolicious
First off, Great Job! Validation::Class looks like a good library.
Reading through the docs for Validation::Class, I don't see a way to get a hashref of all errors discovered (broken down by field name).
I'd like to get a hashref of fields and errors like:
use Data::Dumper;use MyApp::Validation;
my $input = MyApp::Validation->new(params => $params);
unless ($input->validate()){
warn Dumper( $input->errors_to_hashref );
}
# I want:
$VAR1 = {
email => 'Required',
password => 'Too short',
};
Would I need to implement my own "errors_to_hashref" method in my subclass?
jdrago999.myopenid.com, Hi, thanks for the cudos. You're looking for the error_fields() method and it does currently exist. Let me know how it works out.
https://metacpan.org/module/Validation::Class#error_fields
Nice work Al. I plan to try this out soon.
Thanks nickl. Let me know how it goes.
Yes! That will work.
I am having difficulty implementing Class::Validation with a Mojolicious app that does NOT use Mojolicious::Lite (i.e., it's a full-fledged Mojolicious app). I think maybe some of the subroutine names have changed, etc. since this video was created. For instance, I get an error using the 'load_plugins' method. And even if I comment out that line, I then get an error when using the 'render_field' method. Any ideas how I can implement Class::Validation (i.e., what changes need to be made since the video was made)?