Add option to un-flat the error object
See original GitHub issueFeature request:
Add option to allow to return an un-flat error object by adding an options argument for Validator
.
/**
* Default options
* {
* flat: Boolean (Default: true)
* }
*/
const validation = new Validator(data, rules, {flat: false});
const errors = validation.errors.all();
// > {foo: {bar: 1}}
const validation = new Validator(data, rules);
const errors = validation.errors.all();
// > {'foo.bar': 1}
Personally I would find this option useful when using with redux-form
where the validation function must return an nested object structure as received.
Additionally the options
argument could be extended with more features e.g. instance only rules (proposed #98 )
Could be easily added using flat.unflatten
, rather then implementing your own unflatten
method.
I can implement the changes if you agree with my proposal.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:5
Top Results From Across the Web
Add properties to JavaScript Error object? - Stack Overflow
In my specific code, I'd like to tag an Error object with my own tag name for further use, which means -> adding...
Read more >Error - JavaScript - MDN Web Docs - Mozilla
Error objects are thrown when runtime errors occur. The Error object can also be used as a base object for user-defined exceptions.
Read more >ActiveModel::Errors - Rails API
Active Model Errors Provides error related functionalities you can include in your object for handling error messages and interacting with Action View ...
Read more >flat array to tree - macellerialucio.it
If the goal is to just create a flat array of all the nodes' item values, this may be better: const traverse =...
Read more >A mostly complete guide to error handling in JavaScript.
stack : a stack trace of functions execution. For example, if we create a new TypeError object with the appropriate message, the message...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
+1 for redux-form nested errors support.
This library will do the trick but having one less dependency would be nice.
unflatten(validator.errors.all())
https://github.com/hughsk/flat
How about we make
options
the 4th argument to ensure backwards compatibility. Ifoptions
needs to be passed, the invocation would look like this:const validation = new Validator(data, rules, {}, { flat: false });