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

javascript is deleting wrong row in table

Avatar

Level 1

I created a table in livecycle es 8.2. I have buttons to add and delete rows. The add button works fine, but the delete button is deleting the wrong row. For instance, in the PDF preview mode, if I add three rows and try to delete the third, the second is deleted.

To add a row, I am using the code:

usertable._Row1.addInstance(1);

To delete a row, I am using the code:

usertable._Row1.removeInstance(1);

I've tried a lot of variations that I found online, include (this.parent.index) and (true). I don't know anything about javascript other than what I've used for this form. Can anyone help me?

Thanks in advance!

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

The parameter for the addInstance() is either 1 (true) or 0 (false) and this relates to whether the new instance will be merged with the data model.

When it somes to the removeInstance(), the parameter is the instance number you want to remove, based on a zero-numbering system.

So if there were four instances of a repeating row (Row1), then the numbering would be Row1[0], Row1[1], Row1[2] and Row1[3]. If you wanted to remove the second instance the script wouls look like

_Row1.removeInstance(1); 

Here are some examples, have a look at the delete row button:

https://acrobat.com/#d=X1msu65emlM10IWKxkiUyw

https://acrobat.com/#d=tIpEHFadQtSOefZkU9EBfQ

https://acrobat.com/#d=RZ1lzX23*u7L4N9rtWCYPQ

In these you will see I have used 'this.parent.index' as the parameter.

Hope that helps,

Niall

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

Hi,

The parameter for the addInstance() is either 1 (true) or 0 (false) and this relates to whether the new instance will be merged with the data model.

When it somes to the removeInstance(), the parameter is the instance number you want to remove, based on a zero-numbering system.

So if there were four instances of a repeating row (Row1), then the numbering would be Row1[0], Row1[1], Row1[2] and Row1[3]. If you wanted to remove the second instance the script wouls look like

_Row1.removeInstance(1); 

Here are some examples, have a look at the delete row button:

https://acrobat.com/#d=X1msu65emlM10IWKxkiUyw

https://acrobat.com/#d=tIpEHFadQtSOefZkU9EBfQ

https://acrobat.com/#d=RZ1lzX23*u7L4N9rtWCYPQ

In these you will see I have used 'this.parent.index' as the parameter.

Hope that helps,

Niall