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

adding a specific number of subforms based on numerical field data

Avatar

Level 4

I would like to add a specific number of subforms based on what a user enters into a numerical field. So, if the user puts in 4, four instances of the subform would be created. How can I do that?

6 Replies

Avatar

Level 4

I guess I should have waited to post. I figured this part out.

I created a button with this in the click event:

xfa.form.assessment.Questions.Questionset.Questiondetail.FIBdetail._blanks.count=assessment.Questions.Questionset.Questiondetail.FIBdetail.totalblanks.rawValue

So, now what I want to do is number each instance. I have this in the initialize event of the subform:

var cnt = assessment.Questions.Questionset.Questiondetail.FIBdetail.blanks.instanceIndex + 1;
xfa.resolveNode("assessment.Questions.Questionset.Questiondetail.FIBdetail.blanks.blanks.caption.value.#text").value = cnt + ":";

However, they are all numbering as "1" right now.

What can I do to make them number sequentially?

Avatar

Level 10

Using javascript put the following on the calculate event of the field you want the number displayed in:

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

Avatar

Level 4

Thanks for your help. I need the value to end up in the caption field. Can I just change it from this.rawValue to this.caption?

Also, I found out that this code:

xfa.form.assessment.Questions.Questionset.Questiondetail.FIBdetail._blanks.count=assessment.Questions.Questionset.Questiondetail.FIBdetail.totalblanks.rawValue

only works for the first instance of the subform _Questiondetail. There are likely to be multiple instances. How do I make it work for subsequent instances?

Avatar

Level 10

No, unfortunately there's no such thing as "this.caption" – that'd be too easy!

I think if you add it to where you've got cnt + ":"; it should work.

xfa.resolveNode("assessment.Questions.Questionset.Questiondetail.FIBdetail.blanks.blanks.caption.value.#text").value = this.parent.index+1 + ":";

Not sure what you're trying to do there. Are you trying to count the instances? Not sure how to do that maybe someone else here knows.

Avatar

Level 4

I want the specific number of the subform xfa.form.assessment.Questions.Questionset.Questiondetail.FIBdetail._blanks to appear based on what the user enters into assessment.Questions.Questionset.Questiondetail.FIBdetail.totalblanks.rawValue.

But there are going to be multiple instances of the subform assessment.Questions.Questionset.Questiondetail

Right now the code only works in the first instance.

Avatar

Level 4

I figured this out so I wanted to post my form in case anyone is having the same problem.

Here is the code I used on the click event of a button to create the specified number of subform instances.

xfa.resolveNode("xfa.form.assessment.Questions.Questiondetail[" + (xfa.form.assessment.Questions._Questiondetail.count - 1) + "]").FIBdetail._blanks.count=xfa.resolveNode("xfa.form.assessment.Questions.Questiondetail[" + (xfa.form.assessment.Questions._Questiondetail.count - 1) + "]").FIBdetail.totalblanks.rawValue