tags:

views:

83

answers:

2

Hello guys,

Your favorite French is back^^ I have just a small question.

In the YUI examples, this function allows to get information, I am not sure to understand what are reference done by myHandler :

var myHandler = function(sType, aArgs){
      myAC = aArgs[0]; // reference back to the AC instance
      elLI = aArgs[1]; // reference to the selected LI element
      oData = aArgs[2]; // object literal of selected item's result data
      }

Somebody can explain, with example (if possible), the correspondence for myAC, elLI, oData ? How this function work ? (sType, aArgs) ? myAC ?

+1  A: 

Fabien,

You're looking at a handler function written to handle a specific custom event in YUI AutoComplete. The event is the itemSelectEvent (http://developer.yahoo.com/yui/docs/YAHOO.widget.AutoComplete.html#event_itemSelectEvent ), which fires when an item in the AutoComplete list is selected. If you subscribe a function to that event -- eg, myHandler in your code snippet above -- your function will be called any time an item is selected and it will be passed the arguments you have noted.

This example on the YUI website shows you how to use the itemSelectEvent:

http://developer.yahoo.com/yui/examples/autocomplete/ac_itemselect.html

Please let me know if you have further questions.

Regards, Eric

Eric Miraglia
A: 

Thank you Eric,

You point to the example which I wanted to reference(http://developer.yahoo.com/yui/examples/autocomplete/ac_itemselect.html). Just after, in the example, we have :

// update hidden form field with the selected item's ID
myHiddenField.value = oData.id;

The oData.id define myHiddenField.value, but what define (myAC = aArgs[0];) and (elLI = aArgs[1];) in the example ? I don't understand, what is the utility in this example of myAC and elLI ? How work aArgs[0], aArgs[n] ... ?

I learn javascript and yui at same time, and sometime I lost my Latin (or english). Do you have other examples on the net ?