Spawning Refreshed Dynamic Templates

New Here ,
May 16, 2019

Copy link to clipboard

Copied

I am trying spawn (unlimited times) two blank template pages (upon push of a button) that still leverage the custom field-level javascript that has been developed on the page. Using the following script, it will spawn each template (refreshed), but the field-level custom javascript does not work. Is there a way I can add code to each javascript that will dynamically update the field header when spawned?

Code is as follows:

var NextPageIndex = this.pageNum + 1;

if (event.target.value == "Off")

{

    this.deletePages({nStart:NextPageIndex, nEnd:NextPageIndex});

}

else

{

    var a = this.getTemplate("User_Page2");

    a.spawn(NextPageIndex, true, false);

    var PageName = "P"+NextPageIndex;

    this.resetForm(PageName);

    var a = this.getTemplate("User_Page1");

    a.spawn(NextPageIndex, true, false);

    var PageName = "P"+NextPageIndex;

    this.resetForm(PageName);

}

RefreshPageNumbers();

TOPICS
Acrobat SDK and JavaScript, Windows

Views

146

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

Spawning Refreshed Dynamic Templates

New Here ,
May 16, 2019

Copy link to clipboard

Copied

I am trying spawn (unlimited times) two blank template pages (upon push of a button) that still leverage the custom field-level javascript that has been developed on the page. Using the following script, it will spawn each template (refreshed), but the field-level custom javascript does not work. Is there a way I can add code to each javascript that will dynamically update the field header when spawned?

Code is as follows:

var NextPageIndex = this.pageNum + 1;

if (event.target.value == "Off")

{

    this.deletePages({nStart:NextPageIndex, nEnd:NextPageIndex});

}

else

{

    var a = this.getTemplate("User_Page2");

    a.spawn(NextPageIndex, true, false);

    var PageName = "P"+NextPageIndex;

    this.resetForm(PageName);

    var a = this.getTemplate("User_Page1");

    a.spawn(NextPageIndex, true, false);

    var PageName = "P"+NextPageIndex;

    this.resetForm(PageName);

}

RefreshPageNumbers();

TOPICS
Acrobat SDK and JavaScript, Windows

Views

147

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
May 16, 2019 0
Adobe Community Professional ,
May 16, 2019

Copy link to clipboard

Copied

You haven't shown any of the field level scripts and even said anything about what they do, but I imaging they use the names of fields on the page. As you probably know, the names of the fields change on each of the spawned pages. You didn't say, but I imagine this is your problem, i.e. your scripts are written for fields names that don't exists on the page?

So the solution is to create the needed field names dynamically, from the name of the element on which the script is acting.

For example say you have field A, B, and C. Where the calculation script for C is

event.value = this.getField("A").value + this.getField("B").value.

The new tempate name for C is something like "User_Page1.Page#.C".   All you need to know that everything in front of "C" is the prefix for all fields on the page. So you create new field names like this.

var aParts = event.targetName.split(".");

aParts.pop();

var cPrefix = aParts.join(".");

Now you can use this prefix to get the field names specific to the page. Just add this code to the top of each field script. and change the get field to

this.getField(cPrefix + ".BaseFieldName")

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
Reply
Loading...
May 16, 2019 0
New Here ,
May 16, 2019

Copy link to clipboard

Copied

Mostly the scripts trigger other fields to show/hide based on checkboxes, with the occasional alert box.

Your assumption was spot on. I tried your script with no such luck. I was trying a similar script as follows:

var FieldName = this.event.target.name;

if (FieldName.substr(3,8) == "Section3")

{

var PageHeader = FieldName.substr(0,16);

}

else

{

var PageHeader = "";

}

if (this.getField(PageHeader+"Field X").value == "Other")

{

this.getField(PageHeader+"Field Y").display = 0;

}

else

{

this.getField(PageHeader+"Field Z").display = 1;

}

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
Reply
Loading...
May 16, 2019 0
Adobe Community Professional ,
May 16, 2019

Copy link to clipboard

Copied

My script works perfectly. And it works generically for any template or field name.

What about it wasn't working when you added it to your script. Were there error messages reported in the console window? What debug did you do?

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
Reply
Loading...
May 16, 2019 0
New Here ,
May 21, 2019

Copy link to clipboard

Copied

The error that I am getting is that the field is not defined.

Based on your script, I have modified a sample field-level script as follows:

var aParts = event.targetName.split(".");

aParts.pop();

var cPrefix = aParts.join(".");

if (this.getField(cPrefix+"User1_Wire_ApprovalRelease").value == "Yes")

{

this.getField(cPrefix+"User1_Wire_LowerLimit_Text").display = 0;

this.getField(cPrefix+"User1_Wire_Lower Limit").display = 0;

this.getField(cPrefix+"User1_Wire_UpperLimit_Text").display = 0;

this.getField(cPrefix+"User1_Wire_Upper Limit").display = 0;

}

else

{

this.getField(cPrefix+"User1_Wire_LowerLimit_Text").display = 1;

this.getField(cPrefix+"User1_Wire_Lower Limit").display = 1;

this.getField(cPrefix+"User1_Wire_UpperLimit_Text").display = 1;

this.getField(cPrefix+"User1_Wire_Upper Limit").display = 1;

}

Please let me know if you can find the root cause of the issue and why it is not working. Thanks.

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
Reply
Loading...
May 21, 2019 0
Adobe Community Professional ,
May 21, 2019

Copy link to clipboard

Copied

The "." is missing at the front of the field name. All the name parts are separated by a ".". You can see this in my code sample.

So the it should look like this

this.getField(cPrefix+".User1_Wire_LowerLimit_Text").display = 0;

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
Reply
Loading...
May 21, 2019 0
New Here ,
May 21, 2019

Copy link to clipboard

Copied

Thanks Thom! That worked!

One last question: some of the checkboxes on the templates will be triggered by the static pages prior. Is there a way to the checkboxes on the dynamic pages from the static pages (in terms of show/hide) for checkboxes that have not yet been spawned (on a potentially unlimited number of pages)?

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
Reply
Loading...
May 21, 2019 0