3 Replies Latest reply on Feb 21, 2018 9:57 AM by Thom Parker

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

    T000L

      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. 2018-02-19_16-22-54.jpg

       

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

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

      }