components icon indicating copy to clipboard operation
components copied to clipboard

Chip autocomplete doesn't support showing error colour and message

Open mattiLeBlanc opened this issue 7 years ago • 7 comments

Reproduction

https://stackblitz.com/edit/angular-n6tpca?file=app/chips-autocomplete-example.ts

Steps to reproduce:

  1. 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

mattiLeBlanc avatar Jun 26 '19 13:06 mattiLeBlanc

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.

leandro-hl avatar Sep 26 '19 20:09 leandro-hl

Thanks, I will have a look at those solutions.

mattiLeBlanc avatar Sep 28 '19 11:09 mattiLeBlanc

some news? i'm having same problem here in my component based on mat-chip-list

jl91 avatar Oct 25 '19 21:10 jl91

Update? <mat-error> would be nice to use

y3rt avatar Dec 05 '19 19:12 y3rt

Any updates?

HoplaGeiss avatar Jan 30 '20 07:01 HoplaGeiss

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

mmalerba avatar May 29 '20 21:05 mmalerba

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.