setFocus on particular repeatable instance

DKinsley 24-10-2016

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.

Accepted Solutions (1)

Accepted Solutions (1)

BR001
MVP
25-10-2016

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

Answers (3)

Answers (3)

BR001
MVP
26-10-2016

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

DKinsley 25-10-2016

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