I have a form that is being used predominantly in Adobe Reader and designed in Live Cycle Designer ES 8.2. I have created an "Insert Page" button which allows users to duplicate or insert an additional page if required. However, I want to have a button that allows the user to also delete the page if it is not necessary. The script for the button that I'm using to insert the page is as follows:
form1.Page5.Button1[0]::click - (JavaScript, both)
form1.Page5.instanceManager.addInstance()
I thought that perhaps I could just create another button and instead of "addInstance" I would just do "removeInstance" but that doesn't work so I wondered how this can be done?
Any help appreciated.
Solved! Go to Solution.
Views
Replies
Total Likes
Hi,
The addInstance has a parameter 'true' or '1', for example:
form1.Page5.instanceManager.addInstance(1);
This will add another instance of Page5.
Now when it comes to removeInstance, the parameter that you need is the instance number that you want to delete, based on the zero-numbering system. For example if there are three instances of Page5, these are numbered Page5[0], Page5[1] and Page5[2]. So this script will remove the first instance:
form1.Page5.instanceManager.removeInstance(0);
If there is a button on Page 5 to delete the page, then you could pass this.parent.index as the parameter.
form1.Page5.instanceManager.removeInstance(this.parent.index);
However bear in mind that if the button is in subforms you will need multiple 'parent' to get to Page5: this.parent.parent.parent.index.
Hope that helps,
Niall
Views
Replies
Total Likes
Hi,
The addInstance has a parameter 'true' or '1', for example:
form1.Page5.instanceManager.addInstance(1);
This will add another instance of Page5.
Now when it comes to removeInstance, the parameter that you need is the instance number that you want to delete, based on the zero-numbering system. For example if there are three instances of Page5, these are numbered Page5[0], Page5[1] and Page5[2]. So this script will remove the first instance:
form1.Page5.instanceManager.removeInstance(0);
If there is a button on Page 5 to delete the page, then you could pass this.parent.index as the parameter.
form1.Page5.instanceManager.removeInstance(this.parent.index);
However bear in mind that if the button is in subforms you will need multiple 'parent' to get to Page5: this.parent.parent.parent.index.
Hope that helps,
Niall
Views
Replies
Total Likes
Here is a sample: https://acrobat.com/#d=nyxBeJlwdS4ZY2euTZxMKA
Thanks a lot for the answer on this. This was a big help and solved the issue
I was having.
Views
Replies
Total Likes
I was able to get the "delete page" button to work but when I save the form, close it and reopen it, the form reverts to the original number of pages and I lose any additional pages or pages that were deleted are added back in. Any idea what might be causing this?
Views
Replies
Total Likes
Hi,
Yes, if you go to the File > Form Properties > Defaults and look for the preserve script changes, make sure Automatic is selected:
Hope that helps,
Niall
Thanks Niall, I checked this and it seems that "Preserve Script Changes" was already set to "automatic" so that doesn't seem to be the problem.
Views
Replies
Total Likes
Hi,
That's strange behaviour. It may be a pagination issue. Can you share the form? Maybe upload it on Acrobat.com and post the published link here.
Thanks,
Niall
Views
Replies
Total Likes
I would like to share the form but honestly, I'm not sure how to do that. Where exactly on adobe.com can I upload this to?
Views
Replies
Total Likes
Hi,
Niall
Views
Replies
Total Likes
Here's a link to the form. The other thing I noticed was that when I "insert page" on the first page, it creates an additional first page but when I save and close the file the additional first page is gone but there is an additional page 5. Any help you can provide would be appreciated.
Views
Replies
Total Likes
Hi,
First, you had set the max occurrence of Page1 to "1" in the Object > Binding tab. I have unchecked this. Next you had an additional script in the add page button that changed the max occurrence back to unrestricted, so I deleted this as well. Then in the delete button you had a line changing the max occurrence back to "1" again, so I deleted this as well.
For all of the repeating pages I have deselected the initial count = 1 and instead set the minimum count = 1. This will prevent the user from deleting ALL of the instances of a particular page.
Javascript syntax includes a semi colon (;) at the end of each line. I have inserted these for the add/delete buttons. Also the addInstance requires a parameter, either 'true' or '1'. Both true | 1 mean the same thing - merge the new instance with the data model.
The warnings tab had two warnings which I corrected.
NOW...
I have it working, however while Page1 repeats when add button is clicked, when the form is saved, closed and reopened the instances of Page1 increases exponentially. See this thread for details: Saving finished Form duplicates some subForms
I think that there are a couple of things going on here:
I have run the form through John Brinkman's excellent debugger (http://blogs.adobe.com/formfeed/2009/05/debug_merge_and_layout.html), which highlighted some errors. In particular objects that have the same name but are bound to data. Because you have little script in Page1, I have renamed objects with the same name.
I have tried to stop Page1 repeating exponentially on re-open but have failed.
Here is the form back to you: https://acrobat.com/#d=JyvEjsjhkmmF4pcmQgf5lQ
I believe that this random repeating behaviour is buggy and would recommend that you log it as a bug with Adobe.
Good luck,
Niall
Views
Replies
Total Likes
Thanks Niall, really appreciate your help on this. I took your suggestion and sent this to Adobe. They came back with the following, which seems to address the problem:
Mostly a bad case of no hierarchy in the form or the data. You can also get interesting results by doing the following
- open the file in Acrobat
- export the form data to an xml file
- import the exported data back into the form
Same problem – lots of extra bogus Page1.
It’s a combination of the fact that only two of the page subforms are bound and the page count/current page floating fields are also bound.
If you look at the exported data, it’s almost completely flat expect for Page2/Page6 where the data is nested. And the flat data includes multiple CurrentPage and PageCount elements.
So on reloading the data (either by import or by reopening the saved extra page pdf which now contains data), the data merge will generate a new first page for each CurrentPage/PageCount found as a child of the root element.
Can be cured in two ways
- unbind all the CurrentPage/PageCount floating fields – so no CurrentPage/PageCount elements in the data.
- Bind the 4 unbound page subforms – that way the wrapper Page1, Page2, Page3 etc.. elements will trigger the desired correct page creation.
The second is probably preferable. The first only cures it until someone adds two same named fields to different pages and then the same problem could occur.
***********************************************************************************************************************
I have another question with regards to this "delete page" funtionality. On the last two pages of the form I want the user to be able to delete those pages entirely if they are not required. In order to do this I've put the following script in the remove instance/delete page button:
form1.Page5.instanceManager.occur.min="0";
form1.Page5.instanceManager.removeInstance(0);
The binding tab for the form is set with an initial count of 0 and no minimum.
When I open this in reader it allows me to delete the page completely but then when I save and reopen the form, the page that was deleted is there again.
Any guesses on why this might be?
Views
Replies
Total Likes
Hi,
That's very interesting about the data binding set to 'none' for four of the pages. I have set the binding to 'name' and it works perfectly. That is an eye opener, as others have had problems with this.
In relation to the removeInstance, please note that the parameter is the instance number, which uses a zero-based numbering system.
I would recommend the following javascript in the click event of the delete button:
form1.Page1.instanceManager.removeInstance(this.parent.index);
this.parent.index will insert the current page instance number into the removeInstance. In the form I sent back, I had this script in the three delete buttons. Just copy these into your new version and amend the references.
I would not set the min occurrence, as this is set in the Object > Binding tab for each page at design time.
Good luck,
Niall
Views
Replies
Total Likes