JQuery autocomplete search method

I use jQuery UI autocomplete, this is the code below

  var opt_source = {...}
 var options = {
             minLength: 0,
             source: opt_source,
             search: "aPreDefinedString"
         };
 $ (". searchable_input"). autocomplete (options);

My understanding is that now it should look for aPreDefinedString ; This does not happen; rather, it searches for a local source for userInput . Can someone please indicate where I am going wrong?

+3
jquery jquery-ui
source share
3 answers

Ok so i had to make it work

  var opt_source = {..};

 var options = {
             minLength: 0,
             source: function (request, response) {
                 response (opt_source);
             }
         };
 $ (". searchable_input"). autocomplete (options);

This seems to override the inline search (hopefully they won't break it in future versions)

From the jQuery UI documentation

The third option, callback, provides maximum flexibility and can be used to connect any data source to autocomplete. The callback receives two arguments:

A request object with a single property called "term" that refers to the value currently in the text input. For example, when a user entered “new summer” in the city field, the term “AutoComplete” would equal “new year”. A response callback that expects a single argument to contain the data offered to the user.

This data should be filtered based on the provided term and can be in any of the formats described above for simple local data (String-Array or Object-Array with label / value / both properties). This is important when providing a custom source callback to handle errors during a request. You should always call a response callback, even if you encounter an error. This ensures that the widget always has the correct state.

+7
source share

I think you are mixing the search event and the search method in the autocomplete widget. You can specify the event handler for search in the options object (which you do) that was used to initialize the widget.

The method of calling the search method is as follows:

 $(".searchable_input").autocomplete( "search" , "aPreDefinedString" ); 

This will automatically search for autocomplete.

+6
source share

my code is like this and it works.

 var availableTags = ['aa','bb','cc']; $( "#filterinput" ).autocomplete({ source: availableTags, autoFocus: true, }); $( "#filterinput" ).on( "autocompletesearch", function( event, ui ) { console.log($(this).val()); } ); 
0
source share

All Articles