YUI AutoComplete events how?

I am using YUI 3.3.0 and the AutoComplete widget. I am completely new to YUI. That's what. AutoComplete works for me.

How can I catch an event triggered by autocomplete? The documentation states that the select event is fired when the user selects an item from the list. I want to bind a function to this event. How to do it?

+7
source share
1 answer

Here's an example plugin approach, http://tivac.com/yui3/so/skladjfyhafjk_autocomplete.htm

Just pass event handlers as part of the configuration when you first connect autocomplete to the input.

Y.one("#ac").plug(Y.Plugin.AutoComplete, { resultHighlighter: 'phraseMatch', source: ['foo', 'bar', 'baz'], on : { select : function(e) { console.log(arguments); //TODO: REMOVE DEBUGGING } } }); 

You can also subscribe after an element has been connected using the namespace to which it is attached ("ac").

 Y.one("#ac").ac.on("select", function() { console.log("post-plugin event subscription"); //TODO: REMOVE DEBUGGING }); 

If you use it as a class, it works as follows.

 var ac = new Y.AutoComplete({ inputNode: '#ac', source: ['foo', 'bar', 'baz'] }); ac.on("select", function() { console.log("Class event subscription"); //TODO: REMOVE DEBUGGING }); 
+15
source

All Articles