Automatically set focus to to new cell when using a table in AEM Designer /LiveCycle | Community
Skip to main content
June 8, 2023
Solved

Automatically set focus to to new cell when using a table in AEM Designer /LiveCycle

  • June 8, 2023
  • 1 reply
  • 1221 views
Please help.
I am using Add Instance to add a row to a table. How can I setFocus to a cell in the NEW row automatically? The only thing I can manage to do currently is set the focus to Row 1 Cell 1. But how can I write a script for a table row that does not actually exists until the user action triggers the row to be added. Currently when I add a multiple rows, the focus will be placed into row 1 every single time. I want each NEW row cell 1 to get the focus.
 
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by brite48

I Cant get this to work.  I have included a sample file here.

1 reply

ManviSharma
Adobe Employee
Adobe Employee
June 8, 2023

Hi,

 

To automatically set focus on the first cell of a newly added row in a table:

  1. Assign a unique identifier to the cells in the first column of each row.
  2. Attach an event listener to the action that adds a new row.
  3. After adding the row, use JavaScript to find the first cell in the new row using the unique class or identifier.
  4. Set focus to the first cell using the focus() method.

    Example code that I have found:
    const newRow = document.createElement('tr');
    // Add cells to the new row
    // ...
    const firstCell = newRow.querySelector('.first-cell');
    if (firstCell) {
    firstCell.focus();
    }

brite48AuthorAccepted solution
June 9, 2023

I Cant get this to work.  I have included a sample file here.