Not working as expected.
Closed this issue · 7 comments
Hello,
This looked like a good solution for my custom validation message needs, but unfortunately this is not working.
I am using sails 11
Below is my model:
module.exports = {
attributes: {
name: {
type: "string",
unique: true
},
email: {
type: "email",
unique: true
},
password: {
type: "string"
}
},
validationMessages: { //hand for i18n & l10n
name: {
unique: 'name is already taken'
},
email: {
required: 'Email is required',
email: 'Provide valid email address',
unique: 'Email address is already taken'
}
}
}
Dont know if this interests you or not, but this is the sails generated error object which I got form console.log(error)
at node_modules/sails-hook-validation/lib/create.js
line no: 50, before the if(error.ValidationError)
.
{
"error" : "E_VALIDATION",
"status" : 400,
"summary" : "2 attributes are invalid",
"invalidAttributes" : {
"name" : [{
"value" : "hb",
"rule" : "unique",
"message" : "A record with that `name` already exists (`hb`)."
}
],
"email" : [{
"value" : "me@gmail.com",
"rule" : "unique",
"message" : "A record with that `email` already exists (`me@gmail.com`)."
}
]
}
}
Since the above error
object do not have the ValidationError
property, It will not be going into the if statement.
@hussainb Please may you check sails-hook-validation spec.
You may consider fork and clone the repo then run the test. Hope they will give you an insight of your problem.But so far sails add error.ValidationError
on error object which sails-hook-validation
relies on it.
If it will help close the issue. Otherwise am here to help
I have currently decided to leave the validation messages as it is since I need to spend time on studying sails overall to get to a decision to use sailsjs or some other framework like krakenjs.
But I confirm that there is no VaildationError
property in the error object. I have tried with sails-disk adapter and sails-mongo adapter.
Sorry and thanks.
Same issue here. Using Sails 0.11.0.
Test fails too. As said before, if(error.ValidationError)
never enters because that property doesn't exists in the error object.
Using sails-mongo.