Enter Key closes Modal window
Hi guys. We implemented the scenario when user have a list of text conditions to choose from in Modal window and there is a search field to provide the specific search string, and the "Search" button for it. The user wants the Enter Key to work the same way as "Search" button as currently, when they press "Enter", the Modal window gets closed. I tried to modify the behavior of Enter Key, however I think the rules associated with it, are final. Hence I considered to disable it and used the following code I found on PDN (in UserWorkForm function):
<script>
pega.ui.Doc.prototype.handleModaldlgKeyPress = function(event){
if(pega.u.d.bModalDialogOpen){
var modaldialog = document.getElementById("modaldialog");
var srcObj = pega.util.Event.getTarget(event);
var elemTagName = srcObj.tagName.toUpperCase();
/* START Disabling ENTER key event
if (event.keyCode==13){
var controlType = null;
if(srcObj.type){
controlType = srcObj.type.toUpperCase();
}
if (elemTagName == 'TEXTAREA' || elemTagName == 'A' || elemTagName == 'SELECT' || elemTagName == 'BUTTON' ||
controlType == 'BUTTON' || controlType == 'SUBMIT' || srcObj.id == 'ModalButtonSubmit' ||
srcObj.id =='ModalButtonCancel' || typeof(srcObj.AutoComplete)!="undefined") {
pega.util.Event.stopPropagation(event);
return;
}
var buttonObj = pega.util.Dom.getElementsById("ModalButtonSubmit",modaldialog);
if(buttonObj){
Hi guys. We implemented the scenario when user have a list of text conditions to choose from in Modal window and there is a search field to provide the specific search string, and the "Search" button for it. The user wants the Enter Key to work the same way as "Search" button as currently, when they press "Enter", the Modal window gets closed. I tried to modify the behavior of Enter Key, however I think the rules associated with it, are final. Hence I considered to disable it and used the following code I found on PDN (in UserWorkForm function):
<script>
pega.ui.Doc.prototype.handleModaldlgKeyPress = function(event){
if(pega.u.d.bModalDialogOpen){
var modaldialog = document.getElementById("modaldialog");
var srcObj = pega.util.Event.getTarget(event);
var elemTagName = srcObj.tagName.toUpperCase();
/* START Disabling ENTER key event
if (event.keyCode==13){
var controlType = null;
if(srcObj.type){
controlType = srcObj.type.toUpperCase();
}
if (elemTagName == 'TEXTAREA' || elemTagName == 'A' || elemTagName == 'SELECT' || elemTagName == 'BUTTON' ||
controlType == 'BUTTON' || controlType == 'SUBMIT' || srcObj.id == 'ModalButtonSubmit' ||
srcObj.id =='ModalButtonCancel' || typeof(srcObj.AutoComplete)!="undefined") {
pega.util.Event.stopPropagation(event);
return;
}
var buttonObj = pega.util.Dom.getElementsById("ModalButtonSubmit",modaldialog);
if(buttonObj){
pega.util.Event.fireEvent(buttonObj[0],'click');
pega.util.Event.stopPropagation(event);
pega.util.Event.preventDefault(event);
}
}else
*END Disabling ENTER key event */
if (event.keyCode==27){ /* If the ESC key is pressed */
var buttonObj = pega.util.Dom.getElementsById("ModalButtonCancel",modaldialog);
if(buttonObj){
pega.util.Event.fireEvent(buttonObj[0],'click');
pega.util.Event.stopPropagation(event);
pega.util.Event.preventDefault(event);
}
}
}
}
</script>
It is still closing the window. Can somebody help to resolve this issue? We are using PRPC V7.2.1.
Thank you in advance,
Larisa
***Moderator Edit: Vidyaranjan | Updated Categories***