James Moore
James Moore

Reputation: 9026

YUI AutoComplete: how do you get it to expand when the input is selected?

I've got a YUI AutoComplete control, works great. Except that I'd like it to expand the list of suggestions as soon as the user selects the input box. How do I make that happen?

Right now expansion doesn't happen until the user hits a key in the box.

Upvotes: 2

Views: 549

Answers (3)

cbmckay
cbmckay

Reputation: 496

This works when using YUI 3:

Y.one('#id').plug(Y.Plugin.AutoComplete, {source:['item1','item2','item3','etc']})
            .on('focus', function(){this.ac.fire('query')});

On focus of the attached input (id), the query event is fired to populate the 'menu' and display it.

Upvotes: 1

Jenny Donnelly
Jenny Donnelly

Reputation: 412

Tivac has the right idea -- use textboxFocusEvent to send an empty query that returns results to populate the container. Check out this example for some sample code: http://developer.yahoo.com/yui/examples/autocomplete/ac_combobox.html

Upvotes: 1

Tivac
Tivac

Reputation: 2573

You can use the textboxFocusEvent to send a query of the contents of the input, which will open the results pane. I tried using expandContainer without success but wasn't sure that would have worked anyways.

Working Example: http://tivac.com/yui2/autocomplete_jamesmoore.htm

Upvotes: 1

Related Questions