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

Commit

Permalink
fix(typeahead): resolve property length of undefined error
Browse files Browse the repository at this point in the history
- resolves property length of undefined error by checking value first #2999

Fixes #2999
Closes #3178
  • Loading branch information
unkleara authored and chrisirhc committed Mar 23, 2015
1 parent 36e6363 commit 950c22c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/typeahead/test/typeahead.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,15 @@ describe('typeahead tests', function () {
expect(element).toBeClosed();
});

it('PR #3178, resolves #2999 - should not return property "length" of undefined for undefined matches', function () {
changeInputValueTo(element, 'c');
expect(element).toBeClosed();

deferred.resolve();
$scope.$digest();
expect(element).toBeClosed();
});

});

describe('non-regressions tests', function () {
Expand Down Expand Up @@ -777,7 +786,7 @@ describe('typeahead tests', function () {
};
var element = prepareInputEl('<div><input ng-model="result" ng-keydown="keyDownEvent = $event" typeahead="item for item in source | filter:$viewValue" typeahead-on-select="onSelect($item, $model, $label)" typeahead-focus-first="false"></div>');
changeInputValueTo(element, 'b');

// enter key should not be captured when nothing is focused
triggerKeyDown(element, 13);
expect($scope.keyDownEvent.isDefaultPrevented()).toBeFalsy();
Expand Down
4 changes: 2 additions & 2 deletions src/typeahead/typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap
//but we are interested only in responses that correspond to the current view value
var onCurrentRequest = (inputValue === modelCtrl.$viewValue);
if (onCurrentRequest && hasFocus) {
if (matches.length > 0) {
if (matches && matches.length > 0) {

scope.activeIdx = focusFirst ? 0 : -1;
scope.matches.length = 0;
Expand Down Expand Up @@ -172,7 +172,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap
//we need to propagate user's query so we can higlight matches
scope.query = undefined;

//Declare the timeout promise var outside the function scope so that stacked calls can be cancelled later
//Declare the timeout promise var outside the function scope so that stacked calls can be cancelled later
var timeoutPromise;

var scheduleSearchWithTimeout = function(inputValue) {
Expand Down

0 comments on commit 950c22c

Please sign in to comment.