From 27d9c9b0f69e39e998bacdcf781ffff584b42b06 Mon Sep 17 00:00:00 2001 From: Sahat Yalkabov Date: Sat, 1 Feb 2014 03:49:38 -0500 Subject: [PATCH] Add express-validator example to flash messages guide --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index af23a9e8df..5f9c849ed0 100644 --- a/README.md +++ b/README.md @@ -405,7 +405,16 @@ The reason why you pass an error like `{ msg: 'Error messages goes here' }` inst of just a string - `'Error messages goes here'`, is for the sake of consistency. To clarify that, *express-validator* module which is used for validating and sanitizing user's input, returns all errors as an array of objects, where each object has a `msg` property with a message -why an error has occured. To keep consistent with that style, you should pass all flash messages +why an error has occured. Here is a more general example of what express-validator returns when there are errors present: + +```js +[ + { param: "name", msg: "Name is required", value: "" }, + { param: "email", msg: "A valid email is required", value: "" } +] +``` + +To keep consistent with that style, you should pass all flash messages as `{ msg: 'My flash message' }` instead of a string. Otherwise you will just see an alert box without an error message. That is because, in **partials/flash.jade** template it will try to output `error.msg` (i.e. `"My flash message".msg`), in other words it will try to call a `msg` method on a *String* object,