Expand my Community achievements bar.

SOLVED

Buttons to add and/or delete subforms

Avatar

Level 2

Hi

Have come to a halt over a subform issue.

Rest of form is working fine and I have one subform with an add and delete button which works fine

Second subform, using same script, will add but not delete.

As it's too complex to explain and can't upload here any more form is avalable at:

www.type-high.co.uk

Follow the doewnloads link to get the PDF

Thanks

Graham

1 Accepted Solution

Avatar

Correct answer by
Level 10

Place the following code in your "Delete Picture Place Holder" button's click event and comment out the existing code..

if (form1.OpportunitySubform.PicandTextSubform.PicSubform.instanceManager.count == 1) {
xfa.host.messageBox("The minimum allowable number of subforms is 1. You cannot remove any more subforms.", "Warning", 3);
}
else {
// This script uses the removeInstance() method to remove the last instance of the
// Subform2 object (represented by nNumSub) contained in Subform1.
form1.OpportunitySubform.PicandTextSubform.PicSubform.instanceManager.removeInstance(this.parent.index);
}

Similarly on the "Add Picture" Button's click event:

if (form1.OpportunitySubform.PicandTextSubform.PicSubform.instanceManager.count<5) {
// This script uses the addInstance() method to add a new instance of the
// Subform2 object contained in Subform1.
form1.OpportunitySubform.PicandTextSubform.PicSubform.instanceManager.addInstance(1);
}
else{
xfa.host.messageBox("The maximum allowable number of subforms is 5. You cannot add any more subforms.", "Warning", 3);
}

Thanks

Srini

View solution in original post

9 Replies

Avatar

Level 7

To be able to duplicate a subform, it needs to be a positioned subform wrapped in a flowed subform. The one that's not working is a flowed subform. It's not as simple as just wrapping the entire opportunity subform in a flowed subform and setting the opportunity subform to positioned, but that's where you'll need to start.

Regards,

djaknow

Avatar

Level 2

Forms are duplicating fine.

When I try to use 'delete picture placeholder' button I get an error message

Same code works fine on 'delete Opportunity' button

Avatar

Level 7

Now that's interesting. I didn't know you could duplicate a flowed subform. In any case, this script:

if (PicSubform.nodes.item(nCount).className == "subform") {

     nNumSub = nNumSub + 1;

}

is not incrementing the nNumSub variable. When I print the nNumSub value to a message box it returns -1 every time. Does that help?

Avatar

Level 7

I'm thinking you'd be better off to just use the count method to track the number of PicSubform instances, as in:

var nNumSub = PicSubform.instanceManager.count;

if (nNumSub < 1){

<error message here>

}

Avatar

Level 7

I found something else as well. This statement:

form1.PicSubform.instanceManager.removeInstance(nNumSub);

wasn't working to remove the extra subform instance. Since you're referencing the instanceManager from inside the subform, you don't need the form1 at the beginning of the statement. When I got rid of it and tracked the number of subforms with the count method, the form removes the instance correctly.

Avatar

Level 2

Still can't get that to work here.

Could you possibly email the file

graham@type-high.co.uk

Thanks

Avatar

Correct answer by
Level 10

Place the following code in your "Delete Picture Place Holder" button's click event and comment out the existing code..

if (form1.OpportunitySubform.PicandTextSubform.PicSubform.instanceManager.count == 1) {
xfa.host.messageBox("The minimum allowable number of subforms is 1. You cannot remove any more subforms.", "Warning", 3);
}
else {
// This script uses the removeInstance() method to remove the last instance of the
// Subform2 object (represented by nNumSub) contained in Subform1.
form1.OpportunitySubform.PicandTextSubform.PicSubform.instanceManager.removeInstance(this.parent.index);
}

Similarly on the "Add Picture" Button's click event:

if (form1.OpportunitySubform.PicandTextSubform.PicSubform.instanceManager.count<5) {
// This script uses the addInstance() method to add a new instance of the
// Subform2 object contained in Subform1.
form1.OpportunitySubform.PicandTextSubform.PicSubform.instanceManager.addInstance(1);
}
else{
xfa.host.messageBox("The maximum allowable number of subforms is 5. You cannot add any more subforms.", "Warning", 3);
}

Thanks

Srini

Avatar

Level 2

Thanks Srini - superb

These forms are distributed with Acrobat Reader Rights to be saved individually.

If a flowed form goes over a page break and you return to edit that field it displays both the scrolling text box and the page box as well as buttons appearing under the text.

This makes it very difficult to see where you are in the document.

Do you know if this is just a Reader 'thing' or is there a way round it.

Thanks again

Graham

Avatar

Level 10

I feel it is a Reader thing.. Because when you check the check box "Allow Page breaks with in Content", if the text inside a TextField overflows to next page, if you click inside the TextField, the Reader will place the scrollbars automatically.

Hope this helps..

Thanks

Srini