Query regarding creating an object or list from fields on page...

Explorer ,
Apr 19, 2018 Apr 19, 2018

Copy link to clipboard

Copied

Hi there,

I've been reading through an example in the Acrobat JS Scripting Reference regarding dialog creation.

Having worked forward from some code in the reference I've managed to generate the following dialog:

sample-dialog.jpg

I've been able to manipulate the example to list more 'options' in the text field and change some of the buttons etc. All works fine.

What I'm working towards is listing all the form fields, on a page, as the options in the list in the dialog above.

I've found a great function for creating a list of fields, on a given page, which works perfectly. It's really useful.

function getPageFields(doc, p) {

var fields = [];

for (var i=0; i<doc.numFields; i++) {

var f = doc.getField(doc.getNthFieldName(i));

if ((typeof f.page=="number" && f.page==p) || (typeof f.page!="number" && f.page.indexOf(p)>-1)) fields.push(f.name);

}

return fields;

}

getPageFields(this, 0);

Here's where my knowledge is limited. What I'd like to do is create an object (or list, here I'm not sure) from the 'fields list' so I can load it into part of the dialog creation as shown below:

loadDefaults: function (dialog) {

  dialog.load({

  subl:

  {

  "Option 1": +1,

  "Option 2": -2,

  "Option 3": -3,

  "Option 4": -4,

  "Option 5": -5,

  "Option 6": -6,

  }

  })

  }

I've been trying to use this article (https://acrobatusers.com/forum/javascript/dialog-load-list-box-default-value/​), and information from the Scripting Ref, to try and achieve this. As yet I've not succeeded.

Please can someone help me.

Thank you.

TOPICS
Acrobat SDK and JavaScript, Macintosh

Views

143

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 19, 2018 Apr 19, 2018
As you've seen, the input for a listbox on an Acrobat Dialogs is an object, where each member is the text displayed in the listbox, and the value is the selection. Here's some code that will create this input:var oLstFlds = {};for(var i=0;i< this.numFields:i++)   oLstFlds[this.getNthFieldName(i)]= -1;That's all you need, not "oLstFlds" is input for setting the values in the listbox.dialog.load({subl:oLstFlds});It's much easier to create complex dialogs with a dialog editor.  Like this one:ACRODIALOGS OVERVIEW...

Likes

Translate

Translate
Explorer ,
Apr 19, 2018 Apr 19, 2018

Copy link to clipboard

Copied

Kinda getting closer...

If I execute this:

function getPageFields(doc, p) {

var fields = [];

for (var i=0; i<doc.numFields; i++) {

var f = doc.getField(doc.getNthFieldName(i));

if ((typeof f.page=="number" && f.page==p) || (typeof f.page!="number" && f.page.indexOf(p)>-1)) fields.push("\"" + f.name + "\"" + ": -1");

}

return fields;

}

getPageFields(this, 0);

I get this:

"Check Box25": -1,"Check Box32": -1,"Check Box33": -1,"Check Box34": -1,"Check Box35": -1,"Check Box36": -1,"Check Box37": -1,"CheckBox27": -1,"CheckBox28": -1,"CheckBox29": -1,"Text22": -1,"Text23": -1,"Text24": -1,"Text30": -1,"Text31": -1

When I load that as below I get the numbers 0-14 in the dialog?

loadDefaults: function (dialog) {

  dialog.load({

  subl:

  theOptionsList

  })

  }

Which is correct for the number of items in the list - 15, but not for getting the field names into the dialog.

Please can someone point me in the right direction.

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
Adobe Community Professional ,
Apr 19, 2018 Apr 19, 2018

Copy link to clipboard

Copied

As you've seen, the input for a listbox on an Acrobat Dialogs is an object, where each member is the text displayed in the listbox, and the value is the selection.

Here's some code that will create this input:

var oLstFlds = {};

for(var i=0;i< this.numFields:i++)

   oLstFlds[this.getNthFieldName(i)]= -1;

That's all you need, not "oLstFlds" is input for setting the values in the listbox.

dialog.load({subl:oLstFlds});

It's much easier to create complex dialogs with a dialog editor.  Like this one:

ACRODIALOGS OVERVIEW

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

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
Explorer ,
Apr 19, 2018 Apr 19, 2018

Copy link to clipboard

Copied

Hi Thom,

Fantastic!

Thanks for the help, that works a treat!

I did have a look at AcroDialogs, I just fancied the programming exercise to try and further my knowledge.

Thanks again Thom.

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 19, 2018 Apr 19, 2018

Copy link to clipboard

Copied

Excellent! Could you please mark the post as Correct Answer. Thank you.

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

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
Explorer ,
Apr 20, 2018 Apr 20, 2018

Copy link to clipboard

Copied

LATEST

Hi Thom,

I've marked the post as requested.

Thanks once again for your help.

I've got the dialog working. The height resizes depending on the number of items in the fields list and the user can then select the relevant fields to process.

Cheers Thom!

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