Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

error on typeahead #2999

Closed
Tallyb opened this issue Nov 19, 2014 · 6 comments
Closed

error on typeahead #2999

Tallyb opened this issue Nov 19, 2014 · 6 comments

Comments

@Tallyb
Copy link

Tallyb commented Nov 19, 2014

in the last line (in getMatchesAsync):
var onCurrentRequest = (inputValue === modelCtrl.$viewValue);
if (onCurrentRequest && hasFocus) {
if (matches.length > 0) {
an error is thrown that matches.length is not defined.
on the next attempt - it works ok.

@Tallyb
Copy link
Author

Tallyb commented Nov 20, 2014

http://plnkr.co/edit/4hC1F6dKfGS3rRXqLtiN?p=preview
ui bootstrap version is 0.12. The plunker uses angular 1.2.x, in my code I use .1.3.3 (happens the same)
In addition restangular and lodash are used (versions in plunker).
start typing "aa" in the input box, and check the console (only happens on the first time.
fix is either defining $scope.matches or checking if $scope.matches is undefined.
Please let me know if anyting else is required.

@unkleara
Copy link
Contributor

I had this error as well using another library to help with with fuzzy search. I needed to make a copy of the array from the response and have the other library work on new array and return those values to typeahead. The typeahead function that checks $viewValue isn't dealing with the original array after a certain point, so "matches" becomes undefined and if the results are empty it can't reference the original array to check the length property.

A quick fix was to just check if matches are defined and then the length.

if (matches && matches.length > 0) 

Following is where I made the change in case it will help someone in the future.
https://github.com/angular-ui/bootstrap/blob/master/src/typeahead/typeahead.js#L134

@antoinepairet
Copy link

It does not happen every time. I have the feeling there is a issue of timing. Using your plunkr, if I quickly use the typeahead the error will show up. If I wait long enough, the error will not happen.

That being said, the fix seems obvious and harmless. thanks @unkleara

unkleara added a commit to unkleara/bootstrap that referenced this issue Jan 12, 2015
@chrisirhc chrisirhc modified the milestones: 0.13.0, Purgatory Mar 23, 2015
@karianna karianna removed the PRs plz! label Mar 23, 2015
ayakovlevgh pushed a commit to ayakovlevgh/bootstrap that referenced this issue Mar 24, 2015
- resolves property length of undefined error by checking value first angular-ui#2999

Fixes angular-ui#2999
Closes angular-ui#3178
@rkriitr
Copy link

rkriitr commented Mar 29, 2015

if (matches && matches.length > 0) prevents the undefined error, but first time, the matched dropdown does not show up anyway. Please tell me what needs to be done. As above indicated, from second time onwards, everything works fine.

@rkriitr
Copy link

rkriitr commented Mar 29, 2015

sorry, in the code

                   <input ng-model="brandChainName"
        typeahead="name for name in brandChainNames | filter:$viewValue | limitTo:8"
        typeahead-template-url="columnTwo.html" >

brandChainNames was not intialized. Now it is working. It is not a bug in bootstrap, it is bug on the coder's part.

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

No branches or pull requests

7 participants