Skip to content
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

fix(material/form-field): trigger CD when form gets reassigned #30395

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

naaajii
Copy link
Contributor

@naaajii naaajii commented Jan 27, 2025

fixes the issue we were not marking component for changes when form is reassigned making it not update UI for required asterisk

fixes #29066

@naaajii naaajii requested a review from a team as a code owner January 27, 2025 12:48
@naaajii naaajii requested review from crisbeto and wagnermaciel and removed request for a team January 27, 2025 12:48
@@ -378,6 +378,8 @@ export class MatFormField
this._initializeControl(this._previousControl);
this._previousControl = this._control;
}

this._changeDetectorRef.markForCheck();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move this inside the above if block? we should only need to do it if the control actually changed

Copy link
Contributor Author

@naaajii naaajii Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this broke something and I can't debug this right now cause running input tests makes this laptop go brrrr. I will get back to this later. I'm sorry for delay!

although it shouldn't have broke anything.

I think it never goes into the if statement above when form is getting reassigned.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this if statement is for where component is getting replaced for altogether for new one such as if form-field was being used with input and then was replaced with a select. I have added a comment for that statement. #29573 added this for #29402.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I guess the above if-block was unrelated then, but this still feels like its marking for check far too often. I'm a little bit worried that this could have negative performance implications.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have switched the login to check if the validator on the control has changed or not. I couldn't get my head around this any other way as NgOnChange didn't include formControl and equal checks on control doesn't return true either. I'm open to suggestions for improvements.

Copy link
Contributor

@mmalerba mmalerba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops, I was too trigger happy with the approve before I noticed the test was still failing

@motka
Copy link

motka commented Feb 5, 2025

no more working

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug(matInput): Form field doesn't update asterisk after the form was reassigned
3 participants