Tuesday, 15 March 2011

node.js - express-validator retain input values -


Im node nodes, expressjs and z I am using express-validator to validate a form.

In the route:

  req.assert ('firstname', 'name is required') notEmpty () .; Req.assert ('Last name', 'name is required'). NotEmpty (); Req.assert ('email', 'a valid email is required'). IsEmail (); Var Errors = req.validationErrors (); .... if (errors) {res.render ('user / new', {errors: errors}); }   

in Z , to display the error:

  - if (errors) div.alert .alert-ral ul - errors in every error li = error.msg   

The above code works I want to keep the input value in the form so that users do not type it.

  input # name (type = "text", name = "name", value = "?")   

how?

Thanks

You can revert the value to the rendered view directly and Input tags can be placed on each other.

  if (errors) {res.render ('users / new', {errors: errors, first name first name, ...}); }   

and put in jade template

  input # name (type = "text", name = "firstname", value = "# {firstName} Input # name (type = "text", name = "firstname", value = first name)   

or

or Pre>

It depends on your personal style. It is better to define values ​​like

person.first , person.last and Person.email , because you only You can put person in the view of your code.

No comments:

Post a Comment