Repeat a Subform that has dynamic rows

stephanieh55112

13-04-2018

My form has a table that the user can add/remove rows as desired.

I am looking for a way to allow the user to copy the table mentioned above into a second, third, etc. instance. I want the subsequent instances to have the same number of rows and have the same text as entered in the first instance.

Looking for a solution to this in JavaScript.

Accepted Solutions (0)

Answers (5)

Answers (5)

MinusZero

17-04-2018

Glad to have helped out.

Loops are not my thing, but if you search the forum you should be able to find some examples. The LC help is rather lacking when it comes to loops.

stephanieh55112

17-04-2018

Thank you! This helps - I am getting closer.

I can now add a second instance of Table1 with the same number of rows as the first instance.

Now I need help creating my loop functions... I am not experienced in Javascript so examples are helpful.

I think I will need two loop functions or nested loop functions: Copy text fields from the first table instance to x table instance for y number of rows

MinusZero

16-04-2018

Hi,

Another instance of Table1 would still be Table1, but be referenced using an instance parameter Table1[0]. For Example:

  • I have a hierarchy with a table which is wrapped in a subform. The subform (not the table itself) is set to repeat in the Binding tab.

1467124_pastedImage_0.png

1467140_pastedImage_1.png

  • I added a button to create new instances and also add some text into the third instance to show how you can reference it.

1467141_pastedImage_2.png

1467142_pastedImage_3.png

  • When i add two more instances of the subform Table1, text is added to the specified textfield in the third instance.

1467143_pastedImage_4.png

Instead of having this.resolveNode("Table1[2].Table1.Row1.TextField1").rawValue = "text in third instance";

you could easily have

this.resolveNode("Table1[2].Table1.Row1.TextField1").rawValue = this.resolveNode("Table1[0].Table1.Row1.TextField1").rawValue;

This would put the value in the textfield in the original instance into the same field in the third instance. You could shorten the code by counting instances and using a variable or you could just write a very long code accounting for a maximum number of subform instances.

Does that help?

stephanieh55112

16-04-2018

Thanks for the response.

I would like the user to dynamically be able to repeat the table as many times as needed so I don't think your code in the link will work for me. Referencing your example, I would need multiple instances of Table1 - I won't have a Table2.

MinusZero

15-04-2018

Hi,

Your code will need to know how many instances the original table has so you know how many instances in the other tables to make. You will then need to make the rawValue of the target table cell the same as the original table cell. To do this you need to send the rawValue to the correct row (instance).

See this link for some information about referencing row instances directly.

dynamically create new table with set number of rows