I'm using connect-flash to display error messages back to the user on unsuccessful form submit.
req.assert('email','Invalid email address').isEmail();
req.assert('type','Invalid type').matches('^full$|^half$');
var errors = req.validationErrors(true);
if (errors){
req.flash('errors',errors);
return res.redirect('checkout');
}
errors are mapped values from express-validator. Which redirects to
res.render('checkout',{
errors: req.flash('errors')[0] // this looks sloppy?
});
And then in my view I can render
{{#if errors.email}}
<h4 class="regular red mt0">{{errors.email.msg}}</h4>
{{/if}}
Above, where I comment 'sloppy'. I would like a more clear way to pass mapped error values to the view without having to understand that connect-flash uses an array for each property. Should I just use a session variable 'errors' and set to null after render? That seems perhaps clearer.
I hope that's clear! Thanks for your help.