Inserted pages into existing form, now java references to fields on new pages won't work

Community Beginner ,
Apr 25, 2022 Apr 25, 2022

Copy link to clipboard

Copied

I have an existing interactive form that I built on Acrobat DC. It was originally 23 pages and had several custom javascript calculations and hidden/visible fields based off of checkboxes or radio buttons. I'm new to javascript, but after a lot of reading, I had this working really well. However, I needed to add 3 new pages to the document to accomodate some company paperwork changes. I added these 3 pre-built pages right before the last page of the document using the "organize pages" tool. They are not spawned pages. Now, when I try to reference fields on these new pages via javascript it's as if they do not exist. I don't get error messages, but nothing happens either. Additionally, the one pre-existing last page, which follows the new pages, is also behaving badly. Any pre-existing references to the fields on that page work fine, but any new references are acting as if it doesn't exist either. These aren't complex scripts, and I've looked at them a millions times to verify accuracy of naming, etc. For example my validation script on a dropdown on a pre-existing page is this:

if (event.value == "Y")
{
this.getField("cprent").value = "Yes";
this.getField("cpet").value = "Yes";
this.getField("prent").display = display.visible;
this.getField("p_prent").display = display.visible;
}
else
{
this.resetForm("cprent");
this.resetForm("cpet");
this.resetForm("prent");
this.getField("prent").display = display.hidden;
this.getField("p_prent").display = display.hidden;
}

This script works perfectly. Below is the script with the new fields on the new pages added. The existing script continues to work correctly, but nothing happens with the new lines of script.

if (event.value == "Y")
{
this.getField("cprent").value = "Yes";
this.getField("cpet").value = "Yes";
this.getField("prent").display = display.visible;
this.getField("p_prent").display = display.visible;
this.getField("pg_identify").display = display.hidden;
this.getField("pg_animal").display = display.hidden;
}
else
{
this.resetForm("cprent");
this.resetForm("cpet");
this.resetForm("prent");
this.getField("prent").display = display.hidden;
this.getField("p_prent").display = display.hidden;
this.getField("pg_identify").display = display.visible;
this.getField("pg_animal").display = display.visible;
}

 This is just one example. Literally none of my references to fields on these new pages are working. Any insight would be super appreciated. I'm making myself crazy!

TOPICS
JavaScript , PDF forms

Views

74

Likes

Translate

Translate

Report

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

correct answers 1 Correct answer

Adobe Community Professional , Apr 26, 2022 Apr 26, 2022

If getField returns null it means the field can't be located. If you can see it, then it's probably corrupt.

Remove it, save the file under a new name, then close and re-open it and add it again.

Likes

Translate

Translate
Adobe Community Professional ,
Apr 25, 2022 Apr 25, 2022

Copy link to clipboard

Copied

Assuming "prent" is one of those new fields, what does running this code (from the JS Console) return?

 

this.getField("prent")

Likes

Translate

Translate

Report

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 Beginner ,
Apr 25, 2022 Apr 25, 2022

Copy link to clipboard

Copied

Sorry, I should have been more clear, but "prent" is an existing field and it returns "[object Field]" in the JS Console. If I run this.getField("pg_identify") it returns "null". For clarification, the new fields are "pg_identify" and "pg_animal". Interestingly, if I run this.getField("pg_animal") it also returns "[object Field]", but the script behavior doesn't work for this one either. Not sure why there's a difference here since it's the exact same field copied from other pages, but they've all been given unique names. Thanks in advance for your help!

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

If getField returns null it means the field can't be located. If you can see it, then it's probably corrupt.

Remove it, save the file under a new name, then close and re-open it and add it again.

Likes

Translate

Translate

Report

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 Beginner ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

LATEST

That worked perfectly. Thank you!

Likes

Translate

Translate

Report

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