Thanks for your help.
I have modified my code in 2 places.
First, in <p:autoComplet> widget, I have added a "widgetVar" attribute with EXACTLY same value as "id" attribute.
Then, my JavaScript code look like
Code: Select all
function AutoCompleteOnKeyDown(oField, e)
{
if (e.keyCode === 40) // Pressing on ARROW-DOWN
{
// WidgetVar must be equal to Id define in AutoComplete component
var sWidgetVarName = oField.id;
// remove part before last : character
var iPos = sWidgetVarName.lastIndexOf(":");
sWidgetVarName = sWidgetVarName.substring(iPos+1);
// remove '_input' at end of string
var iPos = sWidgetVarName.lastIndexOf("_");
sWidgetVarName = sWidgetVarName.substring(0,iPos);
var oWidgetVar = PF(sWidgetVarName);
if (!oWidgetVar)
{
alert("WIDGET-VAR attribute is not equal to ID attribute (AutoComplete:" + oField.id);
}
else
{
// show propositions ONLY if panel is not already displayed
// to allow to navigate in panel with UP and DOWN arrow keys !
if (oField.value === "")
{
if (!oWidgetVar.panel.attr('style'))
{
// show suggestions panel
oWidgetVar.search("*");
}
else
if (oWidgetVar.panel.attr('style').indexOf("visiblity: visible") > 0)
{
// show suggestions panel
oWidgetVar.search("*");
}
}
}
}
}
It is a big workaround with some tips that depends on how PrimaFaces is named his variable.
I have also try a solution where, in onkeydown() function I pass not "this" but PF('<name of widgetVar').
This solution has no workaround since I must not find/construct the sWidgetVar string.
But this is peanful, because I must type the widgetVar for all <p:autoComplete> widget.
If somebody has a more elegant solution, I'm insteresting !
Is there a manner to pass widgetVar object like
onkeydown="AutoCompleteOnKeyDown(widgetVar, event);"