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

Dynamically Created Table Row Delete Button

Avatar

Level 9

In the form linked below, I can't get one of the buttons to work correctly.

At the bottom of the form there is a table and on the far right a green + button. Clicking this button adds an update row. That row when it appears has a deletion button on the left (red with white "X"). If I click that deletion button it works fine. But if i create several of these update rows, clicking the delete button on the third instance deletes the first instance instead of the third instance. How do I fix this?

https://acrobat.com/#d=4mzuO1Pjz-0Z4ntuLZAy4w

1 Accepted Solution

Avatar

Correct answer by
Level 2

On the remove button you need to modify the parameter passed in the removeInstance.

 

removeInstance(this.parent.parent.index - 1);

when you simply state this.parent.index it is referring to Subform3 which there is only ever one instance.  You are adding instances of Row1[1] therefore you need to go up one more level.  this.parent.parent.index.   Because you have are using  Row1[1] then you need to use -1 as well otherwise is will be the wrong instance

If you had named each Row uniquely then you could use this.parent.parent.index (without the -1).

View solution in original post

2 Replies

Avatar

Correct answer by
Level 2

On the remove button you need to modify the parameter passed in the removeInstance.

 

removeInstance(this.parent.parent.index - 1);

when you simply state this.parent.index it is referring to Subform3 which there is only ever one instance.  You are adding instances of Row1[1] therefore you need to go up one more level.  this.parent.parent.index.   Because you have are using  Row1[1] then you need to use -1 as well otherwise is will be the wrong instance

If you had named each Row uniquely then you could use this.parent.parent.index (without the -1).

Avatar

Level 9

That works great. I never understood that concept until now thanks to you. Thanks for taking the time to help and educate.

~Don