views:

161

answers:

1

The Google Closure (GC) Javascript Library makes it very easy to create an AutoComplete UI, as this demo shows - http://closure-library.googlecode.com/svn/trunk/closure/goog/demos/autocomplete-basic.html .

Basically, all we have to do is define an array and pass it on as one of the parameters. I'd like to be able to update the array dynamically and have AutoComplete show the changes immediately.

Example, if there are two arrays

list1 = ["One", "Two", "Three"]
list2 = ["1", "2", "3"]

and an AutoComplete has been initialized using list1,

var suggest = new goog.ui.AutoComplete.Basic(list1, document.getElementById('input'), false);

how can I update the existing AutoComplete (suggest) to use list2?

A: 

There isn't a public API to do this. You can create a subclass with a method that changes the protected matcher_ variable like this:

this.matcher_ = new goog.ui.AutoComplete.ArrayMatcher(list2, false);

If you want to dynamically update from a remote source, use goog.ui.AutoComplete.Remote.

Annie
That sucks ... too much work! Thanks anyway, Annie. Will look at some other ready made quickie solution.
You can probably just hack it--suggest.matcher_ = new goog.ui.AutoComplete.ArrayMatcher(list2, false);
Annie
The problem is there might be around 20 different arrays. Can't keep creating a new AutoComplete or ArrayMatcher for each of them.