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

Dynamically populating drop-down lists

Explorer ,
Feb 12, 2018 Feb 12, 2018

Hi,

I wonder if it is possible to dynamically populate a drop-down list.

Very basically, I have a drop-down field called "countries". There are some options like, France, Spain, England, etc. but not all the countries.

I would like a user to add an item to the list, but not to duplicate an already existing item in the list.

I have seen it is possible in LifeCycle Designer but I only have license for Adobe Acrobat Pro DC at the moment.

TOPICS
PDF forms
8.7K
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
1 ACCEPTED SOLUTION
Community Expert ,
Feb 12, 2018 Feb 12, 2018

Read these articles:

https://acrobatusers.com/tutorials/js_list_combo_livecycle

https://www.pdfscripting.com/public/List-Field-Usage-and-Handling.cfm

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

View solution in original post

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
Community Expert ,
Feb 12, 2018 Feb 12, 2018

Read these articles:

https://acrobatusers.com/tutorials/js_list_combo_livecycle

https://www.pdfscripting.com/public/List-Field-Usage-and-Handling.cfm

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

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
Explorer ,
Feb 13, 2018 Feb 13, 2018

Thank you Thom for providing me very valuable articles corresponding particular needs.

I am trying to implement it buy using your example however I am stuck in very fist steps.

I basically created three form field (drop-down list) in Acrobat. Names:

Row1.AssemblySelect

Row1.PartSelect

Row1.Price

then I went to document JavaScript and I copied and pasted your code basically (please see below).

At the end I went to preview my doc, but fields are not populated. Could you please kindly point at what I am missing? I tried like a number of times.

//////test out////////

var oAssemblyParts = {

    Chasis: [

        ["-","None"],

        ["Rear Bracket",205.95],

        ["Front Bracket",185.95],

        ["Long Support",44.95],

        ["Front Bearing",48.95]

    ],

    Clutch: [

        ["-","None"],

        ["Plate 1",15.95],

        ["Plate 2",22.95],

        ["Inside Shaft",44.95],

        ["Outside Shaft",32.95]

    ],

    Brake: [

        ["-","None"],

        ["Master Cylindar",139.95],

        ["Slave Cylindar",85.95],

        ["Pad",15.95],

        ["High Presure line",22.95]

    ],

    Coolant: [

        ["-","None"],

        ["Pump",35.95],

        ["Thermostat",19.95],

        ["Coolant Line",8.95],

        ["Reservoir",17.95]

    ]

};

function SetPartEntries() {

    if(event.willCommit) {

        // Get the new parts list from the Master List

        // Since the selection is being committed,

        // event.value contains the Assembly name

        var lst = oAssemblyParts[event.value];

        // Clear the Parts list if there are no parts for the selected assembly

        if( (lst != null) && (lst.length > 0) )

        this.getField("PartSelect").setItems(lst);

        else

        this.getField("PartSelect").clearItems();

        // We have a new parts lists and the first entry is

        // is a non-selection, so clear the price field.

        this.getField("Price").value = 0;

    }

}

SetPartEntries();

//////test out////////

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
Community Expert ,
Feb 13, 2018 Feb 13, 2018

Use the full names of the fields in your code.

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
Explorer ,
Feb 13, 2018 Feb 13, 2018

Thank you, you're right the names of the fields and the code was inconsistent.

So I updated my field names to:

AssemblySelect

PartSelect

Price

BUT, it is still not working. I think what I miss is being able to populate "AssemblySelect" field first. Because I see no correspondence in code. Am I mistaken?

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
Community Expert ,
Feb 13, 2018 Feb 13, 2018

There is a part of the process you did not mention, which is putting code in the Custom Keystroke script. The example shows the code needed there.

Also, make sure the field Options are set to "Commit selected value immediately".

And also you have to setup the entries in the first drop down manually. You could do this from code very easily, but if they don't change there is no point, unless you have several rows of dropdowns to fill. In that case you'll also need to modify the code to handle different row names. But that is another issue.

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

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
Explorer ,
Feb 14, 2018 Feb 14, 2018

Thank you! I was missing "Custom Keystroke script".

Actually I don't have several rows, but I would like to connect several list-box like Continent>Country>Region>City>Town... Should I have better create a new question for the problem I face in that?

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
Community Expert ,
Feb 14, 2018 Feb 14, 2018
LATEST

That requires a more complicated data-model. I've developed a tool that allows you to set up such "cascading" drop-downs easily, based on a spreadsheet. See: Custom-made Adobe Scripts: Acrobat -- Create Cascading Dropdowns

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