feat: add option to stop validation after first validation error
See original GitHub issueIf i apply the following annotations:
@IsNotEmpty()
@IsInt()
@Min(0)
foobar: number;
The validation result will be:
{
"value": null,
"property": "foobar",
"children": [],
"constraints": {
"min": "foobar must be greater than 0",
"isInt": "foobar must be an integer number",
"isNotEmpty": "foobar should not be empty"
}
}
If no value is given (i.e.: foobar === null), I only want the validation result of @IsNotEmpty.
All the others are quite useless… worse: since the validation errors (the constraints) are stored in an object, the ordering is lost so I cannot “just take the first error constraint” 😦
Expected result:
{
"value": null,
"property": "foobar",
"children": [],
"constraints": {
"isNotEmpty": "foobar should not be empty"
}
}
or:
{
"value": null,
"property": "foobar",
"children": [],
"constraints": [
{"isNotEmpty": "foobar should not be empty" },
{"isInt": "foobar must be an integer number"},
{ "min": "foobar must be greater than 0"}
]
}
Issue Analytics
- State:
- Created 5 years ago
- Reactions:25
- Comments:21 (9 by maintainers)
Top Results From Across the Web
Laravel how to stop validation after first error - Stack Overflow
1. Create a custom validator class extending the Laravel validator and overwrite the passes method. <?php namespace App ...
Read more >Stop validation after the first validation error was found
Hi , Would it be possible to stop further validations when the first error was found? Regards, Elena.
Read more >User Input Validation in Razor Pages
However, you should only ever view client-side validation as a courtesy to the user because it is easily circumnavigated. The MVC framework, on...
Read more >show message validate error input once at a time ant design ...
Removed exclusive option of getFieldDecorator . Added createFormField , and you must use it to wrap field data in option.mapPropsToFields of Form.create :...
Read more >Conventional Commits
Summary. The Conventional Commits specification is a lightweight convention on top of commit messages. It provides an easy set of rules for creating...
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 Free
Top 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

I agree. Would be much efficient when no validators would run after one failed.
My example:
IsInModelwill still run even thoughuserIdsent as string.And error will look doubled and not so smart:
User id must be an integer number. Invalid user idIt would be nice if there is a setting that makes the validator stop after the very first fail. For example, I have custom constraint that checks the database for email existence. I used the following decorators:
This makes database query even if email is empty or with less than 3 characters. Of course I could add additional checks in my constraint, but it makes no sense to do that.