Skip to content

How to use observable operators like debounceTime and switchMap for asynchronous validations #6895

@templth

Description

@templth

I find observables really powerful. In the context of HTTP, it's a killer feature since we can use the debounceTime and switchMap operators to control the sent requests and cancel them if necessary.

When using asynchronous validators, it seems that we don't have access to this feature since the call of the validator is internally done and we can't configure the way it's triggered.

I would like to implement something similar than the following within asynchronous validation:

this.ctrl.valueChanges.debounceTime(500).switchMap((val) => {
  return this.http.get('https://...');
}).subscribe((data) => {
  // here would be the validation
});

Is it something supported (or that will be) at the form validation level?

Thanks very much by advance,
Thierry

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions