Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.

Deleting the LAST row in a table

Avatar

Level 2

Hi-

I have a table in which users can add or delete table rows depending on how much info they have to enter.  My problems is that the deleted button deletes the top row rather than the bottom row.

I think it is b/c my script looks like this: Table2.Row1.instanceManager.removeInstance(1);

I think that it should look like this: Table2Row1.instanceManager.removeInstance(nNumSub);

However, I can't get that last one to work either.  Can someone help a newbie out?  Thanks!

7 Replies

Avatar

Former Community Member

Can you post your form so we can give it a try?

Paul

Avatar

Level 2

Sure.  Please know that this is the first form I've ever created so it probably looks very beginner-ish.  Thanks!

Avatar

Level 2

I just posted it. Thanks!

Karen Duerr | Human Resources Manager

Lake Nona

9801 Lake Nona Road, Orlando, FL 32827

direct: 407-816-6597 cell: 407-947-7810

main: 407-851-9091 fax: 407-859-0436

www.LearnLakeNona.com

Avatar

Former Community Member

You will need to get a count of the subforms that are displayed (it is 1 based)  then pass that number to the removeInstance call (0 based). Here is the code for the 1st table:

Table2.Row1.instanceManager.removeInstance(Table2.Row1.instanceManager.count

- 1);

BTW - the form looks great for a 1st attempt.

Paul

Avatar

Level 2

Wow, that totally works! Thank you soooo much!

Karen Duerr | Human Resources Manager

Lake Nona

9801 Lake Nona Road, Orlando, FL 32827

direct: 407-816-6597 cell: 407-947-7810

main: 407-851-9091 fax: 407-859-0436

www.LearnLakeNona.com

Avatar

Former Community Member

There is nothing wrong with the approach that you have taken, but what if I want to remove the 3rd row of 5 then I cannot. For this reason most people will add the delete button to the repeating row (so that each row has a delete button). Then I can eliminate the row that I want instead of just the last one. If you decide to do this then you can change the command to be:

....removeInstance(this.parent.index)

This.parent.index will return the subform number that the button is on and hence it will remove the correct instance.

Just thought you might want to consider a different approach.

You can see this in action in the samples that ship with Designer ....look at your install directory at the subfolder structure below for a good sample.

EN\Samples\Forms\Purchase Order\Dynamic Interactive\Forms

Paul

Avatar

Level 2

Ohhhhh, good point! I'm sure I would have gotten that request once I distributed the form. I am going to try to make that change. Thanks again.

Karen Duerr | Human Resources Manager

Lake Nona

9801 Lake Nona Road, Orlando, FL 32827

direct: 407-816-6597 cell: 407-947-7810

main: 407-851-9091 fax: 407-859-0436

www.LearnLakeNona.com