Repository navigation
Conversation
|
@alexeagle, @alxhub, @amcdnl, @AndrewKushnir, @andrewseguin, @angular-jira-bot, @angular-pullapprove-bot, @benlesh, @b-laporte, @bowenni, @bradlygreen, @brandonroberts, @chembu, @clydin, @crisbeto, @dennispbrown, @devversion, @evmar, @filipesilva, @Foxandxss, @gkalpak, @google-admin, @googlebot, @gregmagolan, @hansl, @hazmatdance, @IgorMinar, @jasonaden, @jbogarthyde, @jelbourn, @jenniferfell, @johnpapa, @josephperrott, @jtraband, @juliemr, @kapunahelewong, @kara, @kyliau, @LucasSloan, @manughub, @marcelgood, @marclaval, @matsko, @mgechev, @mhevery, @mmalerba, @mprobst, @Narretz, @ocombe, @petebacondarwin, @pkozlowski-opensource, @rkirov, @robwormald, @sjtrimble, @stephenfluin, @vikerman, @vivian-hu, @wardbell Any chance we can merge this (see discussion in #20424)? |
|
@suspectpart: please don't spam. |
I am sorry for spamming you, not the best way for sure. I just didn't know who in the list of reviewers is still active and could provide some feedback. My apologies. |
|
Having in mind the fact that everyone is quite busy, one can't help but notice this is quite a severe issue especially in cases when a form control is being encapsulated within a container with |
There was a problem hiding this comment.
Not sure what others think, but I would be tempted to make this shorter by using !!asyncValidator.
There was a problem hiding this comment.
I'd prefer shorter version as well 👍
…pdate / validations RCA: During initialization of FormControl, `emitEvent` is getting passed as `false` to `updateValueAndValidity` function, inturn the same value got passed to the `_runAsyncValidator` function. (sets status = 'PENDING') and asyncValidator will be invoked. When we set the `FormControl` to the `FormGroup` via `FormGroup.setcontrol`, internally it is calling `updateValueAndValidity` (on FormGroup) function with `emitEvent` as undefined, it causes status change event to be emitted on `FormGroup` instance. (causes 'PENDING' status change event) When the asyncValidator (of FormControl) got resolved, `setErrors` function is getting invoked by passing the lexical scoped variable `emitEvent` (false in this case). As emitEvent value is `false`, susbsequent status change events are not getting notified !! If I understand correctly, status-change-events needs to be notified on value update / validations. Please correct me, If I am wrong. Issue: angular#20424
|
Rebased on master... |
|
To land this we need a presubmit from a Googler, and a review from someone in the |
|
Hi @kgopi, after running google3 tests, it turned out that this change breaks a few targets and additional investigation is required to find the origin of these failures and perform the necessary adjustments (either in the changes in this PR or in google3 apps code). I added the "blocked" label for now to indicate that and we'll get back to this PR once v9 final is released. Thank you. |
Can you give a rough projection when this is gonna happen? Is it more like a few weeks or a couple of months? |
Hi @suspectpart, I can not provide any ETA at this moment unfortunately, since ETA also depends on post v9 prioritization. I've added this ticket to "v10-candidates" milestone, so it will be reviewed and prioritized after v9 is released. Thank you. |
@AndrewKushnir, the 9th version has been rolled out recently. |
|
Any updates on this one? It have been a while since v9 rolled out |
| this.updateValueAndValidity({ | ||
| onlySelf: true, | ||
| emitEvent: asyncValidator ? true : false | ||
| }); // `asyncValidator` will cause status change, and that needs to be notified |
There was a problem hiding this comment.
I'd propose moving the comment above the corresponding line + use !!asyncValidator as Pete proposed, something like this (I've also updated a comment a bit):
this.updateValueAndValidity({
onlySelf: true,
// If `asyncValidator` is present, it will trigger control status change from `PENDING` to `VALID` or `INVALID`.
// The status should be broadcasted via the `statusChanges` observable, so we set `emitEvent` to `true`
// to allow that during the control creation process.
emitEvent: !!asyncValidator
});
The same/similar comment can be added to other places as well (FormGroup and FormArray).
| expect(logger).toEqual(['change!']); | ||
| }); | ||
|
|
||
| it('should only emit (`VALID`) status change event in absence of `FormControl.asyncValidator`', |
There was a problem hiding this comment.
Thanks for adding tests 👍
I think we should increase test coverage a bit more to handle additional cases, for example:
-
Standalone
FormControlwith async validator and bothstatusChangesandvalueChangessubscriptions and log what the output is. We should have 2 tests here tp cover bothVALIDandINVALIDresults of the validation. -
Standalone
FormControlwith both sync and async validators and see what happens instatusChangesandvalueChangessubscriptions when sync validators return true/false and async validator returns true/false. -
Combination of
FormGroupand a childFormControlto test the behavior when we initialize such combination and:- async validator is present on a
FormControllevel - async validator is present on both
FormGroupand a childFormControllevel
- async validator is present on a
-
Similar to the previous item, but cover the
setControlcase (this is what is partially implemented already). -
Similar to the one above, the combination of
FormArrayand a childFormControl: initialization phase and a case with calling some API methods that might trigger status change (like pushing new controls to the array). -
Combination of all classes:
FormGroup,FormArray(as a child to theFormGroup) andFormControl(as a child toFormArray).
Once we have improved coverage, we can also see what the difference is in what we emit into the statusChanges and valueChanges now vs what the new set of events are. That should help better formalize the "breaking changes" note to let developers know which changes to expect and how to handle them (if needed).
Please let me know if any additional information is required.
There was a problem hiding this comment.
Quick comment to the previous one: I think it'd also be great to have a test that would replace/remove a control (via setControl and/or other methods) which is running an async validator at this moment (i.e. in PENDING state), to see which events would be emitted in statusChanges.
|
Hi @kgopi, sorry for the delay in answering. I've re-ran presubmit and it looks like there is a couple places where this change triggering some failures. I will perform additional investigation and let you know. I also had a look at the changes and posted additional comments, mostly related to proposed increase in test coverage. Please let me know if you have any questions/comments. Thank you. |
|
Hi @kgopi, Just want to give a quick update: the PR #22575 that I mentioned (with the fixes to the control status with async validators) has landed recently (so you should have more accurate control status in tests now). Also I've updated a couple apps in Google's codebase to be compatible with this change. If you have a chance to perform additional updates based on the comments above (and add tests as I mentioned in #20806 (comment)), please let us know. Thank you. |
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
fix(forms): ensure to emit status change events on subsequent value-update / validations
RCA:
During initialization of FormControl,
emitEventis getting passed asfalsetoupdateValueAndValidityfunction, in turn the same value got passed to the_runAsyncValidatorfunction. (sets status = 'PENDING') and asyncValidator will be invoked.When we set the
FormControlto theFormGroupviaFormGroup.setcontrol, internally it is callingupdateValueAndValidity(on FormGroup) function withemitEventas undefined, it causes status change event to be emitted onFormGroupinstance. (causes 'PENDING' status change event)When the asyncValidator (of FormControl) got resolved,
setErrorsfunction is getting invoked by passing the lexical scoped variableemitEvent(false in this case).As emitEvent value is
false, susbsequent status change events are not getting notified !!If I understand correctly, status-change-events needs to be notified on value update / validations.
Please correct me, If I am wrong.
Issue: #20424
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: #20424
What is the new behavior?
Does this PR introduce a breaking change?
Other information