Trying to use Promise in Custom Validator
See original GitHub issueCool. Ok, so I’ve got a custom validator working in the strictest sense when validateString
returns either true
or false
. I’ve noticed in the current docs that validating functions “can instead return a promise that will be resolved if the value is valid, or be rejected otherwise”. That is what I need to happen, but am having difficulty implementing it. I’m using the native JS Promises like so:
validateString: function(){
var promise = new Promise(function(resolve, reject){
confirmEmailAjax(function(boolean){
if (boolean) {
resolve('Yay');
} else {
reject('sad face');
}
});
});
return promise;
},
confirmEmailAjax
is returning either true
or false
. @marcandre can you shed some light on this? Is the promise referenced in the docs utilized differently? If I need to open a thread on this some where else, I’ll happily do so. Let me know.
Issue Analytics
- State:
- Created 8 years ago
- Comments:7
Top Results From Across the Web
Angular Custom Validators. How to validate a form field using ...
I need to validate a form field using a method which returns a Promise. But it never returns the error because Promises are...
Read more >How to write async form validators with Angular?
Example of custom async validator. In this example, we want to create a form input where the user enters a stock exchange ticker...
Read more >Custom Rules - VeeValidate
This is the most basic custom validator form. It consists of only a function that returns either a Boolean or a promise. However,...
Read more >Custom validators synchronous | Fonk Doc
A field synchronous validator is just a function that expects one argument ... it using promises, in that case you have to use...
Read more >Using Custom Async Validators in Angular Reactive Forms
Ocasionally, we want to validate some input in our fields before submission, which will be validated against an asynchronous source. For ...
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
Yep, this works well. Gonna leave this here to help others:
Thanks!
Perfect, thanks, that shows how one can use custom validatior to get the same (or even more) than a remote validator can do (I am speaking about the custom dynamic error message 😃). Thanks a lot.