Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events

setFocus after recalculate

Avatar

Former Community Member
Does anyone know of a way to set the focus to a field after the form does a recalculate? I've tried this script in the click event of the addInstance button:



_sub3.addInstance(1);



xfa.form.recalculate(1);



app.setTimeOut('xfa.host.setFocus("form1[0].subform5[0].sub3[0].cn1[0]");', 10000);



but it doesn't work. After adding an instance (with the recalculate included) the next tab will bring the user back to the beginning of the form. I also tried putting the timeout script in the exit event of the addInstance button to no avail. On other addInstance buttons that don't contain the recalculate script the tabbing order is fine.



Any advice would be appreciated.



Thanks,

Dave
5 Replies

Avatar

Former Community Member
Check out these threads...



http://www.adobeforums.com/cgi-bin/webx?128@@.3bbf07e5



http://www.adobeforums.com/cgi-bin/webx/.3bbc29c4/3



http://www.adobeforums.com/cgi-bin/webx/.3bc2105c/1



The script is more like this...



_PageScheduleBCD.addInstance(1);

xfa.form.recalculate(1);



//Find the current index

var nindex = (xfa.resolveNodes("PageScheduleBCD[*]").length) -1;



//xfa.host.messageBox("the index is: " + nindex);



app.setTimeOut("this.getField('Form1[0].MainBodySubform[0].PageScheduleBCD[" + nindex + "].SalaryInfo[0].Name[0]').setFocus()", 1);



You have to use getField for it to work. Also, with each added instance you have to find the index so that's why I use a variable each time because it changes.



Thanks,

Ken

Avatar

Former Community Member
Thanks very much Ken, this was a real thorn in my side.



Thank you,

Dave

Avatar

Former Community Member
Ok Ken, I've tried working with the script you posted and I still can't get it to work. Any advice with troubleshooting?



Thanks,

Dave

Avatar

Former Community Member
Maybe if you paste the script in here I could take a look at it. Are you saving the form as dynamic? The script has to be in the click event too. Erase anything you have in the Exit event.

Avatar

Former Community Member
As I was writing this, I realized I had the pathway wrong in my script, it works wonderfully. Thanks Ken.



Dave