2

http://jsfiddle.net/9R4cV/116/

Hi frnds in this fiddle autocomplete is if i type letter "a" its listing even if "a" is in middle of the word but i need only starting words of "a" Please some one give me solution.

 $(document).ready(function() {

  var aTags = ["ask","always", "all", "alright", "one", "foo", "blackberry", "tweet","force9",   "westerners", "sport"];
  $( "#tags" ).autocomplete({
    source: aTags
  });
 });
manoji stack
  • 709
  • 1
  • 11
  • 27
  • 1
    http://jsfiddle.net/9R4cV/117/ An updated fiddle. Here's the documentation: http://api.jqueryui.com/autocomplete/#event-search – Jack Sep 10 '14 at 08:59

2 Answers2

2

I updated your fiddle http://jsfiddle.net/9R4cV/119/

See this answer for more info: https://stackoverflow.com/a/2405109/3810453

Here is the implementation:

    $(document).ready(function() {

    var aTags = ["ask","always", "all", "alright", "one", "foo", "blackberry", "tweet","force9", "westerners", "sport"];

    $( "#tags" ).autocomplete({
        //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( aTags, function(item,index){
            return matcher.test(item);
        });
        responseFn( a );
    }
});
});
Community
  • 1
  • 1
Zanshin13
  • 980
  • 4
  • 19
  • 39
0

From documentation, you can use custom source:

var aTags = ["ask","always", "all", "alright", "one", "foo", "blackberry", "tweet","force9",   "westerners", "sport"];
$("#tags").autocomplete({
   source: function( request, response ) {
     var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( request.term ), "i" );
     response( $.grep( aTags, function( item ){
       return matcher.test( item );
     }) );
   }
});
Justinas
  • 41,402
  • 5
  • 66
  • 96