Skip to main content
Participating Frequently
January 23, 2024
Question

Focus next field by tab number after committing using Enter

  • January 23, 2024
  • 3 replies
  • 578 views

I have some text fields which act as lines. I have to do this because the line spacing does not match up for the font size I have chosen. I do not want to change the font size nor the lines' spacing. I have not found a way to change a text field's line spacing reliably.

 

What I would therefore like to do is focus the next line (text field) when the user commits their input using the Enter key. Solutions I've found online use some strange work-arounds and have not worked for me so far. The OnBlur event fires only when the field loses focus using the Tab key or the mouse buttons, not when the Enter key is used.

 

My idea was to get the current field's tab number and simply change the focus to the next-greatest one when the user hits Enter. I haven't been able to find any API that returns the tab number, nor one that gets a field via its tab number, which is incredibly strange. I would like to avoid having to specify the explicit field name every time.

This topic has been closed for replies.

3 replies

JR Boulay
Community Expert
Community Expert
January 26, 2024

It would be simpler to change the paradigm.

Lines are good for hand-filled paper forms but in a digital form where it's impossible to write askew, you should use a multiline field, with a white background to hide the layout lines.

Acrobate du PDF, InDesigner et Photoshopographe
Nesa Nurani
Community Expert
Community Expert
January 24, 2024

You can use this as a custom keystroke script, this will set focus to a field when you press Enter key:

if (event.commitKey === 2)
this.getField("Text2").setFocus();

 

Change Text2 to the name of the field you wish to set focus to.

Bernd Alheit
Community Expert
Community Expert
January 24, 2024

You can't access the tab number in a script.

try67
Community Expert
Community Expert
January 24, 2024

This is true. If you want to be able to automate it somehow then either maintain an array of field names in their tar order, or add the tab order to the field name itself. Then you would be able to figure out in your code the next field to tab to, without having to hard-code it.