JQuery autocomplete with multiple inputs

I have an autocomplete field that I would like to increase by providing a dropdown value for categories, in the hope that this will simplify the search. This will take the category identifier from the drop-down list and then pass it along with the search text to my server-side autocomplete function.

I am using the autocomplete jQuery plugin, which can be found here:

http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/

The demo page is here:

http://jquery.bassistance.de/autocomplete/demo/

Perhaps this is already explained in the demo somehow, but I just do not see it. I can get data from JSON and split it into multiple fields.

It doesn't really matter, but I also use ASP.NET MVC.

+3
source share
3 answers

The first parameter of the autocomplete plugin can be an array or a URL. All you have to do is provide the identifier of your category as a query string parameter for your autocomplete function.

var selectedCategory = $('.categories').val();
var query = '';
if (selectedCategory !== 0)
{
   query = '?category=' + selectedCategory;
}
$("#suggest4").autocomplete('search_service.svc' + query, {
   // options   
});

Hope this helps.

+3
source

The previous answer is 1/2. The problem is that when you call the .autocomplete () function, the url + request is computed immediately, which means that the current selected category value will always be used when autocomplete is called. This means that if the user selects a different category, the new value will not be passed to the command prompt.

, URL- , bendewey.

jquery-autocomplete-other-fields

. , .

0

the best solution is to add extraParams callback function to your parameters

extraParams: {
  data: function(){ return new Date().getTime() }
},
0
source

Source: https://habr.com/ru/post/1727312/


All Articles