Expand my Community achievements bar.

SOLVED

Repopulating subform instances based on DDM value

Avatar

Level 1

I am testing a portion of my form which allows a user to select a value from a drop down menu (1-9). The value that the user chooses creates that many subform instances below the DDM. The following code is located in the drop down menu:exit and it works correctly:

var numStr = this.rawValue;

for (var i=1; i <= numStr; i++) {

page1._subform.addInstance();

}

Now, I want to make it so that if a user orginally picked 5 (5 subform intances appear) but changes the value to 3, the form repopulates to 3 subform instances. Currently, the new value just adds the number of subform instances to the amount which are displayed. Using the above example, if the user originally picked 5, then changed to 3, it creates 8 instances instead of repopulating to 3.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

Prior to adding the instances, you can set the number of instances to zero. Have this line first:

page1._subform.setInstances(0);

Niall

View solution in original post

4 Replies

Avatar

Correct answer by
Level 10

Hi,

Prior to adding the instances, you can set the number of instances to zero. Have this line first:

page1._subform.setInstances(0);

Niall

Avatar

Level 10

And you can use .setInstances in place of your loop:

page1._subform.setInstances(this.rawValue);

I've used .count for this too, Niall do you know if there's any difference in using setInstances over count?

page1._subform.count = this.rawvalue;

Avatar

Level 10

Hi Jono,

They both achieve the same ends. I have tended to limit count when looking for the number of instances only. Whereas the setInstances specifically sets the number of instances.

It seems setInstances goes back to XFA 2.1, whereas count is more modern at XFA 2.5.

Cat lovers look away: "There's more than one way to skin a cat"

Niall