I created the following plugin....

exports = module.exports = function (req, res, next) {
    var body = req.body;
    if (typeof body === 'undefined') {
        return next(new Error('form-values must be used after 
body-parser'));
    }
    var bodyKeys = Object.keys(req.body);
    res.locals.fv = function (name, defaultValue) {
        if (bodyKeys.indexOf(name) === -1) {
            if (typeof defaultValue === 'undefined') {
                return '';
            } else {
                return defaultValue;
            }
        } else {
            return req.body[name];
        }
    }
    return next();
};

Then to use it
var formValues = require('./lib/form-values');
app.use(formValues);

In the view
input(name="username", value="#{fv('username')}", type="text")

You can also use #fv('fieldName', 32)


-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/9abe9ff9-8488-4f2a-9241-349d9f2c3827%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to