Description
Is this a regression?
No idea
Description
Form field doesn't update the visual state (asterisk) based on validators (unless you touch it or call markAsTouched()
) after the form property is reassigned with a fresh form.
It's even worse when the field has a value: asterisk isn't updated even after calling markAsTouched()
, you have to manually touch the field in order for the asterisk to update.
Reproduction
StackBlitz link: https://stackblitz.com/edit/components-issue-q9ufsm
Steps to reproduce:
- Click on the "toggle" button a few times. Notice that asterisk toggles along with the validators updates.
- Click on the "reassign" button.
- Click on the "toggle" button a few times again. Notice that the field doesn't reflect validators updates.
- Touch the field or click "mark as touched" button. Notice that the state of the field is now correct.
- Enter something in the field.
- Click on the "toggle" button a few times again. Notice that asterisk is not visible even after clicking "mark as touched".
- Click into the field. Notice that the state of the field is now correct.
Expected Behavior
Asterisk visibility should correspond to the presence of Validators.required.
Actual Behavior
Asterisk isn't updated if the field is untouched and the form was reassigned.
Environment
Angular CLI: 17.3.3
Node: 20.10.0
Package Manager: yarn 1.22.19
OS: win32 x64
Angular: 17.3.3
... animations, cdk, cli, common, compiler, compiler-cli, core
... forms, language-service, material, material-moment-adapter
... platform-browser, platform-browser-dynamic, platform-server
... router, service-worker
Package Version
@angular-devkit/architect 0.1703.3
@angular-devkit/build-angular 17.3.3
@angular-devkit/core 17.3.3
@angular-devkit/schematics 17.3.3
@angular/fire 17.0.1
@schematics/angular 17.3.3
rxjs 7.8.1
typescript 5.4.4
webpack 5.91.0
zone.js 0.14.4