Comments (6)
I decided to use a separate validationErrors
method in order to get information about more errors at once. You could add an optional attribute which triggers validation automatically before saving the Model: I'd happily accept a pull request for that! 😊
Also, I think there should be a custom Error object made for throwing exceptions.
from bookshelf-validate.
Also, I think there should be a custom Error object made for throwing exceptions.
This is possible, but then you would probably also want to have your validations look like this:
validations: {
email: [
{
method: 'isEmail',
options: {/* validator isEmail options object */},
error: 'E_INVALID_EMAIL'
}
]
}
and the corresponding error messages:
{
email: ['E_INVALID_EMAIL']
}
instead of the current one which returns just the called method name.
That way you can throw a custom error message for each validation even if it uses the same validation method in different models.
With that setup though it would reduce boilerplate to almost nothing, and just adding the validations
object to a model would do pretty much everything you need.
from bookshelf-validate.
Also, not sure if you're interested but I refactored the plugin just to be a bit cleaner, get rid of the new Function
eval, changed all of your let
to const
where possible, and got rid of the continue
statements in favor of control flow logic.
If you want to use that, I can make a pull request with it and for the custom error and auto-validate on save stuff after I write that.
from bookshelf-validate.
That would be great, but please, submit the Error emission feature as a separate pull request.
I'd suggest to create a new ValidationError
object with a data
argument which shall return the values returned by the Model.validationErrors()
function instead of adding an error
property to Model.validations.[property]
from bookshelf-validate.
Ok this is working really well, I'm happy with the result. I also recommend not adding the special isRequired
checks in the Plugin, but rather onto the validator object as a normal method.
I'll make a couple of PRs in a minute...
from bookshelf-validate.
Thank you very much for all the help you provided! I highly appreciate all of your efforts towards my project.
from bookshelf-validate.
Related Issues (5)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bookshelf-validate.