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

Dynamic Stamps / Dialog Box with Popup Menu (or List Box)

Community Beginner ,
Sep 07, 2016 Sep 07, 2016

Copy link to clipboard

Copied

Hi folks,

i have been experimenting with dynaimc stamps for a while and I got pretty far with this topic. What i cant get working are popup menus (or list boxes) in dialog boxes. The popup menu is displayed properly in the dialog box, but there is no content although its defined. The javascript of the content definition looks like:

    // This maps to a Popup Group in the PDF named 'Test'  

    popupGroup: "Test",

    listItems :

    [

        {popupItems :

            {

                //list of items of Popup menu, positive number indicates default selection

                "Test 1": +1,

                "Test 2": -1,

                "Test 3": -1,

                "Test 4": -1,

                "Test 5": -1

            }

        }

    ]

Do u got any idea whats wrong with the code above?

TOPICS
Acrobat SDK and JavaScript , Windows

Views

1.8K

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

Community Expert , Sep 07, 2016 Sep 07, 2016

I did a quick check of your code, and there is a problem with an exception that is thrown in this line: return Collab.user;

If you take this out, the code works correctly. Why are you using the Collab object?

Votes

Translate

Translate
Community Expert ,
Sep 07, 2016 Sep 07, 2016

Copy link to clipboard

Copied

How did you set the value of the field?

Votes

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
Community Beginner ,
Sep 07, 2016 Sep 07, 2016

Copy link to clipboard

Copied

i doubt there is any value to set like when using radio buttons.

e.g. for radio buttons i use:

{ value:"Test", description:"Test" },

That works fine with radio buttons. But for popupgroups i understood that u just have to define the popupitems like above (or different, because it does not work).

Votes

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
Community Expert ,
Sep 07, 2016 Sep 07, 2016

Copy link to clipboard

Copied

Each item in the list needs to have a different (absolute) value. The positive value is the selected one.

Also, the item_id must be EXACTLY four characters. So it needs to be something like this (I took this example from the documentation of the execDialog method, which I recommend you read carefully):

dialog.load({

subl:

{

"Acrobat Professional": +1,

"Acrobat Standard": -2,

"Adobe Reader": -3

}

})

Votes

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
Community Beginner ,
Sep 07, 2016 Sep 07, 2016

Copy link to clipboard

Copied

Thanks a lot try67, i got that with the Item_id and the different values. I corrected the code, but it still doesnt work. Unfortunatly the code is divided in two seperate text fields. One for the basic java code and one for the claculations. So its a bit confusing compared to the execDialog documentation (which examples work perfectly).

The whole Code of the stamp looks like:

BASIC TEXT FIELD JAVASCRIPT:

var builder =

{

    // These map to Text Fields in the Stamp

    textBoxes :

    [

        { field:"CheckedBy", description:"Checked by:", default:function() { return Collab.user; } },      

        { field:"Date", description:"Date:", default:function()

            {

                var curDate = new Date();

                return (curDate.getMonth() + 1) + "/" + curDate.getDate() + "/" + curDate.getFullYear();

            }

        },  

        { field:"Submittal", description:"Submittal #:", default:function() { return ""; } },

        { field:"Spec", description:"Spec #:", default:function() { return ""; } }

    ],

        // This maps to a Radio Group in the PDF named 'Status'

    radioGroup : "Status",  

    radioButtons :

    [

        // value maps to the 'Choice' of each radio button in the group, description will show on the dialog

        { value:"Approved", description:"Approved" },  

        { value:"Revise", description:"Revise" },

        { value:"Rejected", description:"Rejected" }

    ],

    radioErrorMsg : "Please select a status",

    // This maps to a Popup Group in the PDF named 'Project'  

    popupGroup: "Project",

    listItems :

    [

        {popI :

            {

                //list of items of Popup menu, positive number indicates default selection

                "Project 1": +1,

                "Project 2": -2,

                "Project 3": -3,

                "Project 4": -4,

                "Project 5": -5

            }

        }

    ]

}

SECOND TEXTFIELD FOR CALCULATIONS:

// WARNING: DO NOT EDIT

// SEE GLOBAL JAVASCRIPT SECTION FOR CUSTOMIZATION

if (event.source.forReal)

{

    var stampDialog = CreateDialog(builder);

    app.execDialog(stampDialog);  

  

    this.getField(builder.radioGroup).value = stampDialog.radioSelection;

    this.getField(builder.popupGroup).value = stampDialog.popupSelection;

  

    for (var i = 0; i < builder.textBoxes.length; ++i)

    {

        var t = builder.textBoxes;

        this.getField(t.field).value = stampDialog.textBoxResults;

    }

}

function CreateDialog(dialogBuilder)

{

    var sd = new Object();

    sd.builder = dialogBuilder;

    sd.radioSelection = "";

    sd.popupSelection = "";

    sd.textBoxResults = new Array();

          

    var popupElements = new Array();

  

    popupElements[0] =

    {

        type: "popup",

        item_id: "popI",

        field: sd.builder.popupGroup,

        width: 250

    };

  

    var popupCluster =

    {

        type: "cluster",

        name: builder.popupGroup,

        elements: popupElements

    };

  

    var stateElements = new Array();

  

    for (var i = 0; i < dialogBuilder.radioButtons.length; ++i)

    {

        var c = dialogBuilder.radioButtons;

        stateElements =

            {

                type: "radio",

                name: c.description,

                item_id: "rad" + i,

                group_id: "grp1"              

            };      

    }  

      

    var stateCluster =

    {

        type: "cluster",

        name: "Status",

        alignment: "align_center",

        align_children: "align_distribute",      

        elements: stateElements

    };

              

    var optionsElements = new Array();  

  

    for (var i = 0; i < dialogBuilder.textBoxes.length; ++i)

    {

        var view = new Object();      

        view.type = "view";

        view.align_children = "align_row";

        view.elements = new Array();

      

        var t = dialogBuilder.textBoxes;

      

        var s = new Object();

        s.type = "static_text";

        s.item_id = "sta" + i;

        s.name = t.description;

        s.width = 90;      

      

        var e = new Object();

        e.type = "edit_text";

        e.item_id = "edt" + i;

        e.width = 150;

      

        view.elements[0] = s;

        view.elements[1] = e;      

  

        optionsElements = view;

    }

  

    var optionsCluster =

    {

        type: "cluster",

        name: "Options",

        elements: optionsElements

    };

      

    sd.initialize = function(dialog)

    {

        var init = new Object();

      

        for (var i = 0; i < this.builder.textBoxes.length; ++i)

        {

            var t = this.builder.textBoxes;

            var id = "edt" + i;          

            init[id] = t.default();

        }

      

        dialog.load(init);

        dialog.load(this.builder.listItems[0]);      

    };

  

    sd.commit = function(dialog)

    {

        var res = dialog.store();

      

        for (var i = 0; i < this.builder.radioButtons.length; ++i)

        {

            var c = this.builder.radioButtons;

            var id = "rad" + i;

            if (res[id] == true)

            {

                this.radioSelection = c.value;

                break;

            }

        }      

      

        for (var i = 0; i < this.builder.textBoxes.length; ++i)

        {

            var t = this.builder.textBoxes;

            var id = "edt" + i;

            this.textBoxResults = res[id];

        }

      

        for (var i in res["popI"])

        if (res["popI"] >0)

        {

            this.popupSelection = i;

        }

    };

  

    sd.validate = function(dialog)

    {

        var res = dialog.store();

        for (var i = 0; i < this.builder.radioButtons.length; ++i)

        {

            var c = this.builder.radioButtons;

            var id = "rad" + i;

            if (res[id] == true)

                return true;

        }

      

        app.alert(this.builder.radioErrorMsg);

        return false;

    };

  

    sd.description =

    {

        name: "Stamp Dialog",

        elements:

        [

            {

                type: "view",

                align_children: "align_fill",

                elements:

                [

                    popupCluster,

                    stateCluster,

                    optionsCluster

                ]

            },

            {

                type: "ok"

            }

        ]

    };

    return sd;

}

Votes

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
Community Expert ,
Sep 07, 2016 Sep 07, 2016

Copy link to clipboard

Copied

It looks like you are using a "template" of a dialog object, and then pass that into CreateDialog(), which then modifies that template to create the actual dialog object.

First of all, I would suggest that you edit not in your actual stamp file, but in a standalone document, iin which you can trigger the dialog via a button. Once everything is working, you can then add the stamp specific code and move it to the actual stamp file.

What I would do in regards to your problem is to capture the output that CreateDialog() is creating, and then dump the content of the dialog object to a string (via sd.toSource() ). This way, you can analyze the structure of the object and figure out what it is, that is causing your problems.

Votes

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
Community Expert ,
Sep 07, 2016 Sep 07, 2016

Copy link to clipboard

Copied

I did a quick check of your code, and there is a problem with an exception that is thrown in this line: return Collab.user;

If you take this out, the code works correctly. Why are you using the Collab object?

Votes

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
Community Beginner ,
Sep 08, 2016 Sep 08, 2016

Copy link to clipboard

Copied

Thanks a lot Karl Heinz, i was so focused on the popup topic that i didnt realize the Collab.User was still in the code... u have been a great help. thanks again

Votes

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
Community Expert ,
Sep 08, 2016 Sep 08, 2016

Copy link to clipboard

Copied

LATEST

Whenever you run into strange problems, check for errors in the JavaScript console.

Votes

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