I was looking the following example scottgonzalez / jquery-ui-extensions
I need to customise the source callback
, which expects two argumnets request
and response
for the autocomplete.
My question is the following: how can I pass an extra parameter to the source callback in order to filter the data according a variable defined in autocomplete? Example:
currentUser = false -> I need to exclude the currentUser from the source.
Here is my code (1) (2).
Please see the comment to understand better what I am asking.
Thanks.
(1)
// autocomplte.js
define([
'jquery',
'matcher'
], function ($, matcher) {
"use strict";
var autoComplete = function (element, options) {
console.log(options); // {isCurrentUser: true}
element.autocomplete({
minLength: 3,
autoFocus: true,
source: matcher // this is a callback defined
// in matcher.js
});
// other codes;
}
});
(2)
// matcher.js
define([
'jquery',
'users',
'jqueryUi'
], function ($, UserCollection) {
"use strict";
var userCollection,
matcher;
matcher = function (request, response, options) { // how can I pass
// an extra parameter
// to this callback?
console.log(options); // undefined it should be {isCurrentUser: true}
userCollection = new UserCollection();
var regExp = new RegExp($.ui.autocomplete.escapeRegex(request.term), 'i');
response(userCollection.filter(function (data) {
return regExp.test(data.get('first_name'));
}));
};
return matcher;
});