SxChoc
SxChoc

Reputation: 619

Build autocomplete options

Hi I'm trying to programmatically build a list of options (from some values in a data table) that are then used as the filter for an autocomplete input box.

The problem that I'm having is when i'm typing in the autocomplete field the list that I've built is being recognised as one massive option and not a series of smaller ones.

My code is below, I must be missing something obvious but I just can't see it!

Any help would be great :)

var availableTitles = "", i , iLen = aData.length;
for (i = 0; i < iLen; i++ )
{
        availableTitles += aData[i] + ', '
}

availableTitles = availableTitles.slice(0, -1);
var availableTags = [availableTitles];

$("#tags").autocomplete({ source: availableTags });

thanks in advance :)

Upvotes: 0

Views: 55

Answers (1)

Engineer
Engineer

Reputation: 48813

Write like this:

var availableTags = [ availableTitles.split(',') ];

Or simply remove the code you have provided and write:

$("#tags").autocomplete({source: aData});

as aData already can be served as a valid source for autocomplete.

Upvotes: 3

Related Questions