Is it possible with jQuery Auto-plete, to make it so that if there are 'source:' values available, but they don't match what you are typing, then just show all the sources at once?
IE, given the following code, if I type in "pineapple", how do you show all the programming languages instead of none of them?
<script>
$(function() {
var availableTags = [
"JavaScript",
"Perl",
"PHP",
"Python",
"Ruby"
];
$( "#tags" ).autoplete({
source: availableTags
});
});
</script>
<input type="text" id="tags" />
Is it possible with jQuery Auto-plete, to make it so that if there are 'source:' values available, but they don't match what you are typing, then just show all the sources at once?
IE, given the following code, if I type in "pineapple", how do you show all the programming languages instead of none of them?
<script>
$(function() {
var availableTags = [
"JavaScript",
"Perl",
"PHP",
"Python",
"Ruby"
];
$( "#tags" ).autoplete({
source: availableTags
});
});
</script>
<input type="text" id="tags" />
Share
Improve this question
edited Dec 4, 2012 at 20:11
Salman Arshad
273k84 gold badges444 silver badges534 bronze badges
asked Dec 4, 2012 at 19:21
TheFrackTheFrack
2,8738 gold badges29 silver badges49 bronze badges
0
2 Answers
Reset to default 6Use the source
property with a custom function. The custom function shown below mimics autoplete original behavior, searching for the typed text as substring inside available tags. If no match is found, all available tags are returned.
$(function() {
var availableTags = [
"JavaScript",
"Perl",
"PHP",
"Python",
"Ruby"
];
$("#tags").autoplete({
source: function(request, response) {
var term = request.term.toLowerCase();
var matchingTags = $.grep(availableTags, function(tag) {
return tag.toLowerCase().indexOf(term) >= 0;
});
response(matchingTags.length ? matchingTags : availableTags);
}
});
});
demo here
Just write a custom source
callback.
For example:
source: function(req, res){
res(['w00t', 'yay']);
}
See DOCs
In your case (pseudocode):
source: function(req, res){
//find `req` in array
if not found:
res(availableTags);
else:
res({subset of availableTags});
}