Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

setFocus on particular repeatable instance

Avatar

Level 9

I have a button located at the bottom of a subform.

When clicked the subform repeats.

I want to setFocus on the field located at the top of the new sub-form

so that the user isn't looking at the bottom of the new sub-form after clicking the button.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

The addInstance() method will return the subform just added, so from this you can use the xfa.host.setFocus() method.  If you could post an image of your hierarchy I could probably get the code reasonable close, but it will be something like;

var newInstance = _Subform1.addInstance();

xfa.host.setFocus(newInstance.TextField1.somExpression);

You just need to change the _Subform1 and the TextField1 bits.

Hope this helps

Bruce

View solution in original post

4 Replies

Avatar

Correct answer by
Level 10

Hi,

The addInstance() method will return the subform just added, so from this you can use the xfa.host.setFocus() method.  If you could post an image of your hierarchy I could probably get the code reasonable close, but it will be something like;

var newInstance = _Subform1.addInstance();

xfa.host.setFocus(newInstance.TextField1.somExpression);

You just need to change the _Subform1 and the TextField1 bits.

Hope this helps

Bruce

Avatar

Level 9

Bruce,

Your script solved my issue. Thank you. I understand all of what you wrote except the somExpression ending. What does that do?

Thank you,

-Don

Avatar

Level 10

Hi Don,

The TextField1 reference will return a XFAObject that represents the text field on the form. The somExpression is string reference (or address) of the field, will return a string like xfa[0].form[0].form1[0].Subform1[1].TextField1[0] which the setFocus method uses to reference the field.

Regards

Bruce

Avatar

Level 9

Bruce,

Thanks for taking the time to explain that script.

-Don