Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Spawn template page clears check box values

Guest
Dec 14, 2017 Dec 14, 2017

Hi,

I have a fillable form PDF with buttons at the bottom of certain page that add a duplicate blank form page (giving the user more room to add information). The template page has both text fields and check boxes.

When using the button, the additional page is added fine, but the check boxes on the first page are all cleared when they shouldn't be.

Any thoughts as to why this might be happening? This is the Javascript code I am using.

var expTplt = getTemplate("TemplatePage");

expTplt.spawn({nPage: pageNum + 1, bRename: true, bOverlay: false});

Thanks!

TOPICS
Acrobat SDK and JavaScript , Windows
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 15, 2017 Dec 15, 2017

That's indeed strange. The problem is usually the other way around, ie the fields in the spawned page retain the values from the template page and need to be reset.

Do you have some kind of script that checks (or unchecks) these check-boxes anywhere in your file? Maybe it gets triggered when the page is spawned...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 15, 2017 Dec 15, 2017

There's a button to "Clear Form". It's not using Javascript, it's just set to Reset a Form.

The problem you mentioned, that the page usually retains the fields in the template....I avoided that by doing the following:

1) I added the page as a template

2) spawned a page

3) hid the template page

So the button is actually on both the template and spawned pages. That way you can add as many pages as you need. Is there something there that could be the source of the issue?

What I am finding as I'm playing with it more:

1) the first spawned page is on page 4, and has the button at the bottom to add another page. Because this page is a spawned page rather than the template itself, all of the checkbox fields are in the format P4.fieldname.checkbox#0, or something similar.

2) when you click the button to add a page, it adds a page directly afterwards (so page 5), but the fields are formatted like P4.fieldname.checkbox#1. Why would it use P4 if it's page 5?

3) spawning an additional page (page 6) gives field names like P5.fieldname.checkbox#0.

Could this be part of the problem?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 15, 2017 Dec 15, 2017

Could be. If you're spawning to the same page number they you will get duplicate field names, which might cause a reset.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 15, 2017 Dec 15, 2017

What is the code that you are using to spawn the pages?

It appears you are spawning 2 pages so one needs to make sure the nPage parameter is correct for each of the pages being spawned. It can not have the same value fore each page being spawned.

It might be helpful to see the actual code being run and possibly even a link to working sample of the form.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 15, 2017 Dec 15, 2017

I think the spawn code on the template page buttons is using the same page number as the current page.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 15, 2017 Dec 15, 2017

One needs to be aware that page numbering within the PDF is dynamic or as pages are added the page number could be changed and the number of pages changes even during the running of the script. This needs to taken into consideration within the script that spawns the pages. This will automatically be taken care of if the "numPages" property is used and not using a fixed number or a value taken from the numPages at an earlier line of code within the script.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 05, 2018 Jan 05, 2018

Thanks for all of your answers so far!

I thought the "nPage: pageNum + 1" part in the code meant that it was supposed to put the spawned page directly after the current page.

So if the template is page 3, a spawned page is on page 4, and you click the button on the spawned page on page 4....then it would pawn the same template page on page 4+1 = 5. This is what I see when I spawn multiple page (as I mentioned above), but the issue seems o be that the field renaming doesn't match with the spawned page numbers (ex. P4.fieldname on page 5). Am I interpreting that incorrectly?

What would the code look like if I used numPages? What does that do differently?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 05, 2018 Jan 05, 2018
LATEST

You are correct in your thinking.  And it is possible there is a bug in Acrobat, but it is more likely that the page spawning is getting out of sync with the pages.  This could happen if the current page "this.pageNum" is not the last page spawned, or a page is deleted. One possible solution would be to always add pages to the end of the PDF. So you'd use "nPage:this.numPages"  to place the spawned page.  numPages is always one number past the end of the file.

You can check the value of the page number being spawned by inserting "console.println" statements in you code. This will verify that the code is in fact doing what you think it is.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines