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

How do I have calculated scripts adjust when I spawn a new page from a template?

New Here ,
Jul 02, 2018 Jul 02, 2018

Copy link to clipboard

Copied

I have created a form, am able to use a calculated script to hide & unhide certain fields when a certain action is performed from a dropdown box. I have added a button to spawn from a template, but I cannot figure out how to have the calculated scripts modify themselves with the new field names.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

883

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

LEGEND , Jul 04, 2018 Jul 04, 2018

The parameter for the "getField" method is the name of the field for which you want the JavaScript field object. The field name is just a string of characters. This string can be a quoted string, a variable with the a value of the string name, a result of some JavaScript code that results in a string value, or a combination of these.

The first snipet of code uses the "event.target.name" property to obtain the name of the field which should be from a form field that was renamed during the spawnin

...

Votes

Translate

Translate
Community Expert ,
Jul 02, 2018 Jul 02, 2018

Copy link to clipboard

Copied

The scripts won't modify themselves. You need to write them in advance taking this situation into account, and since the names of the spawned fields are predictable you can adjust the scripts to use the base name of the field that's being calculated (via event.source.name) to figure out the names of the other fields you're interested in.

Votes

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
New Here ,
Jul 03, 2018 Jul 03, 2018

Copy link to clipboard

Copied

How do I accomplish this? I have seen threads stating that I need to get, here is a sample of one:

var cPreFix = "";

// get prefix elements for spawned pages;

var aFieldName = event.target.name.split(".");

if(aFieldName.length > 2)

{

// first 2 elements of name array makeup the prefix for fields on a spawned page;

cPreFix = aFieldName[0] + "." + aFieldName[1] + ".";

}

Here is a partial of my script:

if(this.getField("Wave Type").value=="THROUGH TRANSMISSION")
{this.getField("MHz-1").display=display.visible;
this.getField("MHz-2").display=display.visible;
this.getField("SN-1").display=display.visible;
this.getField("SN-2").display=display.visible;
this.getField("UT-2").display=display.hidden;
this.getField("SN-4").display=display.hidden;
this.getField("Blank-1").display=display.hidden;
this.getField("Blank-2").display=display.visible;
this.getField("Blank-3").display=display.visible;
this.getField("Blank-4").display=display.visible;}

I have this in a drop down list.

I do not understand how to incorporate the sample from the other into mine.

Thank you,

Votes

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
LEGEND ,
Jul 03, 2018 Jul 03, 2018

Copy link to clipboard

Copied

You have gotten the prefix for the spawned fields into a variable but you have not added that prefix variable to the specific field names strings.

Votes

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
LEGEND ,
Jul 04, 2018 Jul 04, 2018

Copy link to clipboard

Copied

The parameter for the "getField" method is the name of the field for which you want the JavaScript field object. The field name is just a string of characters. This string can be a quoted string, a variable with the a value of the string name, a result of some JavaScript code that results in a string value, or a combination of these.

The first snipet of code uses the "event.target.name" property to obtain the name of the field which should be from a form field that was renamed during the spawning code. So the variable "cPreFix" has the prefix items added by the spawning rename. One can the concatenate this variable to the quoted field name to create the field names on the spawned page.

var cPreFix = "";

// get prefix elements for spawned pages;

var aFieldName = event.target.name.split(".");

if(aFieldName.length > 2)

{

// first 2 elements of name array makeup the prefix for fields on a spawned page;

cPreFix = aFieldName[0] + "." + aFieldName[1] + ".";

}

if(this.getField(cPreFix + "Wave Type").value=="THROUGH TRANSMISSION")
{this.getField(cPreFix + "MHz-1").display=display.visible;
this.getField(cPreFix + "MHz-2").display=display.visible;
this.getField(cPreFix + "SN-1").display=display.visible;
this.getField(cPreFix + "SN-2").display=display.visible;
this.getField(cPreFix + "UT-2").display=display.hidden;
this.getField(cPreFix + "SN-4").display=display.hidden;
this.getField(cPreFix + "Blank-1").display=display.hidden;
this.getField(cPreFix + cPreFix + "Blank-2").display=display.visible;
this.getField(cPreFix + "Blank-3").display=display.visible;
this.getField(cPreFix + "Blank-4").display=display.visible;}

Votes

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
New Here ,
Jul 04, 2018 Jul 04, 2018

Copy link to clipboard

Copied

LATEST

That helped me through what I needed to accomplish. Thank you very much!

Daniel

Votes

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 Expert ,
Jul 03, 2018 Jul 03, 2018

Copy link to clipboard

Copied

To the degree possible, use the event object when calculating fields that are on page templates, that way you don't need to guess what the name of the field will be.

You can get the name of any spawned field using event.target.name then you can use the name to figure out the other calculations.

Votes

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