-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Async Validator causes form control state to be set to valid when other validators are invalid #10074
Description
I'm not sure if this is a bug or not but the behavior doesn't make sense. I'm using a model driven form on my page and one of the controls has two synchronous validators (required and minlength) and a custom asyncValidator. When the page initially loads the form control is empty so it should be failing the required and minlength validations. The custom validator will return valid when the field is empty. However, the state of the control is being set Valid on form initialization. Previously my custom async validator had been a synchronous validator and it worked as expected, i.e. the custom validator is initially valid but the form control is still invalid due to the other validations being invalid.
The following plnkr illustrates the behavior:
http://plnkr.co/edit/VJlg1Q1EXs9mQ8Bx2YTQ?p=preview
Also, note that the after form initialization the async validator only runs after satisfying the minlength requirement (in this case upon typing the 6th character) while the sync validator runs on every key press and the sync validator is run twice on form initialization while the async validator only runs once. Another thing is that the form control with the async validator will report invalid if you type some characters then delete them all making the field empty.