-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Custom validation not documented completely #8905
Comments
Or simply {
attribute: {
validate: {
isURLArray() {
const urlArray = urls.split(',');
if (urlArray.find((url) => !Validator.isUrl(url))) {
throw new Error('Array contains invalid urls!');
}
}
}
}
} |
I'm aware of that. You linked the same documentation that I linked in my post. Using a custom function in the |
What are you doing?
Extending
Sequelize.Validator
with a custom validator for an array of urls, according to this, by just throwing an error if the format is wrong. The reason I used that is because I could not findValidator.extend
documented anywhere.What do you expect to happen?
The validation passes for an array of valid urls, otherwise it throws.
What is actually happening?
The validation throws correctly for invalid array (throws
Array contains invalid urls!
error). However, for an array of valid urls, it throwsValidation isUrlArray on images failed
.The reason this happens is this line. If the validator function doesn't return a truthy value, the generic error with the
validatorType
andfield
is thrown.It seems that extending Validator adds a new built in validator, instead of a custom one. However, built in validators seem to return falsy values instead of throwing (like custom ones do). And since
Validator.extend
isn't documented anywhere, nor is writing new built in validators, this creates a problem. Basically, the way I fixed this was just making my validator return true or false, but I think the docs should be updated with this use case or by makingValidator.extend
add a new custom validator.Dialect: postgres
Database version: 10
Sequelize version: 4.28.1
Tested with latest release: No, but the mentioned line of code is unchanged since this version
The text was updated successfully, but these errors were encountered: