lykmapipo / sails-hook-validation

Custom validation error messages for sails model with i18n support
104 stars 29 forks source link

Not working as expected. #8

Closed hussainb closed 9 years ago

hussainb commented 9 years ago

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.

lykmapipo commented 9 years ago

@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

hussainb commented 9 years ago

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.

lykmapipo commented 9 years ago

@hussainb Ok.

pakzech commented 9 years ago

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.

lykmapipo commented 9 years ago

@pakzech

Which sails adapter are you using?

pakzech commented 9 years ago

@lykmapipo

Using sails-mongo.

lykmapipo commented 9 years ago

@pakzech

Please follow this issue to resolve your problem