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

Asynchronous validator overrides validation result from synchronous validator #8923

Closed
2 tasks
NiklasJFischer opened this issue May 31, 2016 · 4 comments
Closed
2 tasks

Comments

@NiklasJFischer
Copy link

  • I'm submitting a ...
  • [x ] bug report
  • feature request
  • support request => Please do not submit support request here, see note at the top of this template.

Current behavior
When adding both synchronous and asynchronous validators to a control, the control is in valid state after the asynchrous validator is done even though the synchronous validator says invalid. For example if you have the "required" validator and a custom asynchrouns validator that takes 2 seconds to complete and you erase all text during these 2 seconds the control is in valid state after the 2 seconds.

Expected/desired behavior
The control should be in invalid state because of the "required" validator.

  • If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via
    1. Create a form with an input type="text"
    2. Add a control to that input with the "required" validator and a custom asynchronouns validator that takes 2 seconds to complete.
    3. Write some text in the input control to trigger the asynchrouns validator and then erase all text before it completes
  • What is the expected behavior?
    The control should be in invalid state and not valid state because of the "required" validator
  • What is the motivation / use case for changing the behavior?
    Form validation should work with asynchronous validators
  • Please tell us about your environment:
  • Angular version: 2.0.0-beta.17
  • Browser: [Chrome 50 | IE 11]
  • Language: [TypeScript 1.7.3 | ES5 ]
@zoechi
Copy link
Contributor

zoechi commented May 31, 2016

Sounds similar to #8118

@nukefusion
Copy link

Just ran into this myself. The workaround I'm using for the time being is to wrap the synchronous validators in a promise and pass them all together as async validators using composeAsync. For example (I'm using TypeScript):

this.username = new Control("", null, Validators.composeAsync([ (control: Control) => Promise.resolve(Validators.required(control)), (control: Control) => this.usernameDoesNotExistValidator(control) ]));

@pkozlowski-opensource
Copy link
Member

Yup, definitively a bug and one still present in RC6: https://plnkr.co/edit/y10r0ETIKShfVCqX91LP?p=preview

DzmitryShylovich pushed a commit to DzmitryShylovich/angular that referenced this issue Jan 28, 2017
DzmitryShylovich pushed a commit to DzmitryShylovich/angular that referenced this issue Jan 29, 2017
mhevery pushed a commit that referenced this issue Feb 2, 2017
mhevery pushed a commit that referenced this issue Feb 3, 2017
asnowwolf pushed a commit to asnowwolf/angular that referenced this issue Aug 11, 2017
juleskremer pushed a commit to juleskremer/angular that referenced this issue Aug 28, 2017
@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 10, 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

4 participants