Support Article

Hotkeys do not work in modal windows

SA-29329

Summary



If a hotkey is defined for a button, using the hotkey in a modal window has no effect.

Error Messages



Not applicable.

Steps to Reproduce

  1.  Use a hotkey in a modal window.

Root Cause



An issue in the custom application code or rules.This is the default browser behaviour.

Resolution



Perform the following local-change:

Whenever hotkey event fired, the browser tries to find the element associated with fired hotkey event in current window only and triggers the action.
In this case, header is outside of new claim document(window) and we can’t access the elements outside of current window.

<script> 
pega.u.d.attachOnload(function() { 
 
pega.u.d.modalDialog.subscribe("show", function() { 
disableAccessKeysOnParentDocument(); 
}); 
 
pega.u.d.modalDialog.subscribe("hide", function() { 
enableAccessKeysOnParentDocument(); 
}); 
 
function disableAccessKeysOnParentDocument(){ 
try{
    var hotKeys = $("[id='HARNESS_CONTENT'] [accesskey]"); 
    hotKeys = $.merge(hotKeys, $("[id='HARNESS_BUTTONS'] [accesskey]")); 
    hotkeys = $.merge(hotKeys, $("div[class*='screen-layout'] [accesskey]")); 
    if(parent && parent != window){
        hotKeys = $.merge(hotKeys, $(parent.document).find("[id='HARNESS_BUTTONS'] [accesskey]")); 
        hotkeys = $.merge(hotKeys, $(parent.document).find("div[class*='screen-layout'] [accesskey]")); 
    }
    
    if(hotKeys && hotKeys.length > 0){ 
        var hotKeysLength = hotKeys.length; 
        for(var index =0; index < hotKeysLength; index++){ 
            var element = hotKeys[index]; 
            if(element){ 
                var attrDisabled = element.getAttribute("disabled"); 
                if(( !attrDisabled || attrDisabled == "false" )){ 
                    element.setAttribute("disabled", "true"); 
                    element.setAttribute("hotkeydisabled", "true"); 
                } 
            } 
        } 
    }
 
}catch(e){
 
}
 

 
function enableAccessKeysOnParentDocument(){
    try{
        var hotKeys = $("[id='HARNESS_CONTENT'] [hotkeydisabled]"); 
        hotKeys = $.merge(hotKeys, $("[id='HARNESS_BUTTONS'] [hotkeydisabled]")); 
        hotkeys = $.merge(hotKeys, $("div[class*='screen-layout'] [accesskey]")); 
        
        if(parent && parent != window){
            hotKeys = $.merge(hotKeys, $(parent.document).find("[id='HARNESS_BUTTONS'] [hotkeydisabled]")); 
            hotkeys = $.merge(hotKeys, $(parent.document).find("div[class*='screen-layout'] [accesskey]")); 
        }
 
        if(hotKeys && hotKeys.length > 0){ 
            var hotKeysLength = hotKeys.length; 
            for(var index =0; index < hotKeysLength; index++){ 
                var element = hotKeys[index]; 
                if(element){ 
                    element.removeAttribute("disabled"); 
                    element.removeAttribute("hotkeydisabled"); 
                } 
            } 
        }
    }catch(e){
    
    }
 

}); 
</script>
 

 

Published October 19, 2016 - Updated October 23, 2016

Have a question? Get answers now.

Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.