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

Anticipating dynamic field names

Engaged ,
Jun 21, 2016 Jun 21, 2016

Dynamic field names on pages spawned from templates begin with "P1," "P2," etc. based on where the page is spawned.

How can I write my code for buttons and other scripts if I don't know in what order templates will be spawned?

I'm creating a PDF containing several templates to be spawned as needed and, often, multiple times.

I have fields that need to communicate with other fields across pages but, even fields on the same page won't be able to communicate because a button using getField won't know that a field will be called "P4.templateName.fieldName"

Is it possible to have a script that executes when a page is spawned, assigning that "P4" or whatever to a variable that I can use in the other scripts?

Is it possible to change the naming convention for dynamic fields?

TOPICS
Acrobat SDK and JavaScript , Windows
602
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

correct answers 1 Correct answer

LEGEND , Jun 21, 2016 Jun 21, 2016

See A Lesson in Template​ for an explanation of the naming convention.

It is possible when there is a defined naming convention that one can compute the names of fields once one gets any field that follows the naming convention. One can get the name of the of a field that has focus using "event.target.name". if this field was renamed as part of the spawning of the page, it will have 2 hierarchical levels of the format "P#." and "[template name]". So if one has a field name of "Amouint" on the tem

...
Translate
Community Expert ,
Jun 21, 2016 Jun 21, 2016

There is a script that is being executed when a page is spawned, and that is your script that is calling Template.spawn(). You know what parameters you've provided to the spawn method, and therefore you also know what page number the newly spawned page has, so you can save that information right after you called the spawn method.

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 ,
Jun 21, 2016 Jun 21, 2016
LATEST

See A Lesson in Template​ for an explanation of the naming convention.

It is possible when there is a defined naming convention that one can compute the names of fields once one gets any field that follows the naming convention. One can get the name of the of a field that has focus using "event.target.name". if this field was renamed as part of the spawning of the page, it will have 2 hierarchical levels of the format "P#." and "[template name]". So if one has a field name of "Amouint" on the template named "Invoice" and that template is used to spawn a new page after the first page of the form with the fields being renamed, the name for that field will be "P1.Invoice.Amount". Now usi

ng the "event.target.name" in say the calculation field, one use a script like:

// get the focused field name;

var cNameField = event.target.name;

to get the field's name. Now can split the nirearchical field name into an array using the "split()" method. Sincet each level of the name is seprated by a ".", using that character for the split method will create an array where each level of the name is a element in the array;

So we can now have the code:

// get the focused field name;

var cNameField = event.target.name;

// split the field name into an array;

var aNameField = cNameField.split(".");

// list the levels of the name field;

console.show();

console.clear);

for(var I = 0; I < aName.length; I++)

{

console.println(I + ": " +aNameField);

}

So the console should now display:

0: P1

1: Invoice

2: Amount

Element 0 of the array is the "P#" value and element  1 is the template name. With these values one can compute the name of any field renamed on that spawned page.

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