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
fix(forms): Don't override form group's dirty state when disabling controls #24591
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the bug fix! Some comments below.
@@ -491,10 +494,13 @@ export abstract class AbstractControl { | |||
this._onDisabledChange.forEach((changeFn) => changeFn(false)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like enable()
needs to be updated with the check as well. Otherwise, you'll have the same problem of resetting dirtiness when you re-enable the control.
expect(c.dirty).toBe(false); | ||
|
||
c.disable(); | ||
expect(a.dirty).toBe(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add the following to this test (as well as the other one)?
c.enable();
expect(a.dirty).toBe(true);
I think this assertion would fail as the code is currently written.
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the |
@kara I finally managed to run Bazel so I'll have a look at this ASAP. I've actually completely forgotten what I did here because it's been 6 months now so I'll need to recall what's going on in this PR. |
@martinsik No worries, sorry for the initial delay. Ping me whenever it's ready and I'll have better turnaround time this time :-) |
… and then called enable() Closes angular#24591
94823e0
to
0437853
Compare
… and then called enable() Closes angular#24591
588243c
to
7ffb45a
Compare
@kara I updated this PR. You were right, it really didn't work after calling I think I messed the history in this PR when I unintentionally referenced this PR id instead of the issue id but it's showing just 3 commits here https://github.com/angular/angular/pull/24591/commits which is correct. |
I don't know why CLA is failing. Maybe because I merged one suggestion as a comit here on GitHub. |
A Googler has manually verified that the CLAs look good. (Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small nit, then should be good to go.
Can you squash your commits together into one? I think the commit in the middle is causing our linter job to fail.
…ntrols Update packages/forms/src/model.ts Co-Authored-By: martinsik <martin.sikora.ahoj@gmail.com>
CLAs look good, thanks! |
@martinsik FYI, I squashed the commits and fixed the nit to move the PR along. If Google internal tests pass, this should be good to go. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…ntrols (angular#24591) Update packages/forms/src/model.ts Co-Authored-By: martinsik <martin.sikora.ahoj@gmail.com> PR Close angular#24591
…ntrols (angular#24591) Update packages/forms/src/model.ts Co-Authored-By: martinsik <martin.sikora.ahoj@gmail.com> PR Close angular#24591
…ntrols (angular#24591) Update packages/forms/src/model.ts Co-Authored-By: martinsik <martin.sikora.ahoj@gmail.com> PR Close angular#24591
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. |
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?
I can manually change
dirty
state of aFormGroup
but when I disable a single control it changesdirty
state of its parent.Demo: https://stackblitz.com/edit/angular-8bab4v?file=src%2Fapp%2Fapp.component.ts
Issue Number: #23309
What is the new behavior?
When calling
disable()
onAbstractControl
it now checks whether its parent isdirty
and if itsdirty
state corresponds to the current state of its children. If not it means I had to change it myself withmarkAsDirty
so I won't override parent'sdirty
state.Does this PR introduce a breaking change?
This could be a BC but it's probably very unlikely that anybody was relying on this behavior since its counter-intuitive.