Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.
SOLVED

Delete Page Button

Avatar

Former Community Member

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.

1 Accepted Solution

Avatar

Correct answer by
Level 10

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

View solution in original post

13 Replies

Avatar

Correct answer by
Level 10

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

Avatar

Former Community Member

Thanks a lot for the answer on this.  This was a big help and solved the issue

I was having.

Avatar

Former Community Member

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?

Avatar

Level 10

Hi,

Yes, if you go to the File > Form Properties > Defaults and look for the preserve script changes, make sure Automatic is selected:

LCDES2 properties preserve script changes.png

Hope that helps,

Niall

Avatar

Former Community Member

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.

Avatar

Level 10

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

Avatar

Former Community Member

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?

Avatar

Level 10

Hi,

  1. Go to https://acrobat.com
  2. Sign up for a free account
  3. Upload the file
  4. You will be prompted if you want to share it - click share
  5. At the bottom of the screen click publish, then confirm.
  6. At the bottom of the screen a published menu will appear and there you will see a 'copy link'
  7. Click the copy link and post the URL to this thread.

Safari2.png

Niall

Avatar

Former Community Member

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.

https://acrobat.com/#d=O5pbNuVmZffxpQudMyH25Q

Avatar

Level 10

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:

  1. The form is quite complex and you have used multiple objects unnecessarily. Acrobat now has to render multiple separate objects to display one interactive element of the form. This is taking up resources, for example in the US_ARMYICV checkboxes you are using four rectangles with 0.01in widths to form a box, this is very difficult to layout and maintain. You can change the visual appearance of the checkbox in the Object > Field tab under the appearance dropdown. Currently you have 'none' but you can select one of the built in appearances 'solid square' or 'sunken square' or even a custom appearance. This will allow you to delete the rectangle and make it much easier to set out your form as you will not have to try and align multiple objects on the form.
  2. You have also used lines instead of rectangles or even grouping elements in subforms and giving the subform a border. This is also decreasing performance during render.
  3. Getting to the problem of the exponentially repeating Page1, you have multiple objects with the same name. While this generally should not cause a problem, I believe that it does affect repeating objects.
  4. In Page1 you have three 'Table1' with the same name. Each Table1 has two HeaderRow and no BodyRow. The last Table1[2] also has an untitled Table Section with no content.
  5. The ECONO object was named "ECONO." with a full stop, this may cause problems because a full stop is used to separate objects when creating a reference. I have renamed all of these to "ECONO"
  6. You have some script on Page1 that does not make sense, for example the enter event script in T193. For the time being I have commented out some of the script that does not do anything at the moment.

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

Avatar

Former Community Member

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?

Avatar

Level 10

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