Copy link to clipboard
Copied
I have a form with a template for spawned pages. On the tenplate there is a "delete this page" button so users can delete spawned pages. However, I also have a field, "Pages" that shows the page number on each page using the calculation script below:
event.value = (event.target.page+1) + " of " + this.numPages;
I would like to reset "Pages" when a page is deleted, but realized that adding this as a function of the delete button will not work - can't call a script from a deleted page.
Is there any other ways to do this?
Copy link to clipboard
Copied
Why did you add this condition to the code?
Attached is the file I created that demonstrates how it can work. There is one problem with it, though, that if you remove one of the pages in the middle of the file and then spawn a new one the field names on that new page will not be unique and it will also break the page numbering field, but there's no real solution for that. You have to only delete the last page for it to work correctly.
Copy link to clipboard
Copied
After deleting the page you can update the fields by calling this command:
this.calculateNow();
Copy link to clipboard
Copied
Thank you, I was looking at using this.calculateNow(); but I don't know where to call it from because I need to caclculate after the page has been deleted. So, it can't come from the delete button.
In the document javascript, is there a way to express the condition "if a page has been deleted"? I tried if (this.numPages--1); but Acrobat didn't like it.
Copy link to clipboard
Copied
Did you try it? I think it should work.
Copy link to clipboard
Copied
Works fine for me.
Copy link to clipboard
Copied
Really? I'm getting "Syntax error missing ) after condition 1"
Copy link to clipboard
Copied
Here's what I'm entering:
if (this.numPages--1); {
this.calculateNow();
}
Copy link to clipboard
Copied
Why did you add this condition to the code?
Attached is the file I created that demonstrates how it can work. There is one problem with it, though, that if you remove one of the pages in the middle of the file and then spawn a new one the field names on that new page will not be unique and it will also break the page numbering field, but there's no real solution for that. You have to only delete the last page for it to work correctly.
Copy link to clipboard
Copied
Thanks for sending that, I played around with it and I see what you're saying about the page numbering.
I added the condition because I was trying to say, at the document level "IF total page numbers decrease by 1, then calculate now." I don't think I'm doing it right though, or maybe it isn't possible?
Copy link to clipboard
Copied
You don't need that. You know there are less pages because you deleted one yourself in the previous line of code...
Find more inspiration, events, and resources on the new Adobe Community
Explore Now