Copy link to clipboard
Copied
I there a way to limit a mouse up Java Script action to run once reguardless of how many times a button is selected?
Currently, I am working on a fillable form that has a button that will add a page template to the end of the document. Here is the script that I am using:
if (event.target.value != "Off") {
this.getTemplate("Template Name").spawn(this.numPages, true, false) ;
}
This works exactly how I want it to, except I don't want more pages to be added if the end user clicks the "add" button more than once.
Thanks for help!
Copy link to clipboard
Copied
If this is the only template in the file you can limit the button by checking the number of pages in it.
Say there are 4 pages before you click it and 5 afterwards. You can then change your code to this to limit it to only spawn one page:
if (event.target.value != "Off" && this.numPages==4) {
this.getTemplate("Template Name").spawn(this.numPages, true, false) ;
}
Copy link to clipboard
Copied
No, this is not the only spawned template in this document. There are two separate places in the document allowing the user to spawn pages to include additional information needed ("Additional Info A" and "Additional Info B"). For each, once the person spawns one of the additional information pages, the spawned page is added to the end of the document and the field names are renamed so that the previously entered information will not duplicate. On the spawned template page (for this example, "Additional Info A") there is also button to add additional information (spawning another "Additional Info A") as well as a delete the page button in case they added the page in error.
All of this works fine when one template page is spawned per page/button click -- there is no duplication of entered fields and the user can delete a spawned page if it was added in error. But, for some reason, if the add additional info button is clicked multiple times (spawning multiple copies of the template) the info entered in the spawned page is duplicated on the added page AND the delete button no longer functions.
I thought that limiting the number of times a button could add a page to one would be a simple solution to this problem/glitch. Does this make sense?
Copy link to clipboard
Copied
The data is duplicated because it is copied from the original page, or because your spawning multiple pages to the same page number, which causes them to have the same field names. If it's the former then you just need to reset the fields on the spawned page after creating it. If it's the latter there's no easy solution, I'm afraid. This is what happens when you delete some spawned pages and then spawn more.
I don't see a reason the button should stop working. There might be an error in the code if it does.
Copy link to clipboard
Copied
Thanks for getting back to me. The issue was only happening when spawning multiple pages from a spawned page (everything worked fine spawning multiple pages from the original page). The problem, I discovered thanks to you, was because I had the template pages spawning from the original page(s) to the end of the document, but on the template page(s) I had the added template page(s) spawing to the next page.
This was done in an effort to keep the like template pages together.
Adding all the spawned pages to the end of the document (and not worrying about page order) eliminated the issues with the filled field duplication and the delete button functioning.
I'm not sure why the delete button stopped functioning when multiple pages were spawning to the same page number (when I was adding to next page rather than to end of document). Here is the action script I am using in the delete page button:
this.deletePages(event.target.page);
Do you see any errors in this code? Just curious--it works fine now that I am not adding the templates to the next page.
Thanks again for your time.