Here is the scenario…

You have a text edit box, and when you leave that field (onBur) you fire a partial refresh to update some other values on the page.  Now since it is refreshed the focus of the cursor may not be where the user clicked on the form, worse – what if the user clicked a cancel button or another button?  The user will have to click it twice, once for the partial refresh and then once to fire the button.

With a little help from Paul Withers i think i have found a good solution to this issue.

First on the Xpage in the onClientLoad() event lets declare our 2 variables

var cancelRefresh = "";
var focusOnMe = "";

Next we go to the field with the onBlur() event that fires the partial update.

Click on the onBlur() event, then click on the client tab.  In the script area enter this code where yourfieldid is the id of the field you are editing.

if(dojo.byId("#{id:yourfieldid}").value ==""){return false};
if(cancelRefresh =="Yes"){
cancelRefresh ="";
return false;
}

Next we are going to go to the outline.  In the Outline you can expand the field and see event handlers.  Click on the event handlers, then the properties tab to the right.

Then scroll down until you see the onComplete property.  Click on it and enter this code.

if(focusOnMe != ""){
dojo.byId(focusOnMe).focus();
focusOnMe =""
}

This will focus on the field we just clicked on.

The next step is to go to a button, like a cancel button, or to a field.  Click on the onMouseDown event and enter this code on the Client tab.

For a button, tell it not to update

cancelRefresh ="Yes"

For a field, tell it where to focus, where yourfieldid is the id of the field

focusOnMe = "#{id:yourfieldid}"

That should get you immediate actions on your buttons and focus on the fields you click on after the refresh has occurred.

 

5 Responses to Xpages: How to make onBlur() partial update play nice with users

  1. Kim says:

    Gave this a try. I installed this code as published and when exiting out of the field I get the error msg of the cancelRefresh variable has not been defined. What is missing?

  2. Neil says:

    I have the same problem as Kim. Surely the scope of the two variables declared in the onClientLoad event do not exist beyond this event? Should they be scope variables?

  3. Jeffery Lay says:

    I’ve just recently run into a similar problem with a button in a partial-refreshed section. The embarrassingly awful kludge I’d used until I found a better solution was to script the events of the offending button, so that as soon as you moused over it, it gained focus and, in doing so, triggered the needed refresh. The result was that the refresh took place just as you moused over, and the button was ready to click. Ugly, I know… I’m not proud of it. This is much better, and I’ll switch over soon!

  4. Could that fix the “funny behavior” in the example on combining client and server side validation?

Leave a Reply

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