Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

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

Avatar

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

Avatar

Correct answer by
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

8 Replies

Avatar

Former Community Member

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.

Avatar

Former Community Member

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

Avatar

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...

Avatar

Former Community Member

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...

Avatar

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.

Avatar

Former Community Member

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

Avatar

Correct answer by
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.