This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Mar 7, 2011, 8:18 AM
149 Posts

Re: How to set focus to a field when Xpages load

  • Category: Dojo and Client Side JavaScript
  • Platform: All
  • Release: 8.5.2
  • Role: Developer
  • Tags: Focus
  • Replies: 6
 
you can use this code in a CSJS scriptlibrary
 
dojo.addOnLoad(function(){
    var it = dojo.query("*[id$='subject']")[0];
    it.focus();
});
 
Mar 7, 2011, 7:57 PM
13 Posts
Re: How to set focus to a field when Xpages load [Not working]
 I tried this and it doesn't work. I *think* the problem might be that the field that I want to focus on has a partial refresh on one of it's events? I read somewhere that there is a problem with focus if a field has a partial refresh?
Mar 8, 2011, 7:08 AM
41 Posts
Re: How to set focus to a field when Xpages load [Not working]
 If an onfocus event is defined for the target field and the component matching the refresh ID of that event contains the field, then yes... that portion of the page would be refreshed immediately onload, which would replace the field with the result of the updated component state. This would cause the focus to be lost... unless, of course, you set an onComplete for the event to refocus the field... but that would trigger the refresh event, and another focus... infinite loop.
Mar 8, 2011, 4:11 PM
13 Posts
Re: How to set focus to a field when Xpages load [Not working]
That is a good point, but I am refreshing another part of the Xpage.
 
I can't get this to work even on a clean Xpage. I must be doing something stupid.

Here is my code:

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">

    <xp:this.onClientLoad><![CDATA[dojo.query("input[id$='inputText1']")[0].focus();]]></xp:this.onClientLoad>
    <xp:inputText id="inputText1"></xp:inputText>
</xp:view>
 
If someone can point out my error I would greatly appreciate it.

This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal