Open warnero opened 11 years ago
Friend helped me out and I managed to fix it by doing this instead exports.validateObject = form( form.field("bookmark_url").trim().required().isUrl(), form.field("bookmark_title").trim(), form.field("bookmark_tags").trim(), form.field("bookmark_description").trim() );
Would be good if you could add an example showing this for others.
Good suggestion, I had this issue myself when I tried to do the same thing.
:+1: I just hit this today. So glad to have found warnero's snippet. Which in hindsight seems so obvious, thanks!
Glad I stumbled upon this! Nice one...
I have this defined in an external file exports.validateObject = function(req) { return form( form.field("bookmark_url").trim().required().isUrl(), form.field("bookmark_title").trim(), form.field("bookmark_tags").trim(), form.field("bookmark_description").trim() ); }
I'm then using it in my app.js like this: app.post('/notebooks/:notebookId/bookmark', route.validateObject, route.saveObject);
It gets to the validateObject function but never calls my route method. Hoping you can help shed some light on how to use it this way as I don't see any examples that allow you to separate your validation from where you define your routing. I have also verified that all the fields are coming through to the validateObject method by looking at the req.body.