refactor(forms): make markAsTouched() touch all descendants by default#67453
refactor(forms): make markAsTouched() touch all descendants by default#67453leonsenft wants to merge 2 commits intoangular:mainfrom
markAsTouched() touch all descendants by default#67453Conversation
`markAsTouched()` now marks all descendants as touched. In general this
method is called when controls update the model. Most controls update
leaf nodes, in which case this change has no effect.
Marking all descendants allows triggering validation for subsections of
a form, independently from having to call `submit()` on the entire form.
`markAsTouched()` now accepts a `MarkAsTouchedOptions` parameter, which
includes a `self` property. This can be used mark only the receiving
field as touched: `node.markAsTouched({self: true})`.
| * If `true`, only marks the current field as touched. | ||
| * If `false` or not provided, marks the field and all its descendants as touched. | ||
| */ | ||
| self?: boolean; |
There was a problem hiding this comment.
Yeah that's probably better. I could seemarkAsTouched({self: false}) being confusing. Does it mean descendants and not self? onlySelf is much more clear in that regard.
However, I noticed Reactive Forms uses onlySelf, but regarding whether ancestors (rather than descendants) are included. Do we mind the potential confusion, or would a name that indicates the inclusion/omission of descendants be more clear? For example markAsTouched({includeDescendants: false})
There was a problem hiding this comment.
The alternative I'm thinking of skipDescendants:true (not a huge fan of negative flags).
There was a problem hiding this comment.
AbstractControl.markAsTouched(opts?: {onlySelf: boolean}), so skipDescendants: true would be precedence, but since signal forms is a new ap, maybe that's ok?
There was a problem hiding this comment.
while at it, maybe give the same treatment to markAsDirty in one go, as it also has this option in AbstractControl?
markAsTouched()now marks all descendants as touched. In general this method is called when controls update the model. Most controls update leaf nodes, in which case this change has no effect.Marking all descendants allows triggering validation for subsections of a form, independently from having to call
submit()on the entire form.markAsTouched()now accepts aMarkAsTouchedOptionsparameter, which includes aselfproperty. This can be used mark only the receiving field as touched:node.markAsTouched({self: true}).