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.

how to refresh subforms index

Avatar

Former Community Member

Hi all,

is there any way for me to refresh the form subform index in form ready:layout?

i am having "2" subforms in my XDP form at page 6, as subform1[0],subform1[2].

A user can :

       i ) add more subform

       ii ) delete subform

The "add subform' will add a new subform by cloning the subform1 as reference subform.

The newly created subform will be placed on top of the subform1 (using moveinstance command )

Problem,

i am able to delete the subform1[2] on form load.

if i add "2" new subforms and delete the last subform which is previously subform1[2] or the last subform in the form,  i am not able to delete that subform. The delete script is not working.

I guess it is the subform index issue as the newly created subform give some conflict in indexing for the existing subform1[2] in the form.

So, is there any ways for me to refresh or re-arrange  " all the subforms indexs''  on form  ready:layout ?

regards,

Jeeva

5 Replies

Avatar

Level 10

Hi,

what script do you use to delete the subforms?

I prefer this script in the click:event of a button that is placed within the subform.

ReferenceSyntax.removeInstance(this.parent.index);

This will delete the current instance.

Avatar

Level 10

Hi Jeeva,

Where you have repeatable subforms with the same name, you are going to have problems and unexpected behaviour. Where subforms are not repeating, having the same name, while not good practice, is not as problematic. It just makes it more awkward to reference objects. In this case you will have multiple instances of the subform with the same name: 'subform1[0]', 'subform1[1]', etc.

When an object is repeatable and the user adds more instances, then each instance of that object at runtime will also have an instance. For example 'object1[0]', 'object1[1]', 'object1[2]', ..., 'object1[n]'.

In your case you appear to have multiple versions of the repeatable subform in the form, with the same name. This does not affect the addInstance as the parameter is true/false. However the removeInstance parameter is the instance number that is to be removed. I believe that there is a conflict with the instances number of the multiple repeatable subforms with the same name and their respective instances at runtime.

I would recommend that all objects on the form have a unique name, in particular repeating objects.

Niall

Avatar

Former Community Member

Hi Niall,

I change my approach.

instead add subform by function addInstance, I create  3 static subform in the form.

Make 2 of them invisible and if user want more subform, make visible the other hidden subform.

Now the problem is, if the user add 3 subform and delete ( real logic - in button is hidden the subform )the second subform. and later add again

a new subform, subform2 will come visible.

As subform2 in the form located below subform1, the time perform "add  subform" once after the deletion, this subform

appear below the subform1 and make the user's data entry not user friendly as need to key-in in the second subform in the form.

For the reason, i change the script to

     --> the time add subform, i do verify is subform3 is presence visible, if it's presence visible, then i did :

          if(subform2.presence=="hidden"){

               if(subform3.presence=="hidden"){

               subform2.presence="visible";

                 _subform2.moveInstance(1,0);     }

               else

               subform2.presence="visible";

          }

only the  subform2.presence="visible"; is working and   _subform2.moveInstance(1,0);     is not work. It not switch the subform location.

any suggestion , Niall?

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

Avatar

Level 10

Hi Jeeva,

I see the three subforms with different names. The click even of the 'add subform' button is now changing the presence of subforms 2 and 3. This works okay.

The next thing you are trying is to move a subform2 above subform3. You will not be able to do this using moveInstance.

I see that all three subforms are set as repeatable, but that you are not using the addInstance to add new instances of these.

The moveInstance will move an instance up or down WITHIN the range of its instances only. For example _subform2.moveInstance(1, 0); will move the second instance on subform2 to be above the first instance. You cannot use moveInstance to move an instance of subform2 above or below a different repeating subform (subform1 or subform3).

The line _subform2.moveInstance(1,0); does not work because there is only one instance of subform2[0].

I think that what you are after is a nested repeating subforms, so that an instance of subform2 will have an instance of subform3. Is this correct?

Niall

Avatar

Former Community Member

Thanks for the response,Niall.

First i am create all the subform dinamicly using the addInstance and removeInstance.

Subform contain Invoice Table mapped to invoice Node in XSD .

The time i create a new instance, the newly created instance too mapped to the same invoice node in XSD.

If i create 5 instance of invoice table and save the dinamic pdf, in the next time i open the pdf, i nowticed all the 5 tables

data are merged into 1 table. I was told this is the reason of the same invoice Node<invoice> mapping in all the tables.

So that reason,  i create a 5 static subforms in my dinamic pdf.  Each tables are mapped to differeent invoice node in XSD as

<invoive1>, <invoice2>....... I make a visiable as default and the rest hidden. A user can add table as it will make the  the

hidden table to visible.

Now i have solve the data merging issue, but Found another new problem as :

if i add 5 subform  and delete the 3 th subform and again add subform again, the new subform will be visible at 3th position as this

subform previously deleted and the property is now hidden. As as for the reason, i have try use moveInstance to move instance from 3th

position to 1 position. That not work as no new instance is involve.

So, what is the altenative i can applied to overcome this problems.