Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions angucomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ angular.module('angucomplete', [] )

$scope.hideResults = function() {
$scope.hideTimer = $timeout(function() {
// if no object selected, on blur pick the top one from the list

if ($scope.selectedObject == null) {
$scope.selectResult($scope.results[0], true);
}

$scope.showDropdown = false;
}, $scope.pause);
};
Expand Down Expand Up @@ -184,13 +190,13 @@ angular.module('angucomplete', [] )
}
}

$scope.selectResult = function(result) {
$scope.selectResult = function(result, showDropdown) {
if ($scope.matchClass) {
result.title = result.title.toString().replace(/(<([^>]+)>)/ig, '');
}
$scope.searchStr = $scope.lastSearchTerm = result.title;
$scope.selectedObject = result;
$scope.showDropdown = false;
if (typeof showDropdown === 'undefined') { $scope.showDropdown = false; } // optionally keep autocomplete open
$scope.results = [];
//$scope.$apply();
}
Expand Down Expand Up @@ -218,6 +224,9 @@ angular.module('angucomplete', [] )
}

} else if (event.which == 13) {
if ($scope.currentIndex == -1 && $scope.results.length > 0) {
$scope.currentIndex = 0;
}
if ($scope.results && $scope.currentIndex >= 0 && $scope.currentIndex < $scope.results.length) {
$scope.selectResult($scope.results[$scope.currentIndex]);
$scope.$apply();
Expand Down