Apologies all for what is probably something I should be able to work out for myself rather than bothering you guys with, in fact I'm fairly certain it is - my (poor) understanding of the docs leads me to believe this is probably trivial, but I am very new to this, under a fair amount of pressure, and for all my staring at it I just cannot connect the dots....
Basically I have the following simple ajax based select2 input field working :
$(document).ready(function () {
var allUsersUrl = '/cmd/match_list/usrname';
$('#username').select2({
placeholder: 'Enter username',
minimumInputLength: 3,
allowClear: true,
ajax: {
quietMillis: 150,
url: allUsersUrl,
dataType: 'json',
data: function (term, page) {
return {
string: term,
};
},
results: function (data, page) {
return { results: data.Results };
}
}
});
}
.
.
.
<input type="hidden" id="username" name="username">...but since this involves a relatively slow and expensive back end LDAP query, I would like any subsequent key presses received after the first LDAP lookup to search the initial results, instead of firing off another brand new (but very similar) back end lookup.
For example, when I type 'smi' in the field, a shortlist of 52 matches is shown. When I then press 't' I want to look for 'smit' in the shortlist, and not do another back end lookup as currently happens.
The documentation talks about a 'context' parameter that sounds very relevant to my problem, but I just cant seem to get my head around it enough to make anything work, and so far I have failed to find any examples of other people doing something similar.
Any suggestions will be gratefully received, and apologies again if this doesnt belong in this forum. Thanks in advance.