-
Notifications
You must be signed in to change notification settings - Fork 25.9k
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
feat(forms): add markAllAsDirty to AbstractControl #58663
base: main
Are you sure you want to change the base?
Conversation
Adds the `markAllAsDirty` method to the `AbstractControl` class. This method will mark the control and all its descendants as dirty. I pretty much just duplicated the behaviour and tests of `markAllAsTouched`. Fixes angular#55990
250f823
to
587a1c8
Compare
@AndrewKushnir just checking if this requires any action from me? |
|
||
expect(innerFormArrayGroupControl1.dirty).toBe(false); | ||
|
||
formArray.markAllAsDirty(); |
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 tests that also cover emitEvent
? (and checking the events are emitted)
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.
I've added a basic test which I grabbed from elsewhere for inspiration. I also did the same for markAllAsTouched
which is what I got inspiration from for the other tests.
|
||
expect(group1.dirty).toBe(false); | ||
|
||
const group1Control1 = group1.get('c1') as FormControl; |
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.
This question may be bigger than this PR's scope:
I see that the old fashioned .get('...') as FormXXX
conventions come from existing tests. But I wonder: is there any reason for this now other than consistency? I would think they could be properly typed now by just accessing the now default typing. Either just for these new tests now, or perhaps someone take a more formal sweep through form tests in a separate PR.
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.
Tbh I just followed what was in the tests for markAllAsTouched
. This is my first contribution to angular so I'm not sure how else to do things, but happy to adjust if this is deemed within the scope of my contribution.
Deployed adev-preview for 587a1c8 to: https://ng-dev-previews-fw--pr-angular-angular-58663-adev-prev-qaaol9d0.web.app Note: As new commits are pushed to this pull request, this link is updated after the preview is rebuilt. |
Co-authored-by: michael-small <[email protected]>
0f78d85
to
6ce833f
Compare
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
@@ -141,6 +221,12 @@ import {StatusChangeEvent} from '../src/model/abstract_model'; | |||
|
|||
expect(arrayFirstChildGroupFirstChildCtrl.touched).toBe(true); | |||
}); | |||
|
|||
it('should not emit events when `FormGroup.markAllAsTouched` is called with `emitEvent: 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.
Thanks for adding this test.
Consider also adding a test that verifies that event is emitted for true and not having a value.
* When false, no events are emitted. | ||
*/ | ||
markAllAsDirty(opts: {emitEvent?: boolean} = {}): void { | ||
this.markAsDirty({onlySelf: true, emitEvent: opts.emitEvent, sourceControl: this}); |
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.
I'm wondering why onlySelf is not being passed as a prop to cover the case where we want to mark descendants but not ascendance?
I assume this is just something you copypasted from markAllAsTouched
, but curious if you have any context for this.
expect(arrayFirstChildGroupFirstChildCtrl.dirty).toBe(true); | ||
}); | ||
|
||
it('should not emit events when `FormGroup.markAllAsDirty` is called with `emitEvent: 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.
Please add a test that verifies that event is emitted for true and not having a value.
* | ||
* @param opts Configuration options that determine how the control propagates changes | ||
* and emits events after marking is applied. | ||
* * `emitEvent`: When true or not supplied (the default), the `events` |
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.
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.
undefined
is !== false
.
I think we're good here !
@kirjs thanks for the review. I'm not sure how to proceed on this, given that the PR seems to have the necessary approvals, but there are also change requests. I also want to point out that the requested changes seem to be beyond the scope of my addition - given that they are addressing feedback on tests that were already there. If it helps get this merged, I can put more time and effort in, but I doubt I am the best suited to put that effort in (I'm a first-time contributor, and just trying to add a very small change). |
@AndrewKushnir @kirjs @michael-small can you let me know if this needs any action from me or whether we can proceed as is? |
I'm just a random community guy who keeps up with forms PRs. I think these changes are legit. My comments were just thinking out loud to real maintainers about the existing tests beyond the scope of your PR. Looks good to me for what it's worth |
Pullapprove is reporting that we miss 2 public-api scope approvals. |
Adds the
markAllAsDirty
method to theAbstractControl
class. This method will mark the control and all its descendants as dirty.I pretty much just duplicated the behaviour and tests of
markAllAsTouched
.Fixes #55990
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: #55990
What is the new behavior?
Adding
markAllAsDirty
toAbstractControl
Does this PR introduce a breaking change?
Other information
N/A