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

How to add a count to dynamic repeating subforms

Avatar

Level 2

Hi,

I am creating a form which has a dynamic interactive sub form.

I want the sub forms to be numbered, i.e. first one is 1, second - 2, and every time a user adds or removes an instance, the sub forms are numbered consecutively.

How do I do this??

Thanks in advance for your replies.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Here is a sample file for you..

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

I placed the below code in the LayOut Ready event of the TextField to display the Repeating Subform's index..

     this.rawValue = this.parent.index;

And in the Remove Instance Button Click event:    

     Subform1.instanceManager.removeInstance(this.parent.index);

     xfa.form.recalculate(0); // Passing 1 also to this method works.

Hope this helps.

Thanks

Srini

View solution in original post

6 Replies

Avatar

Level 10

Use the index of the Repeating Subform and add 1 to it. Because the index starts with 0.

For example if you have the text box inside a Subform that repeats..

this.rawValue = this.parent.index + 1;

Here the text box is one level down of the Repeating Subform in the heirarchy..If it is two levels down use this.parent.parent.index.. And so on..

Thanks

Srini

Avatar

Level 2

Thanks Srini, that’s great, works well.

The part I was having most trouble with was how to get the sub forms to re-number;

i.e. If I have 3 instances numbered 1, 2 and 3 and I delete 2, I want instance number 3 to re label to become the new 2.

Avatar

Level 10

You need to add xfa.form.recalculate(1); to your add/remove scripts.

Avatar

Level 2

Thanks

My scrip already has this line in. This line does sort the count for new additions post removal; it does not recalculate the count numbers of any instances added before the removal..........

i.e.  I have instance A with label 1

     I click the add button twice giving instances B and C with labels 2 and 3.

     I click remove on instance B.

     I am left with A and C with labels 1 and 3

     I then click add and I now have A, C & D with labels 1, 3 & 3.

I need to get instance C to recalculate from 3 to 2

Avatar

Correct answer by
Level 10

Here is a sample file for you..

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

I placed the below code in the LayOut Ready event of the TextField to display the Repeating Subform's index..

     this.rawValue = this.parent.index;

And in the Remove Instance Button Click event:    

     Subform1.instanceManager.removeInstance(this.parent.index);

     xfa.form.recalculate(0); // Passing 1 also to this method works.

Hope this helps.

Thanks

Srini