Skip to main content
Participating Frequently
February 5, 2020
Question

Issue with multiple popup lists not populating in custom dialog

  • February 5, 2020
  • 1 reply
  • 1313 views

Essentially I'm trying to pull two different lists into two separate dialog "popup" lists but for some reason only one of the lists will populate at a time. I'm doing all this in a folder level script and I am unable to change that. The data is being pulled from a proprietary application. My code is below, please let me know if there's anything obviously wrong with it or if clarification is needed.

 

 

 

function newElement(type, id, name, elements) {

    var ele = {};

    if (elements === undefined) {
        elements = 0
    }

    switch (type) {
        case "radio":
            ele = { type: type, item_id: id, group_id: 'grup', name: name };
            break;
        case "check_box":
            ele = { type: type, item_id: id, name: "    " + name };
            break;
        case "edit_text":
            ele = { type: type, item_id: id, name: name };
            break;
        case "popup":
            ele = { type: type, item_id: id, name: name, char_width: 10 };
            break;
        case "static_text":
            ele = { type: type, alignment: id, name: name };
            break;
        case "cluster":
            ele = { type: type, align_children: id, name: name, elements: elements };
            break;
    }
    return ele;
}

function initState(type, list, id, pupList) {
    if (pupList === undefined) pupList = {};
    var state = {};
    switch (type) {
        case "check_box":
            for (var i = 0; i < list; i++) {
                state[id + i] = false;
            }
            break;
        case "radio":
            for (var i = 0; i < list; i++) {
                state[id + i] = false;
            }
            break;
        case "edit_text":
            for (var i = 0; i < list; i++) {
                state[id + i] = "";
            }
            break;
        case "popup":
            for (var i = 0; i < list; i++) {
                state[id + i] = pupList;
            }
            break;
    }
    return state;
}

//PLEASE NOTE ALL THE VARIABLES ARE FROM AN EXTERNAL SOFTWARE

var repList = {};

for (var i = 0; i < m.heirReps.number; i++) {
    //making integer values odd so doesn't conflict with relationship list
    if (i === 0) {
        j = 1;
    } else {
        j += 2
    }


    repList[m.heirReps.name[i]] = j * -1;
}

var repInit = initState("popup", finHeirList.number, "fan", repList); //representative

var disInit = initState("check_box", finHeirList.number, "dis"); //disability

var plzInit = {};


for (i = 0; i < finHeirList.number; i++) {
    plzInit["plz" + i] = {
        "Son": -2,
        "Daughter": -4,
        "Grandson": -6,
        "Granddaughter": -8,
        "Brother": -10,
        "Sister": -12,
        "Father": -14,
        "Mother": -16,
        "Niece": -18,
        "Nephew": -20
    }

}

var finRes = {}

var finDlg = {
    initialize: function (e) {
        e.load(plzInit, repInit, disInit);
    },

    commit: function (e) {
        finRes = e.store();
    },

    description: {
        type: "view",
        elements: [
            {
                type: "view",
                elements: [
                    {
                        type: "static_text",
                        name: "Fill out relevant information for each heir."
                    },
                    {
                        type: "view",
                        elements: []
                    },
                    {
                        type: "ok_cancel"
                    }
                ]
            }
        ]
    }
};




for (var i = 0; i < finHeirList.number; i++) {

    var plzEle = newElement("popup", "plz" + i, "Relationship: ");
    var disEle = newElement("check_box", "dis" + i, "Under legal disability");
    var repEle = newElement("popup", "fan" + i, "Representative");

    //Created these 2 clusters because for some reason the name of the popup elements doesn't work for me -_-
    var repCluster = newElement("cluster", "align_fill", "Select a representative", [repEle])
    var plzCluster = newElement("cluster", "align_fill", "Indicate the heir's relationship to the decedent", [plzEle])
    finDlg.description.elements[0].elements[1].elements.push(newElement("cluster", "align_fill", finHeirList.name[i], [plzCluster, repCluster, disEle]));

}



if (finHeirList.number > 0) {
    app.execDialog(finDlg);
}


for (var i = 0; i < finHeirList.number; i++) {

    for (x in finRes["plz" + i]) {
        if (finRes["plz" + i][x] > 0) {
            var plz = x;
            break;
        }
    }

    for (y in finRes["fan" + i]) {
        if (finRes["fan" + i][x] > 0) {
            var fan = x;
            break;
        }
    }

    console.println("Relationship, Rep, Disability - " + finHeirList.name[i] + ": " + plz + ", " + fan + ", " + finRes["dis" + i]);

}

 

 

Result is that the relationship popup populates fine while the rep one does not. When I instead put the rep popup first in the for loop the relationship popup stops working. I thought maybe it had something to do with the cluster not allowing them to be together but I separated them into different clusters and it still isn't working correctly.

 

All advice is greatly appreciated. 

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
February 5, 2020

Ok, so the first question is why?  Are you trying to build a generic dialog generation tool? or create a specific dialog?

If you are trying to create a specific dialog then there are much easier ways. 

 

If you want professional help I'd be happy to fix your code. But this way outside the scope of this forum. 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participating Frequently
February 6, 2020

Hi Thom. I'm trying to create code for a dialog to be created based on the number of people input into the system. What's important is I don't know how many items/what the items would be in the list I'm trying to add to the popup field. This is for automating a pdf based off info given through a separate program. Does that make sense? I would love help with this code if possible.

 

Participating Frequently
February 6, 2020

I should mention that whichever popup is stated first in the initialization function is the one that works while the other just doesn't populate. Even if it's the relationship popup that's second it doesn't populate even though I've hard coded the list