JQuery Autocomplete Custom Search Function

I want to use the jquery.autocomplete.js plugin for input in my form. I want to search on the client side and cannot use ajax. But I do not want the array to use the simple "Contains" search algorithm. I want to do to write a custom search function in javascript to search and order results. Is this possible and how?

Thank you for your time.

+4
source share
1 answer

Sure. You specify source as a function that will respond to a list of strings or, alternatively, {label, value} objects.

 $('#myInput').autocomplete({ source: function (request, response) { var term = request.term; var data = handleAutocomplete( term); /* get answers from somewhere.. */ response( data); } }); function handleAutocomplete (term) { var options = ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby"]; // use 'term' for custom filtering etc. return options; } 

See: http://api.jqueryui.com/autocomplete/#option-source

+4
source

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


All Articles