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
BedrockMission!

Learn More

View all

Sign in to view all badges

How do I set focus after initialization?

Avatar

Avatar
Validate 1
Level 4
jasotastic81
Level 4

Likes

35 likes

Total Posts

329 posts

Correct Reply

43 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile

Avatar
Validate 1
Level 4
jasotastic81
Level 4

Likes

35 likes

Total Posts

329 posts

Correct Reply

43 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile
jasotastic81
Level 4

13-03-2013

Problem: I'm having trouble setting the focus to a new text field after it is initialized.

Background: I have created a form with a table that creates a new row after leaving the last textfield/cell in the last row if it is needed. Once I tab out of the last field, focus is lost completely--i.e., tabbing does not reach any other parts of the form.

Attempts: I have attempted to set focus on the first text field in the new row by using (rowNum is a variable for the newly created row)

xfa.host.setFocus("xfa[0].form[0].form1[0].#subform[0].Subform2[0].Table1[0].Row1[rowNum].TextField1[0]");

and

this.parent.parent.Row1[rowNum].TextField1.setFocus();

I have also tried to set focus back to the last field I had just exited with

xfa.host.setFocus("this");

I have also tried using the action builder to bring focus to the newly created textfield when it is initialized.

[edit] I forgot to say that the attempt to set the focus back to the last field I had just exited actually worked. [/edit]

Message was edited by: jasotastic81

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Give Back 3
Level 2
past-tense
Level 2

Likes

9 likes

Total Posts

85 posts

Correct Reply

10 solutions
Top badges earned
Give Back 3
Give Back
Validate 1
Boost 5
Boost 3
View profile

Avatar
Give Back 3
Level 2
past-tense
Level 2

Likes

9 likes

Total Posts

85 posts

Correct Reply

10 solutions
Top badges earned
Give Back 3
Give Back
Validate 1
Boost 5
Boost 3
View profile
past-tense
Level 2

13-03-2013

Looks like you used the variable as a literal string... you need to concatenate the value of the variable into the SOM expression:

xfa.host.setFocus("xfa[0].form[0].form1[0].#subform[0].Subform2[0].Tab le1[0].Row1[" + rowNum + "].TextField1[0]");

Note the two + around the variable name, to join it's value with the rest of the string.

Let us know if this helps.

-Scott

Answers (2)

Answers (2)

Avatar

Avatar
Give Back 3
Level 2
past-tense
Level 2

Likes

9 likes

Total Posts

85 posts

Correct Reply

10 solutions
Top badges earned
Give Back 3
Give Back
Validate 1
Boost 5
Boost 3
View profile

Avatar
Give Back 3
Level 2
past-tense
Level 2

Likes

9 likes

Total Posts

85 posts

Correct Reply

10 solutions
Top badges earned
Give Back 3
Give Back
Validate 1
Boost 5
Boost 3
View profile
past-tense
Level 2

13-03-2013

Hey again, glad you worked it out.

Just for clarification, a literal string is anything between quotes. Literal strings are just plain text. Including the name of the variable in the string does not actually cause a reference to the value to exist. The compiler just sees text, and doesn't know which (if any) parts of the text you intended to reference a variable.

So when you wrote:

xfa.host.setFocus("xfa[0].form[0].form1[0].#subform[0].Subform2[0].Table1[0].Row1[rowNum].TextField1[0]");

if was almost like trying to reference a field directly by using:

xfa.form.form1.subform.subform2.table1.Row1["rowNum"].TextField1

"rowNum" is just a string, one that 'just so happens' to have the name of your variable in it. The compiler has no clue what to do with a string as an index, so it fails.

Hope that helped to explain it a bit better.

Avatar

Avatar
Validate 1
Level 4
jasotastic81
Level 4

Likes

35 likes

Total Posts

329 posts

Correct Reply

43 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile

Avatar
Validate 1
Level 4
jasotastic81
Level 4

Likes

35 likes

Total Posts

329 posts

Correct Reply

43 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile
jasotastic81
Level 4

13-03-2013

@past-tense

It didn't fix it exactly, but it did put me on the right track. I think I may have changed some of the containers after posting my question while working on other parts of the form.

Here was my solution:

var s = "this.parent.parent.Row1["+rowNum+"].TextField1";

xfa.host.setFocus(s);

I had not even considered that I was using a literal string, despite the quotation marks...