Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Dynamic Add table not working

Avatar

Not applicable

Hi,

I have to  2 subforms,name table_subform[0] and table_subform[1] .

To add a new table , i use script :

var sSubformSOM = "xfa.form.form1.page1.table_subform";

var oSubform = xfa.resolveNode(sSubformSOM);    

var sParentSOM = oSubform.parent.somExpression;   

var sManagerSOM = sParentSOM + "._" + oSubform.name+ "["+ 1 +"]"; ;  // Control the the new table location

var oManager = xfa.resolveNode(sManagerSOM);

oManager.addInstance(1);

PROBLEM : , the this add table function "ADD THE NEW TABLE IN BETWEEN table_subform[0] and table_subform[1].

REQUIREMENT : The new table should added next to the last table.

SOLUTION 1 : var sManagerSOM = sParentSOM + "._" + oSubform.name + "["+ 1 +"]"; // index 1 to add the new table next to the second table

var sSubformSOM = "xfa.form.form1.page1.table_subform";

var oSubform = xfa.resolveNode(sSubformSOM);   

var sParentSOM = oSubform.parent.somExpression;   

var sManagerSOM = sParentSOM + "._" + oSubform.name+ "["+ 2 +"]"; ;  // Control the the new table location

var oManager = xfa.resolveNode(sManagerSOM);

oManager.addInstance(1);

PROBLEM : NOW all my "new table" are added by reference to oSubform.name + "["+ 1 +"]";  OR oSubform.name[1]

                   Now the add table are working fine.

                    But this create an issue when deleting the table from the same subform.

                     If i click the "Delete table at "table_subform[1] - which index is used to create the rest of the tables" , it delete      table_subform[2],table_subform[3] in sequence.

----------------------------------------------------------------------------------------------------------------------------------------

Anyone have any solution for this ????

0 Replies

Avatar

Level 10

The removeInstance method requires an index so that it knows which subform to remove. If the button that you are pressing is part of the subform that you are removiing you can use the this.parent.index to return the index that you are on and as such the appropriate subform can be removed. Depending on your structure you may need to use the parent keyword to get back the level that you need. In many cases it gets confusing to know which subform is repeating so you can add this javascript command to the enter event of a field in the subform.

app.alert(this.somExpression)

This command will show you the complete somExpression of the field and as such you will know the somExpression for the rest of the subform. You may need to click on the field in a couple of different rows to understand the pattern that is emerging. This command is only for debugging ...you woudl remove it after you figure out your issue.

Hope that helps

Paul