Thursday, December 4, 2014

Prevent backspace button navigating to previous page ADF

 

<af:document id="d1" title="#{apptaskflowBundle.AppName_APPLICATION}">
      <af:clientListener method="onloadJSPXPage" type="load"/>

      <af:resource type="javascript" source="javascript/<javascriptfile.js>"/>


Use the method onButtonPressed() on KeyDown event - To disable backspaceon a component like select one choice

On load event of the document call the method onloadJSPXPage() in javascript.js file to avoid navigating to the previous page

*Thanks! to my colleague Gareth Paglinawan for providing the code snippet


function onloadJSPXPage(event) {
    document.onkeydown = function (e) {

        var evt = e ? e : window.event;
        var keyCode = evt.keyCode;
        var tag = evt.srcElement.tagName;
       
        
        if (keyCode == 8){
          if (tag == 'INPUT'){
            return true
          }else{
            return false;
          }
        }
        else{
            return true;
        }


    };


//document.onkeydown = onButtonPressed;//or however you are calling your method

function onButtonPressed(event) {
    var keycode = event.getKeyCode();
    //alert(keycode);
    switch (keycode) {
        case 8:
            event.cancel();
            break;
        case 46:
            break;
        default :
            break;

    }

}


No comments: