Skip to content
This repository was archived by the owner on May 21, 2025. It is now read-only.

Commit 7c11490

Browse files
committed
Merge branch 'add-custom-function-support-for-remote-data' of https://github.com/jbuquet/angucomplete-alt into jbuquet-add-custom-function-support-for-remote-data
2 parents 2d2f6a0 + 348726d commit 7c11490

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ var app = angular.module('app', ["angucomplete-alt"]);
9696
| pause | The time to wait (in milliseconds) before searching when the user enters new characters. [example](http://ghiden.github.io/angucomplete-alt/#example1) | No | 400 |
9797
| selected-object | Either an object in your scope or callback function. If you set an object, it will be two-way-bound data as usual. If you set a callback, it gets called when selection is made. [example](http://ghiden.github.io/angucomplete-alt/#example1) | Yes | selectedObject or objectSelectedCallback |
9898
| remote-url | The remote URL to hit to query for results in JSON. angucomplete will automatically append the search string on the end of this, so it must be a GET request. [example](http://ghiden.github.io/angucomplete-alt/#example5) | No | http://myserver.com/api/users/find?searchstr= |
99+
| get-remote-data-function | A function in the controller that would receive the string and some parameters like the timeout promise, and would return a promise with the request for the data | No | - |
99100
| remote-url-data-field | The name of the field in the JSON object returned back that holds the Array of objects to be used for the autocomplete list. [example](http://ghiden.github.io/angucomplete-alt/#example5) | No | results |
100101
| title-field | The name of the field in the JSON objects returned back that should be used for displaying the title in the autocomplete list. Note, if you want to combine fields together, you can comma separate them here (e.g. for a first and last name combined). If you want to access nested field, use dot to connect attributes (e.g. name.first). [example](http://ghiden.github.io/angucomplete-alt/#example1) | Yes | firstName,lastName |
101102
| description-field | The name of the field in the JSON objects returned back that should be used for displaying the description in the autocomplete list. [example](http://ghiden.github.io/angucomplete-alt/#example6) | No | twitterUsername |

angucomplete-alt.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
remoteUrlRequestWithCredentials: '@',
8080
remoteUrlResponseFormatter: '=',
8181
remoteUrlErrorCallback: '=',
82+
getRemoteDataFunction: '=',
8283
id: '@',
8384
type: '@',
8485
placeholder: '@',
@@ -448,6 +449,17 @@
448449
.error(httpErrorCallback);
449450
}
450451

452+
function getResourceResults(str) {
453+
cancelHttpRequest();
454+
455+
httpCanceller = $q.defer();
456+
var params = { timeout: httpCanceller.promise };
457+
458+
scope.getRemoteDataFunction(str, params).$promise
459+
.then(httpSuccessCallbackGen(str))
460+
.catch(httpErrorCallback);
461+
}
462+
451463
function clearResults() {
452464
scope.showDropdown = false;
453465
scope.results = [];
@@ -503,7 +515,9 @@
503515
getLocalResults(str);
504516
});
505517
}
506-
else {
518+
else if (scope.getRemoteDataFunction) {
519+
getResourceResults(str);
520+
} else {
507521
getRemoteResults(str);
508522
}
509523
}

0 commit comments

Comments
 (0)