node.js - express-validator error message attributes and location -


i using expressjs, node , handlebars.

in post function have following:

routes.js

req.assert("referencenumber", "enter ...").notempty(); req.assert("yourpostcode", "enter ...").notempty();  var errors = req.validationerrors(true);  if (errors) {    res.render('<page>/index', {    title: "<title>",    errors: errors });  } else {    // redirection } 

index.hbs

{{#if errors}}  <ul>   {{#each errors}}     <li><a href="#">{{this.msg}}</a></li>   {{/each}}  </ul> {{/if}} 

this outputs list of errors on submission great. problem need error message located next form field as.

so ideally can target each error name e.g. "referencenumber", "yourpostcode".

i have thought maybe having variable inside routes.js so:

if (errors) {    res.render('<page>/index', {    title: "<title>",    referencenumber: <something>,    yourpostcode: <something> }); 

and perhaps able funky way.

it associating id each error message act anchor link each error form field.

totally stumped one, , appreciate help.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -