Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

date type validation customization doen't work #5

Closed
ctimoteo opened this issue Mar 22, 2015 · 3 comments
Closed

date type validation customization doen't work #5

ctimoteo opened this issue Mar 22, 2015 · 3 comments

Comments

@ctimoteo
Copy link

Hello,

i think that i cannot customize validation messages of attributes with type "date" with your module
(sails v0.11 updated and latest module code too),

in my model User i have one attribute set as:

birthday: {
type: 'date',
required: true,
unique: false
},

in validationMessages object i added:

birthday: {
required: 'Your birthday is required',
birthday: 'Birthday is not a valid date'
}

when i called the User.create function (in Controller), with a invalid date 'aaa' in attribute birthday,

User.create(data, function(error, user) { (...) });

it returns validation errors as expected, but error.Error is empty (empty object {})

if i retrieve invalidAttributes property from errors, i get the original validation error:

{ birthday:
[ { rule: 'date',
message: 'undefined should be a date (instead of "aaa", which is a string)' } ] }

am i doing something wrong or date type validation is not customized correctly with your module?

thanks in advance.

@lykmapipo
Copy link
Owner

@ctimoteo all custom error messages are placed on error.Errors.

Check that if it does not work. Let me know

@lykmapipo
Copy link
Owner

@ctimoteo

In sails validation are series of rules on attribute which sails-hook-validation tap in to them and pick any validation error found and match it with your custom validation messages.

So your validation messages must contain valid sails validation rules.

To setup your birthday rules(date rule) check

And you can access custom messages as shown on the spec:

Hope it help.

@ctimoteo
Copy link
Author

Yes, helped a lot!
My mistake was to use the field name instead of rule name as you mentioned.
i already added minLength and other rules, everything works now.

Thank you, one more time.

I will close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants