Skip to main content
New Participant
February 21, 2018
Answered

Dynamic Stamps w/Dialog Box containing Popup (Dropdown) Menu

  • February 21, 2018
  • 1 reply
  • 7735 views

I've been fighting an issue with creating a dynamic stamp. I can't seem to get popup menus (list boxes) in dialog boxes working. The popup menu is displayed properly in the dialog box, but there is no content in the dropdown, although it is defined.

The javascript is in two locations.

The global (document) javascript:

var builder =

{

     // These map to Text Fields in the Stamp

     textBoxes :

     [

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

          { field:"Company Name", description:"Company Name:", default:function() { return ""; } },

     ],

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

     popupGroup: "Plan Section",

     listItems :

     [

          {popupItems :

               {

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

                    "Road": -1,

                    "Bridge": -1,

                    "Traffic": -1,

                    "ITS": -1

               }

          }

     ],

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

     radioGroup : "Type of Plans",

     radioButtons :

     [

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

          { value:"", description:"Original Plans" },

          { value:"Revised Plans", description:"Revised Plans" },

          { value:"As-Built Plans", description:"As-Built Plans" }

     ],

     radioErrorMsg : "Please select a status"

    

}

And here's the javascript contained in a hidden calculations field on the stamp:

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: "popupItems",

                                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["popupItems"])

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

}

This topic has been closed for replies.
Correct answer George_Johnson

All item_id values must be unique 4 character strings. It appears you're using "popupItems", and there's the potential for others not to be 4 characters either (e.g., "edt" + i, where i >= 10).

1 reply

George_JohnsonCorrect answer
Inspiring
February 21, 2018

All item_id values must be unique 4 character strings. It appears you're using "popupItems", and there's the potential for others not to be 4 characters either (e.g., "edt" + i, where i >= 10).

T000LAuthor
New Participant
February 21, 2018

Thanks George.

That was it... I changed "popupitems" to "popl" and that solved the problem.

Thom Parker
Community Expert
February 21, 2018

For an easy way to create Acrobat JavaScript Dialogs, see this: ACRODIALOGS OVERVIEW

It enforces the 4 characters limit on item_id values.

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