Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(forms) Async-Validators not triggered for ControlGroup as long as Sync-Errors persist #8118

Closed
choeller opened this issue Apr 18, 2016 · 3 comments

Comments

@choeller
Copy link
Contributor

Steps to reproduce and a minimal demo of the problem

Having a dependent validation in the form "If state is not "BACKLOG" assignee is required" using asyncValidators is not triggering as long as other Validations-Errors (e.g. required on another field) persist.

See the following plnkr:

http://plnkr.co/edit/8bmXDkmKiILUtKkRKhaf?p=preview

When your first action is to choose the state, the asncValidator will not be executed! Only after making the title field valid, by typing something in the title-field async-Validation works.

Current behavior

Async-Validations only get triggered, when no invalid sync-validations are present.

Expected/desired behavior

Async-Validations should be triggered independent of other validation errors.

Other information

@choeller choeller changed the title Async-Validators not triggered for ControlGroup as long as Sync-Errors persist bug(forms) Async-Validators not triggered for ControlGroup as long as Sync-Errors persist Apr 18, 2016
@pkozlowski-opensource
Copy link
Member

This is by design and we've got a test to prove it:

it('should run the async validator only when the sync validator passes', fakeAsync(() => {
const c = new FormControl('', Validators.required, asyncValidator('expected'));
tick();
expect(c.errors).toEqual({'required': true});
c.setValue('some value');
tick();
expect(c.errors).toEqual({'async': true});
}));

I guess that the reasoning is that async validation is "expensive" and as such should run after sync validators.

Async-Validations should be triggered independent of other validation errors.

Why? If sync validators mark a filed as invalid there is no point in checking with async validators. It was already market as invalid.

Do you have a specific use-case where the current design causes problems?

@kara
Copy link
Contributor

kara commented Sep 9, 2016

Yep, this is by design.

@kara kara closed this as completed Sep 9, 2016
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants