Chip autocomplete doesn't support showing error colour and message
Reproduction
https://stackblitz.com/edit/angular-n6tpca?file=app/chips-autocomplete-example.ts
Steps to reproduce:
- select a fruit, and then remove it. The boolean display TRUE (invalid) all the time because we set the input formControl to null. The input is invalid, but the invalid class is not projected to the mat-form-field.
Expected Behavior
When removing all chips, I expect to see a red border and red label, and the mat-error tag should display.
Actual Behavior
No error behaviour is displayed.
It could be that this is happening since the input tag is nested in the mat-chip-list, and can't find the parent element to apply the styles to.
Manually adding ng-invalid && mat-form-field-invalid via the ngClass directive does work.
Environment
- Angular: 8,0.2
- CDK/Material:8.01
- Browser(s): Chrome
- Operating System (e.g. Windows, macOS, Ubuntu): MacOS Mojave
the two solutions that I've seen are:
In the first one you have to manage the chip state by yourself
@ViewChild('chipList') chipList;
this.chipList.errorState = true;
In the second one you have to set the directive formControlName to both chip list and input:
<mat-chip-list formControlName='newFruit'>
<input formControlName='newFruit'>
The second one works well.
Thanks, I will have a look at those solutions.
some news? i'm having same problem here in my component based on mat-chip-list
Update? <mat-error> would be nice to use
Any updates?
I think the [formControl] is just on the wrong element here, it should be on the chip list not the input https://stackblitz.com/edit/angular-n6tpca-yuxxza?file=app/chips-autocomplete-example.html
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.