Closed eduardonunesp closed 10 years ago
This is more of an issue with how Mongoose uses the validators. Validators will not be run by mongoose is no data exists - as you've discovered the only way or forcing them to run is to use required: true
. If you are using the models error messages to update the view, then you may want to look at abstracting that out.
You found solution to this problem? how can i set custom messgae for required field?
Why not use mongoose's built in required
validator? - see the docs
The problem occurs when try save a post and the values are omitted for my validators, as following:
So the request came with json data, but if the request in blank like
{}
, or if only one field is set like{"name":"Eddie"}
, the other field (email) ins't tested.Then i set to
required: true
in my schema, but the problem is cannot manipulate theerror message
with my validators.