-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
bug(matInput): Form field doesn't update asterisk after the form was reassigned #29066
Comments
This is likely an issue with the forms module since we read the required state from the control here: https://github.com/angular/components/blob/main/src/material/input/input.ts#L178. I'm transferring the issue to the main repo. |
I suspect this is an Per components/src/material/form-field/form-field.ts Lines 410 to 414 in c40cb80
markForCheck occurs on state changes, but swapping out the control entirely supposedly doesn't cause the same.
|
Ah you're right, triggering the change detection eventually makes it catch up. Transferring this back. |
gets reassigned fixes the issue we were not marking component for changes when form is reassigned making it not update UI for required asterisk fixes angular#29066
gets reassigned fixes the issue we were not marking component for changes when form is reassigned making it not update UI for required asterisk fixes angular#29066
gets reassigned fixes the issue we were not marking component for changes when form is reassigned making it not update UI for required asterisk fixes angular#29066
gets reassigned fixes the issue we were not marking component for changes when form is reassigned making it not update UI for required asterisk fixes angular#29066
gets reassigned fixes the issue we were not marking component for changes when form is reassigned making it not update UI for required asterisk fixes angular#29066
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:
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
The text was updated successfully, but these errors were encountered: