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

Change next field key to "enter" instead of "tab"

Lucrecious
Level 3
Level 3

Is there a way to change the key assigned to going to the next field for the "enter" key rather than the default "tab" key in a limited area within the form?

1 Accepted Solution
Niall_O_Donovan
Correct answer by
Level 10
Level 10

Hi,

Here is an example: https://acrobat.com/#d=RZ1lzX23*u7L4N9rtWCYPQ

Note if the user uses the tab key then the script will not fire.

Good luck,

Niall

PS One thing to bear in mind is that "index" is zero based, whereas "count" starts at 1.

View solution in original post

0 Replies
westlakejager
Level 3
Level 3

You will need to enter this script in the exit section as JavaScript into each field:

if (xfa.event.commitKey == 2){

      xfa.host.setFocus("fieldname");

}

The fieldname is the field you want to go to next.

westlakejager
Level 3
Level 3

Also, to be consistent, make sure your tabbing order is in line with the scripts.

Lucrecious
Level 3
Level 3

Unfortunately, it turns out to be a bit more complex as the next field is a cell within a row in a dynamic table.

I have worked this out based on your excellent advice:

if (xfa.event.commitKey == 2){
      xfa.host.setFocus("EditorialCreditForm.ProductInfo.Table3.Row[3].FirstChoice");
}

then the next field has this:

if (xfa.event.commitKey == 2){
      xfa.host.setFocus("EditorialCreditForm.ProductInfo.Table3.Row[4].FirstChoice");
}

etcetera...

Now, it works perfectly well, thank you, however, when I add another row to the table with the addRow button, the code does not translate properly.

This suprised me as similar codes have worked in the past.

The increment on the row number doesn't seem to work at the last row of the table.

Any thoughts...

westlakejager
Level 3
Level 3

Ahhh...that's a good question. The only thing I can think of is to count the rows/instances and write some IF statements. Hopefully the real pros can help...

Niall_O_Donovan
Level 10
Level 10

Hi,

Westlakejager's script will do the job, I think you just need to be a bit more dynamic in the row instance.

If I understand you correctly you want the focus to go to the same object, but on the next row down. If so then something like this should work:

if (xfa.event.commitKey == 2)

{

     var nextRow = this.parent.index + 1;

     var nextHit = xfa.resolveNode("EditorialCreditForm.ProductInfo.Table3.Row[" + nextRow + "].FirstChoice");

     xfa.host.setFocus(nextHit);
}

If you wanted the enter to set focus an object on the same row it would be easier, as Acrobat would assume you want the object in the same instance:

if (xfa.event.commitKey == 2)
{
     xfa.host.setFocus("thirdChoice");
}

Hope that helps,

Niall

PS If this works in any way, you may need to test first that the user is not already on the last instance, otherwise it will be out of bounds. Maybe if it is on the last instance, set focus to the top of the table or somewhere else.

westlakejager
Level 3
Level 3

I tried and that works well, although, once you're on the last row, how would you get to the next field?

Niall_O_Donovan
Correct answer by
Level 10
Level 10

Hi,

Here is an example: https://acrobat.com/#d=RZ1lzX23*u7L4N9rtWCYPQ

Note if the user uses the tab key then the script will not fire.

Good luck,

Niall

PS One thing to bear in mind is that "index" is zero based, whereas "count" starts at 1.

View solution in original post