You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
md-select errors still displayed even after resetting formGroup #7522
After submitting the form and resetting it, the intuitive thing is to clear md-select from all sort of errors; Is there a good approach to achieve this ?
After you reset the form, that is what happens. You are asking that by resetting your FormGroup, the FormGroupDirective is also reset. FormGroup and FormGroupDirective aren't coupled in that way due to whatever design decisions were made in @angular/forms.
Submitted state is based on the FormGroupDirective or the NgForm (depending on if you're using template- or model-driven forms). FormGroup does not hold submitted state.
If you wish to reset the form, you must gain access to the FormGroupDirective or the NgForm and call resetForm() on it. That will remove .mat-input-invalid from the input and all associated md-errors
This behavior is in Angular core, not material. You are welcome to propose a change to the behavior, but that should be done in the angular core repository, not here.
I think there is a misunderstanding, i understand that in order to remove all errors after submission we need to gain access to FormGroupDirective or the NgForm and call resetForm() on it, but the problem is that just remove .mat-input-invalid from all inputs and not .mat-select.invalid from all selects components !
So my question is how to remove also all .mat-select.invalid from all selects components ?
Thank you very much and i'm sorry if i'm not getting something right.
And here's some additional clarification, if it helps:
By default, Material shows the invalid styling when the control isInvalid && (isTouched || isSubmitted). This strategy is recommended by the spec. If you want to customize how and when controls show invalid styling, you can use a custom error matcher (the api does have a minor breaking change coming in beta.12).
Activity
willshowell commentedon Oct 4, 2017
I think this is expected behavior, per #4190.
ChakrounAnas commentedon Oct 4, 2017
After submitting the form and resetting it, the intuitive thing is to clear md-select from all sort of errors; Is there a good approach to achieve this ?
Thank you very much.
willshowell commentedon Oct 4, 2017
After you reset the form, that is what happens. You are asking that by resetting your
FormGroup, theFormGroupDirectiveis also reset.FormGroupandFormGroupDirectivearen't coupled in that way due to whatever design decisions were made in@angular/forms.--
#4190 (comment) pretty much covers it:
ChakrounAnas commentedon Oct 5, 2017
I think there is a misunderstanding, i understand that in order to remove all errors after submission we need to gain access to FormGroupDirective or the NgForm and call resetForm() on it, but the problem is that just remove .mat-input-invalid from all inputs and not .mat-select.invalid from all selects components !
So my question is how to remove also all .mat-select.invalid from all selects components ?
Thank you very much and i'm sorry if i'm not getting something right.
willshowell commentedon Oct 5, 2017
I'm still not sure I understand 😄 . Here's an example of this approach clearing the invalid styles for inputs and selects:
https://stackblitz.com/edit/material2-beta11-8ylcrf?file=app%2Fapp.component.ts
And here's some additional clarification, if it helps:
By default, Material shows the invalid styling when the control
isInvalid && (isTouched || isSubmitted). This strategy is recommended by the spec. If you want to customize how and when controls show invalid styling, you can use a custom error matcher (the api does have a minor breaking change coming in beta.12).mmalerba commentedon Nov 21, 2017
This is working as intended. As @willshowell mentioned, you can use a custom error state matcher to change when errors are shown
angular-automatic-lock-bot commentedon Sep 7, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.