I'm implementing application to obtain stock information from Yahoo Finance API using YUI3. I've done the autocomplete list but face a problem on how to get the value after user click mouse or press enter on the list.
Here is my code. The problem is that mynode.after(...) gives an error but I have no idea why and how to fix it. Any help would be appreciated. Thank you.
YUI().use('autocomplete', function (Y){
mynode = Y.one('#comsymbol');
mynode.plug(Y.Plugin.AutoComplete, {
activateFirstItem: true,
enableCache: false,
source: function(query, callback) {
$.ajax({
dataType: "jsonp",
cache: true,
type: "GET",
jsonp: "callback",
jsonpCallback: "YAHOO.Finance.SymbolSuggest.ssCallback",
data: {query:query},
url: "http://autoc.finance.yahoo.com/autoc",
});
YAHOO.Finance.SymbolSuggest.ssCallback = function(data) {
var result = data.ResultSet.Result;
var lists = new Array();
for( var i = 0; i < result.length; i++ ) {
var sb = result[i].symbol;
var nm = result[i].name;
var xch = result[i].exch;
var all = sb + ", " + nm + " (" + xch + ")";
lists[i] = all;
}
callback( lists );
};
},
}
mynode.after('select', function (e) {
getStockInfo();
});
});
});
You must attach the event listener to the AutoComplete
instance rather than the Node
. The AutoComplete
instance can be accessed via the ac
member of the Node
, and from there you can simply attach your event callback as you had before:
mynode.ac.after('select', function (e) {
getStockInfo();
});
Take a look at the YUI AutoComplete tutorial (As a Plugin section specifically) for more details.