Expand my Community achievements bar.

SOLVED

Need to add rows to dynamic form based on numeric field

Avatar

Level 2

I have designed a form based on the example in the Terry book of using javascript with addInstance to make a button add a row to a table.

Works fine for me however I am trying to morph the form a little so that instead of allowing the user to click the add row button I have them enter a numeric value in a field and then call addInstance to create the correct number of rows. The numeric field is on page 1 of the form and is called NumberStudents and is bound as Global.  I tried to have it call addInstance to add rows but cannot get it to work.  Suggestions appreciated. Newbie thanks.

1 Accepted Solution

Avatar

Correct answer by
Level 10

The only mistake you did was missing rawValue next to the control name "NumberOfCards"

var i=0;

for

(i=2;i<=NumberOfCards.rawValue;i++){

     Roster.Page2.StudentSubform.Table1._Row1.addInstance(1);

     xfa.form.recalculate(1);

}

If your requirement is add the number of rows based on the value entered in the numeric field, you can so by calling the setInstances method. This way you do not need to loop thru the number and use the addInstance every time.

Roster.Page2.StudentSubform.Table1.Row1.instanceManager.setInstances(5);

xfa.form.recalculate(1);

or

Roster.Page2.StudentSubform.Table1._Row1.setInstances(5);

xfa.form.recalculate(1);

Thanks

Srini

View solution in original post

7 Replies

Avatar

Level 10

goto acrobat.com website
login with your Adobe login/password.
In Actions you will find Upload. Select your form and upload.
After uploading, select form name in All Files section and right click and select share.
Check the checkbox "Allow anyone with a link to view this document".
Copy the URL link and post it in the forum.

Thanks
Srini

Avatar

Correct answer by
Level 10

The only mistake you did was missing rawValue next to the control name "NumberOfCards"

var i=0;

for

(i=2;i<=NumberOfCards.rawValue;i++){

     Roster.Page2.StudentSubform.Table1._Row1.addInstance(1);

     xfa.form.recalculate(1);

}

If your requirement is add the number of rows based on the value entered in the numeric field, you can so by calling the setInstances method. This way you do not need to loop thru the number and use the addInstance every time.

Roster.Page2.StudentSubform.Table1.Row1.instanceManager.setInstances(5);

xfa.form.recalculate(1);

or

Roster.Page2.StudentSubform.Table1._Row1.setInstances(5);

xfa.form.recalculate(1);

Thanks

Srini

Avatar

Level 2

I want to do something like this - however - is there a way to not have the page 2 "student" rows disappear - but create a new page, instead????  Also, why did you create page 3??   If I am looking at it correctly - page 3 is like page 2 but with no Add student button??

Thanks

Christina in Tucson