material icon indicating copy to clipboard operation
material copied to clipboard

[md-autocomplete] Unable to reset the input

Open jgoux opened this issue 11 years ago • 18 comments

Hi, on the master, I'm unable to reset the selected input from md-autocomplete by setting the model to null Here is the demo : http://codepen.io/jgx/pen/XbMmxE

jgoux avatar Jun 02 '15 12:06 jgoux

Well, you need to set the md-search-text variable to null as well. See the modified demo: http://codepen.io/anon/pen/oXZmVG

CxRes avatar Jun 04 '15 18:06 CxRes

@CxRes this works but if you have set md-min-length="0" it will open the popup again.

Anyways I think the desired behavior should be the same way as with md-select by just setting the selected item to null.

stefan-schweiger avatar Jul 14 '15 15:07 stefan-schweiger

This is as designed and would require you to set both the searchText and the selectedItem. I believe resetting just searchText would also clear selectedItem.

robertmesserle avatar Jul 20 '15 21:07 robertmesserle

@robertmesserle

why don't we have both?

it would be more in line with md-select as you also just set the ng-model to null (and in the context of autocomplete selectedItem is the model in my opinion)

btw setting searchText to null actually results in an exception, setting it to '' works as far as I can tell in a codepen with the current master (but I had problems with a master from last week, so I will recheck this tomorrow at my actual project)

stefan-schweiger avatar Jul 20 '15 22:07 stefan-schweiger

@stefan-schweiger The problem is that we have two models that we need to track for Autocomplete. An empty searchText always means that there is no selectedItem, but the opposite is not always true. (ie. while typing in your query, searchText has a value, but you haven't yet selected an item.)

robertmesserle avatar Jul 20 '15 22:07 robertmesserle

@robertmesserle ok I see. Also now I remember what the problem was, when you have set md-min-length="0" the popup comes back open when you set md-search-text to '' and as it has no focus it behaves kind of weird.

http://codepen.io/anon/pen/waEzgv

What's even worse in my case is that I hide the md-autocomplete after selection to display the item, when you clear it again you have the popup in the upper left corner nowhere near the md-autocomplete.

stefan-schweiger avatar Jul 21 '15 08:07 stefan-schweiger

The same here, I understand that autocomplete can have no model value but searchText has it. Just need that popup dont back open.

tolemac avatar Jul 23 '15 09:07 tolemac

As a workaround, you can disable the md-autocomplete before resetting and enable it again afterwards, which is stupid as hell, but at least it works...

stefan-schweiger avatar Jul 23 '15 09:07 stefan-schweiger

It looks like if we go by triggering the dom element it works.

plunker here

techno2mahi avatar Aug 25 '16 08:08 techno2mahi

Actually this should be fixed within v1.1.0 with commit https://github.com/angular/material/commit/dadbcf21ff95764ddcc678a0821e1fa02beaf12d.

devversion avatar Aug 25 '16 09:08 devversion

Hi..having a problem with md-autocomplete.

  1. when item is searched and selected. After the selection, it is not closing the dropdown.
  2. when you clear the text after written something in input field, there is a empty dropdown. empty_dropdown

asirigada avatar Sep 28 '16 21:09 asirigada

I'm having the same issue as @asirigada - when an item is selected, the completion suggest does not close. Any ideas, folks?

johndshea avatar Oct 12 '16 19:10 johndshea

add ng-hide class in your css.. ng-hide{ display: none; }

asirigada avatar Oct 12 '16 19:10 asirigada

Hope that works. It worked for me

asirigada avatar Oct 12 '16 19:10 asirigada

Edit: this worked -

.ng-hide { display: none; }

I wonder whether the issue has to do with the fact that I'm working on a chrome extension.

Thanks, @asirigada

johndshea avatar Oct 12 '16 19:10 johndshea

I m also working on extensions... After adding the class it works..!!

asirigada avatar Oct 12 '16 19:10 asirigada

This appears to be a broader issue with angular-material and chrome extensions. Ng-show doesn't work at all in chrome extensions in my experience. Adding the .ng-hide class to your CSS appears to fix that issue as well.

johndshea avatar Oct 12 '16 19:10 johndshea

Yes angular-material and chrome extensions has lots of issues to solve. No working with md-virtual-repeat too. when tabs are shown, md-virtual is hidden in the dialog content.

asirigada avatar Oct 12 '16 19:10 asirigada