8 Replies Latest reply on Sep 8, 2016 7:01 AM by Karl Heinz Kremer

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

    Michail Wod.

      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?

        • 1. Re: Dynamic Stamps / Dialog Box with Popup Menu (or List Box)
          Bernd Alheit Adobe Community Professional & MVP

          How did you set the value of the field?

          • 2. Re: Dynamic Stamps / Dialog Box with Popup Menu (or List Box)
            Michail Wod. Level 1

            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).

            • 3. Re: Dynamic Stamps / Dialog Box with Popup Menu (or List Box)
              try67 MVP & Adobe Community Professional

              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
              }
              })
              
              • 4. Re: Dynamic Stamps / Dialog Box with Popup Menu (or List Box)
                Michail Wod. Level 1

                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[i];

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

                    }

                }

                 

                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[i];

                        stateElements[i] =

                            {

                                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[i];

                      

                        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[i] = 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[i];

                            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[i];

                            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[i];

                            var id = "edt" + i;

                            this.textBoxResults[i] = res[id];

                        }

                      

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

                        if (res["popI"][i] >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[i];

                            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;

                }

                • 5. Re: Dynamic Stamps / Dialog Box with Popup Menu (or List Box)
                  Karl Heinz Kremer Adobe Community Professional

                  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.

                  • 6. Re: Dynamic Stamps / Dialog Box with Popup Menu (or List Box)
                    Karl Heinz Kremer Adobe Community Professional

                    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?

                    1 person found this helpful
                    • 7. Re: Dynamic Stamps / Dialog Box with Popup Menu (or List Box)
                      Michail Wod. Level 1

                      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

                      • 8. Re: Dynamic Stamps / Dialog Box with Popup Menu (or List Box)
                        Karl Heinz Kremer Adobe Community Professional

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