Components: How do you clear an autocomplete manually?

Created on 3 Nov 2017  路  6Comments  路  Source: angular/components

Bug, feature request, or proposal:

Bug

What is the current behavior?

Actually have the same problem which is reproduced in this example
https://stackblitz.com/edit/angular-material2-issue-v5gpri?file=app%2Ftag.component.html
I using an autocomplete chips component. Try to put some letter in input and select one of the values. Note that input not clearing. I trying to reset this value manually and nothing helps.

2017-11-03 16 51 01

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Chrome, MacOS Sierra 10.12.6
Angular ^4.4.6
@angular/material ^2.0.0-beta.12

P4 materiaautocomplete

Most helpful comment

I'm not sure why this would be set to such a low priority. Through this bug, you cannot combine chip input with autocompletes :/

All 6 comments

I'm not sure why this would be set to such a low priority. Through this bug, you cannot combine chip input with autocompletes :/

Edit: never mind. After a bit of testing I realized the obvious problem that although the input field is blanked, the autocomplete doesn't know about it and is still filtering on the old value.

@We-St You can work around the issue by changing:
(optionSelected)="add($event)"
To:
(optionSelected)="add($event); chipInput.value = ''"

After a bit of playing around I was able to get it working, however there does appear to be an issue where the formControl setValue is not updating the value displayed in the control:
https://stackblitz.com/edit/angular-material2-issue-wmgcaj

I was able to work around this by using both formControl.setVaue and input.value so both view and model were in sync.

Faced the same problem. After little investigation of source code, found that MatAutocompleteTrigger saves previous value.
Setting empty value and dispatching "input" event worked for me:

input.value = '';
input.dispatchEvent(new Event('input', {
      'bubbles': true,
      'cancelable': true,
    }));

Revisiting old bugs- I think this one is obsolete. We have an example of this in our docs: https://material.angular.io/components/chips/examples#chips-autocomplete

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

savaryt picture savaryt  路  3Comments

kara picture kara  路  3Comments

Miiekeee picture Miiekeee  路  3Comments

jelbourn picture jelbourn  路  3Comments

constantinlucian picture constantinlucian  路  3Comments