Thursday, March 05, 2009

Accessing an LOV with a function key (F9)

In good old Oracle Forms you could access an LOV by pressing F9 (depending on your resource file settings). Within APEX you always need a mouseclick....unless you catch a keypress and call the LOV programatically. Of course with help of jQuery.

Create a function in your Page Header:

function checkLOV(pThis, pEvent){
var keynum;
var current = document.getElementsByName( pThis.name );
if(window.event) // IE
{ keynum = pEvent.keyCode; }
else if(pEvent.which) // Netscape/Firefox/Opera
{ keynum = pEvent.which; }
if (keynum == 120) //F9
//The LOV function call is in the anchor of the next TD element
{ eval($(pThis).parent().next().children().attr('href'));
}
}
This function is called by an onkeydown event on the fields with an LOV: onkeydown="checkLOV(this,event)". Ofcourse you also use jQuery and the APEX Repository to set this event for all fields with an LOV definition...
You can see it live on apex.oracle.com.

Update: After a comment of Louis-Guillaume I changed the above code using the jQuery HotKeys plugin. The code gets a lot simpler:

$(function(){
$('#P22_EMP').bind('keydown', 'f9', function(){
eval($(this).parent().next().children().attr('href'));
});
$('#P22_DEPT').bind('keydown', 'f9', function(){
eval($(this).parent().next().children().attr('href'));
});
});
Also available on apex.oracle.com.
Post a Comment