Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

SetFocus to a new SubForm

Avatar

Former Community Member
I have a document with a checkbox to activate a 5th page where the user can modify the document. When the user checks the checkbox I want to set focus on the new page and the first checkbox on that page.

Any ideas on how to get this working?

I´ve tried this on the layout:ready event without success:



app.setTimeOut("this.getField('MyPage[0].MySubForm[0].MyCheckbox[0][" + nindex + "]).setFocus()", 1);
5 Replies

Avatar

Former Community Member
Have you tried putting the script on the click event of the checkbox? If you put it on layout:ready, it's going to run the script when the form opens, at which time the 5th page isn't active.



Regards,

Dave

Avatar

Former Community Member
Hi,

Thanks for replying Dave,

The script is on the click event of the checkbox.

Is it necessery to reference to both the Page, subform and checkbox or can I simply reference to the checkbox like this:

app.setTimeOut("this.getField('CheckBox_Loadcheck[0][" + nindex + "]').setFocus()", 1);



Regards

/Mats

Avatar

Former Community Member
Just to clarify, your script should be in the checkbox that activates page 5, and should reference the 1st checkbox on page 5 for setting the focus, with the full path to that page 5 checkbox, something like:



app.setTimeOut("this.getField('formname[0].subformname[0].checkboxname[" + nindex + "]').setFocus()", 1);



Regards,

Dave

Avatar

Former Community Member
David,

It still does not work as intended.

I have the script on the checkbox for showing and hiding the 5th page and on the click event.

The code is:

// Show hide page 5

if (CheckBox2.rawValue == 1)

xfa.resolveNode("FormPage1").presence="visible";

else

xfa.resolveNode("FormPage1").presence="hidden";



//Focus

app.setTimeOut("this.getField('FormPage1[0].Subform11[0].CheckBox100[" + nindex + "]').setFocus()", 1);



Any ideas?



Regards

Mats

Avatar

Former Community Member
Where are you defining your nindex variable? If you don't have one set up, and there are no other instances of the page 5 checkbox, you should just be able to replace " + nindex + " with zero.