How to use event.willCommit with export values in dropdown?

New Here ,
Feb 26, 2020 Feb 26, 2020

Copy link to clipboard

Copied

Hello experts, I come to you with a very beginner-level question.

 

I have two dropdown menus, Dropdown1 and Dropdown2. I would like to make it so when a choice is selected from Dropdown1, the choices available in Dropdown2 will change based on the export value of the choice in Dropdown1. For example, my Dropdown1 has the following choices and export values: (Choice1, a) & (Choice2, b). If Choice1 (a) is selected, the choices from Dropdown2 should be a, b, or c. If Choice2 (b) is selected, the choices from Dropdown2 should be d, e, or f.

 

I found some possible solutions online using the event.willCommit method, but I can't get this to work with the export values of my choices. When Choice1 is selected from Dropdown1, the choices in Dropdown2 are not updated. It's only when I select Choice2 that Dropdown2 is populated with a, b, & c. Here's the Keystroke Script I have in my Dropdown1:

 

var arrayOne = ["a", "b", "c"];
var arrayTwo = ["d", "e", "f"];

if (event.willCommit)
{
    event.value = this.getField("Dropdown1").value;
    var exportValue = event.value;

    if (exportValue == "a")
    {
        this.getField("Dropdown2").clearItems();
        this.getField("Dropdown2").setItems(arrayOne);
    }
    else if (exportValue == "b")
    {
        this.getField("Dropdown2").clearItems();
        this.getField("Dropdown2").setItems(arrayTwo);
    }
    else
    {
        this.getField("Dropdown2").clearItems();
    }
}

 

How can I adjust this code to make the choices in Dropdown2 update once a choice in Dropdown1 is selected? Also worth noting, I have 'Commit selected value immediately' option checked on Dropdown1.

 

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

263

Likes

translate

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 ,
Feb 27, 2020 Feb 27, 2020

Copy link to clipboard

Copied

You're code has some unnecessary items, but it is correct. 

You need to set the "Commit selected value immediately" option on the Properties dialog for the dropdown.

Here's are article that covers this exact topic.

https://acrobatusers.com/tutorials/js_list_combo_livecycle/

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

Likes

translate

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