开发者

YUI AutoComplete events, how to?

开发者 https://www.devze.com 2023-02-05 15:29 出处:网络
I\'m using YUI 3.3.0 and the AutoComplete widget. I\'m entire开发者_开发知识库ly new to YUI. Here\'s the thing. I have AutoComplete working.

I'm using YUI 3.3.0 and the AutoComplete widget. I'm entire开发者_开发知识库ly new to YUI. Here's the thing. I have AutoComplete working.

How do I catch an event fired by AutoComplete? The documentation states that a select event is fired when a user selects an item from the list. I want to attach a function to that event. How do I do that?


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

Simply pass your event handlers as part of the config when you first plug autocomplete into 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 the element has been plugged using the namespace it attaches to ("ac").

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

If you are using it as a class, it works like this.

var ac = new Y.AutoComplete({
    inputNode: '#ac',
    source: ['foo', 'bar', 'baz']
});

ac.on("select", function() {
    console.log("Class event subscription"); //TODO: REMOVE DEBUGGING
});
0

精彩评论

暂无评论...
验证码 换一张
取 消