Audit Comments Custom Control: Enhancement

Home » Audit Comments Custom Control: Enhancement

A couple of weeks ago I posted on my blog an Audit Comments Custom Control for XPages, which launches a dijit dialog for audit comments when editing a document, and passes the value of the field back to the underlying DominoDocument data element. This simulated finctionality I had previously used in the Notes client for logging a reason for editing – a screenshot of the dijit dialog (after validation has failed) is below:

Audit Comments Dijit Dialog

You will see that unlike the normal dijit.Dialog, this dialog does not have the “X” icon in the top right to allow the user to prematurely close the dialog. However, during my final testing I remembered that pressing the Esc key also closes the dialog. Fortunately I remembered that about six months ago, in the same development where I had learned how to hide the “X” icon, I had also prevented the user from click Esc to close the dialog. To add the prevention, just include the following code in the dialog.js Javascript library:

//BLOCK TO PREVENT ACCIDENTAL CLOSING OR REFRESHING

 

dojo.connect(dialogWidget.containerNode,

“onkeypress”, function (evt) { //Prevent user accidentallyclosing dialog in IE and FF by pressing ESCif(evt.keyCode == dojo.keys.ESCAPE) {

dojo.stopEvent(evt);}

 

}

 

);

The dijit.Dialog provides a nice modal window, and the techniques I used in the Audit Trail custom control can be used to pass values from any dijit.Dialog back to the underlying document. However, if you’re not triggering the dialog from the onLoad function and you want to force them to click a button, you’ll also need to prevent the user from closing the dialog by pressing F5. This gets a bit more complex, because of differences in how Internet Explorer and Firefox handle that. For Internet Explorer you need to connect to the onkeypress function, for Firefox you need to connect to the onkeydown function. The rest of the code is very similar, and with the comments included is self-explanatory:

 

dojo.connect(dialogWidget.containerNode,

“onkeypress”, function (evt) { //Prevent user accidentally clearing data in IE by pressing F5

if(evt.keyCode == dojo.keys.F5 && evt.charCode == 0) {

//F5 = t, so check charCode = 0 (charCode for t is 116)

 

if (dojo.isIE)

{

 

evt.keyCode = 0;

//FF throws an error at this line, keyCode is read only for FF

 

 

dojo.stopEvent(evt)

//IE needs you to set keyCode to 0 (i.e. no key) as well

 

}

}

 

}

 

 

);

dojo.connect(dialogWidget.containerNode,

“onkeydown”, function (evt) { //Prevent user accidentally clearing data in FF by pressing F5

if(evt.keyCode == dojo.keys.F5 && evt.charCode == 0)

{

 

dojo.stopEvent(evt);}

 

}

 

);

For the Audit Trail custom control we don’t necessarily have to prevent the user pressing F5, because it reloads the page and reloads the dijit.Dialog. But there is no harm in including the code, especially if you’re looking to use the dialog_create function elsewhere. The fully updated dialog.js is attached.

 

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top