Issue with multiple popup lists not populating in custom dialog

New Here ,
Feb 05, 2020 Feb 05, 2020

Copy link to clipboard

Copied

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. 

TOPICS
Acrobat SDK and JavaScript, General troubleshooting, How to, PDF forms

Views

64

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

Copy link to clipboard

Copied

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 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
New Here ,
Feb 06, 2020 Feb 06, 2020

Copy link to clipboard

Copied

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.

 

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
New Here ,
Feb 06, 2020 Feb 06, 2020

Copy link to clipboard

Copied

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

 

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
New Here ,
Feb 06, 2020 Feb 06, 2020

Copy link to clipboard

Copied

Nevermind, I figured out the issue, thanks for the advice regardless, didn't know this forum was for more basic issues. Where can I go if I have similar more complex issues?

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

Copy link to clipboard

Copied

You can't, nobody is going to analyze complex code for free. That's what you pay people for. If you want help on a specific issue, then you state that specific issue. 

 

But just to provide some advice, you're code is insanely over complex for what you've described. 

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
New Here ,
Feb 06, 2020 Feb 06, 2020

Copy link to clipboard

Copied

Alright, no need to be so condescending, man. I thought you were saying there's a better forum for this stuff. Also, I did state my specific issue but your response clearly indicates that you didn't even take any time to read what I asked... Honestly your response cements my previous realization that this community is basically useless unless you have a question that a toddler couldn't figure out given a reasonable amount of time. It's crazy how you're one of the maybe three people who actually know what they're talking about when it comes to pdfs and you take the time to patronize me after I ask a simple question while thanking you for literally doing nothing for me. I mean, I just read your bio and acting like this is really beneath you. 

 

By the way this code is an exerpt from a script that is around 700 lines. I have never learned JavaScript formally so if my code is overcomplicated you can blame my lack of instruction. 

 

Once again, thanks for nothing.

 

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

Copy link to clipboard

Copied

I appologize for seeming to condesend, but by posting a long list of  complex code you are asking someone to spend a great deal of time trying to figure out what you've done. Which is very unreasonable. 

You also didn't really describe what you want. I did read through your post and the code. There is not enough detail on what you are actually trying to do, for someone who is looking at it cold.

Is the idea to add new dialog elements to a dialog based on the number of people, or to just change the value of a static set of elements based on number of people?

 You could have also asked what the better way of doing this is.

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
New Here ,
Feb 06, 2020 Feb 06, 2020

Copy link to clipboard

Copied

LATEST

Don't worry about it, I'm having a bad day. I said above that I was having an issue where the drop down list elements weren't populating. Solved it by taking what was initially two separate initialization objects (containing the two different sets of elements) and combining them into one. For some reason when there are two different objects in that step the one that is stated second seems to be ignored entirely by acrobat.

//changed this part
e.load(plzInit, repInit, disInit)
//to this
e.load(heirInit, disInit)
//heirInit contains two sets of popup list elements instead of having one
//in plzInit and one in repInit

I apologize for my earlier, and unnecessarily caustic, response.

 

Cheers

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