material icon indicating copy to clipboard operation
material copied to clipboard

Autocomplete: Unable to select item with either 'return' or mouse

Open ericodes opened this issue 11 years ago • 11 comments

md-autocomplete select error

When I type in 'san d' , a list of cities drops down. Whether I click on a result with my mouse, or use the arrow keys and 'return' keyboard key to select an item, the selected text is not updated and stays at 'san d'.

I tried to follow the model in the demo (https://material.angularjs.org/#/demo/material.components.autocomplete) as closely as possible, but can't get it to select as it does in the demo.

My code <md-autocomplete md-selected-item="selectedItem" md-search-text="searchText" md-items="item in cityLookup(searchText)" md-item-text="item.display"> <span md-highlight-text="searchText">{{item}}</span> </md-autocomplete>

and cityLookup returns a list of cities cityLookup = function (query) { var This = this; if (query && query.length > 2) { var url = "/api/location/city?q=" + query; return This._http.get(url).then(function(response){ return response.data; }); } };

Everyone's help is much appreciated, and please let me know what other details I can give to resolve this :)

ericodes avatar Feb 23 '15 18:02 ericodes

I looked at semi-related issue #1527 , but am still perplexed as to why neither the 'return' nor mouse click is updating what's selected.

ericodes avatar Feb 23 '15 18:02 ericodes

What is the exact json you get back. Maybe md-item-text is the culprit

david-gang avatar Feb 23 '15 20:02 david-gang

I updated to 0.8.0-rc1-master-71b17ba few minutes ago and I have same error. It's not related with any custom callback.

kdela avatar Feb 23 '15 20:02 kdela

Are there any errors being logged to the console?

robertmesserle avatar Feb 23 '15 21:02 robertmesserle

Hi everyone! This is the first issue I've ever opened, so it's cool getting some feedback!

So there was a 2 part fix :)

First, I used <script src="https://rawgit.com/angular/bower-material/master/angular-material.js"></script> instead of <script src="https://rawgit.com/angular/bower-material/v0.8.0-rc1/angular-material.js"></script>

  • I realized something was up after I copy and pasted the exact code from the Material Design demo, and still wasn't able to select an item with either 'return' or mouse click. I don't think the fix described in #1527 has been released yet, so using the RawGit above, I was able to use the latest, most-current build version. (But this also makes me wonder, how are other people using the autocomplete in version 0.8.0?)

And second, good eye @david-gang. The objects in the array I was returning didn't have a 'display' property, (which the Angular demo had). So I changed md-item-text="item.display" to md-item-text="item" and now it works great. So that was my beginner's mistake :)

Hope this is helpful! Devil's in the details

ericodes avatar Feb 23 '15 21:02 ericodes

@robertmesserle There is no logs in console. It does work on 0.7.1-master-ffa11c7.

@ericodes FYI this ticket should definitely stay open :)

kdela avatar Feb 24 '15 19:02 kdela

@kdela :) there we go

ericodes avatar Feb 24 '15 20:02 ericodes

@kdela

May you please provide a plunkr for this issue?

david-gang avatar Feb 25 '15 05:02 david-gang

@david-gang Of course. I'll do that little later.

kdela avatar Feb 25 '15 10:02 kdela

Possibly related: if you click and hold on a list item, something similar to this happens. The list disappears and the option you had selected / were selecting will not be placed in the input.

Looks like a blur event fires, and the click event never does.

mckenzielong avatar Feb 25 '15 22:02 mckenzielong

@kdela Closing until there is a Plunker or CodePen to demonstrate. Cannot recreate.

robertmesserle avatar Feb 26 '15 19:02 robertmesserle