Set focus of input in repeating group

I ended up solving this with some fairly simple Javascript.

In the use case below, I’m setting the focus on the input in a newly created object in a repeating group.

Here’s how it works:

  1. Make sure your app settings allow IDs on elements (instructions here)

  2. Give each input field inside your repeating group (RG) a dynamically created unique ID


    In my app, each row in the RG is called a “Narrative” so I set the ID to be “narrative-” + the unique ID of the narrative object

Now that each input has a uniquely addressable ID we can set the focus in Javascript.

  1. Add the free Toolbox plugin to gain access to the “Run Javascript” in your workflows.

  2. In your workflow, create the new entry in the RG (in my case, creating a New Narrative and adding it to the RG)

  1. Now you can use Run Javascript to run this code. Note, this is very simple code that could use some more error handling.

What the code is doing is creating a variable with the ID of the input, then it tries to find it in the DOM. If it does, it sets the focus.

  1. Note that I put a pause of 100 milliseconds before the JS code to give time for the new element to be rendered on the page.

You’d need to modify where you use the code in your workflows if you want to use it for something else, such as setting focus on the first input of the RG. The key tho is that we now have addressable IDs so we can find them whenever we need them.

Hope this helps!