i have the following code:
$(function() {
//autocomplete
$("#autocomplete_ville_nom").autocomplete({
source: "../assets/php_queries/search_ville_nom.php",
minLength: 2
});
});
I am trying to tweak in order to have a matching on the first two characters. If the user inputs "An", he should see "Angola" and not "France".
I found the below code that works well:
var wordlist= [ "about", "above", "across", "after", "against",
"along", "among", "around", "at", "before",
"behind", "below", "beneath", "beside", "between",
"beyond", "but", "by", "despite", "down", "during",
"except", "for", "from", "in", "inside", "into",
"like", "near", "of", "off", "on", "onto", "out",
"outside", "over", "past", "since", "through",
"throughout", "till", "to", "toward", "under",
"underneath", "until", "up", "upon", "with",
"within", "without"] ;
$("#input1").autocomplete({
// The source option can be an array of terms. In this case, if
// the typed characters appear in any position in a term, then the
// term is included in the autocomplete list.
// The source option can also be a function that performs the search,
// and calls a response function with the matched entries.
source: function(req, responseFn) {
var re = $.ui.autocomplete.escapeRegex(req.term);
var matcher = new RegExp( "^" + re, "i" );
var a = $.grep( wordlist, function(item,index){
return matcher.test(item);
});
responseFn( a );
} });
from jQuery UI Autocomplete widget search configuration
However, i can't find a way to merge both (Basically using my php query and not a list).
Can you please help? thanks