➡ Set focus on text field in last repeater item

Hi,

I have created a repeater widget.

Each item in the repeater widget contains a text input field.

With the click of a button, I dynamically add a new repeater item to this repeater widget.

When that happens, I want to automatically set focus to the text input field contained in the last repeater item of the repeater widget.

If e.g. the last repeater item contained in the repeater widget has an index of 12, I want to set the focus to text input field contained in the 12th repeater item.

How can I do this in Axure RP9 without using Javascript, if at all?

Thanks!

Hi!

Whenever the repeater’s dataset is modified in any way (not counting marking a row) its OnItemLoad handler executes, just like it executes when the page loads. You can test whether the row is the last row using Item.isLast, and then put focus on the row.

You’ll want to make sure this is happening only when adding a row, and not - say - when the repeater simply loads when the page does., So you can set a variable to true just before adding the row and to false just after.

Pseudocode below:

OnClick (of add-row button)
  set v_addingRow to true
  add row to repeater
  set v_addingRow to false 

Then in your repeater:

OnItemLoad
  if this is the last row AND v_adding row is true
    wait 0 ms
    set focus on text field

Note that the wait command is there so that the set focus command doesn’t execute until the OnItemLoad code finishes. Essentially, it puts the set focus command at the end of the execution queue.

set-focus-on-last-row-upon-add.rp (50.7 KB)

1 Like

Thanks, @josephxbrick!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.