[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
When the directive associated with a form control is created in the view, validators are triggered.
Validators should not be triggered when the view changes. Reactive forms should not be tied to the way they are represented in the view. Their source of truth should be the model.
https://stackblitz.com/edit/angular-reactive-forms-issue?file=app/app.component.ts
Observe the fact that error message is now gone. Toggling the view is mocking the use-case of having a mulitpart form.
If this is by design, I don't see a reason for it. We're creating a view where we write data form model to view. The action of reading from model should not trigger validators, as far as I understand. As I see it, validators should be run when the FormControl
instances are created in the model. _Why are validators triggered when value did not change?_
Angular version: 4.3.6
Yes sounds right.
A change in the view should not affect the model in reactive forms and no change on the model shouldn't trigger validation.
I've pin point it to https://github.com/angular/angular/blob/17eaef0311990e1a06c028f19bc6c63dcd775f31/packages/forms/src/directives/reactive_directives/form_group_directive.ts#L98-L104
It's always running a new validation run (updateValueAndValidity()
), while it only should do it if there was new validators introduced by the control directive.
Also renaming the function into addControlDirective()
may reduce confusion on what it's doing.
May be somehow related to #14376 has it's both about editing the view on a reactive form and looks like FormGroupDirective
is at fault.
Most helpful comment
Yes sounds right.
A change in the view should not affect the model in reactive forms and no change on the model shouldn't trigger validation.
I've pin point it to https://github.com/angular/angular/blob/17eaef0311990e1a06c028f19bc6c63dcd775f31/packages/forms/src/directives/reactive_directives/form_group_directive.ts#L98-L104
It's always running a new validation run (
updateValueAndValidity()
), while it only should do it if there was new validators introduced by the control directive.Also renaming the function into
addControlDirective()
may reduce confusion on what it's doing.May be somehow related to #14376 has it's both about editing the view on a reactive form and looks like
FormGroupDirective
is at fault.