Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery Autocomplete: Overriding default behavior

I want to have some sort of custom autocomplete and I thought it makes more sense to customize jQuery's autocomplete. So I'd like to know:

  1. How to force open the autocomplete list? $("#autocomplete").trigger('autocompleteopen'); doesn't work.

  2. How to put your own stuff onto the list? Obviously not through source option, but from outside it.

In other terms, from 1 and 2, I want to have a list of all options (not limited by limit) and I want it open and showing all the options before the user starts to type and regardless of what the user is typing.

Any help would be appreciated.

Cheers
Parsa

like image 584
parsa Avatar asked Nov 16 '10 13:11

parsa


1 Answers

The other answer didn't help me much (in regards to your question 1), however after a bit of digging around I have found the easiest way to force the autocomplete list to open. All you need to do is simply call the 'search' method.

The first thing you need to do is initilase your autocomplete with a minlength of 0, like so:

$('#autocomplete').autocomplete({
  minLength: 0,
  ...
});

Then you can call the search method to open the list:

$('#autocomplete').autocomplete('search');

Hopefully this helps other people searching for an answer to this problem.

like image 183
Christian Avatar answered Nov 11 '22 19:11

Christian