Custom validators ignore return value
See original GitHub issueI just updated from v5.3.1 to the latest v6.1.1. And I realized my custom validators are not working anymore. I used to just return false;
to make the validator fail. But now I need to throw an exception.
To me this would be a “breaking change”, but I couldn’t find anything in the changelog. And another question would be if there is a particular benefit doing it that way? I find it cleaner to just return a boolean, cause that is exactly what one asks the validator: “Can you check if this check is true or false?”
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:8 (3 by maintainers)
Top Results From Across the Web
How to return data to templates from custom validator in Angular
When creating a custom validator in Angular we have to return a javascript object (with true value) when an error is found (at...
Read more >The best way to implement custom validators - Angular inDepth
The validator itself is just a function that accepts an AbstractControl and returns an Object containing the validation error or null if everything...
Read more >How To Use Custom Form Validation in Angular - DigitalOcean
This validator will return an object - { 'phoneNumberInvalid': true } - if the value fails the condition of not being equal to...
Read more >Building Custom Validators in Angular - Pluralsight
Every field in a form can act as a FormControl that returns complete ... Custom validators take the value from the FormControl ,...
Read more >Validation - Laravel - The PHP Framework For Web Artisans
Validating Files; Validating Passwords; Custom Validation Rules ... even providing the ability to validate if values are unique in a given database table....
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
@sheghun people used to complain that a custom validator needed a return value to tag their field valid.
E.g.
…whereas the docs have always stated (although not clearly) that a resolved promise means a valid field. So the return value shouldn’t be important.
I have expanded the docs with clearer details on this.
Ah yup, when the custom validator is async a resolved promise means a successful result. I guess it needs more extensive docs then.