Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Programmatically setting md-search-text in md-autocomplete opens dropdown #2767

Closed
PritishC opened this issue May 7, 2015 · 3 comments
Closed
Assignees
Milestone

Comments

@PritishC
Copy link

PritishC commented May 7, 2015

Hi there!

I came across this quirk in md-autocomplete, with the following steps -:

  1. I bind md-search-text programmatically, say 'Steve'.
  2. I bind md-selected-item programmatically to a hash, say {name: 'Steve', id: 2} (not necessary for quirk reproduction - I need it for my own purposes).

Now the clincher is that there are multiple results corresponding to 'Steve' (different people with the same first name?), and this causes the dropdown list to open up. I don't need the dropdown list to open up at this point - I've already made the right selection. Is there a way to prevent the opening of the dropdown if I'm making the selection programmatically?

On the other hand, if there aren't multiple results, md-autocomplete still tries to fire a search. This, again, isn't really needed as I've already made the right selection.

Example CodePen which demonstrates the issue (line 15 in JS).

@Londovir
Copy link

Londovir commented May 7, 2015

I believe this is similar to an issue I opened yesterday (#2756), which I encountered more specifically when modifying the md-search-text bound scope variable when md-min-length is set to 0.

The behavior is being caused by the $watch on searchText (at least for some of your issue, as well as mine). This triggers a call to handleSearchText, which among other things may cause a call to handleQuery (assuming the minimum length is met). handleQuery cascades over to fetchResults, which actually retrieves any matches to the searchText ("mi" in your example), which ultimately results in the call to shouldHide, which determines if the dropdown should be hidden.

The problem, I think, is that currently shouldHide is merely a check to see if the searchText field has met or exceeded the minimum length needed to open a dropdown (md-min-length if set, or 1 otherwise). It does not bother to check whether or not the element has the focus, which semantically I think would make more sense to me. That check seems to make sense if it were put into shouldHide.

@PritishC
Copy link
Author

PritishC commented May 7, 2015

+1, I agree that the shouldHide method ought to check for whether the control has focus as well.

Setting the value programmatically would not bring focus on the control, thus keeping the dropdown hidden.

@robertmesserle
Copy link
Contributor

This is a duplicate of #2756

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants