0 Replies Latest reply on Feb 2, 2012 5:52 AM by Jim MacD

    New to Dialog Boxes and I'm stuck

    Jim MacD Level 1

      Seems there is no way to format a field in a Dialog Box. How can a field be checked to determine if the correct type of data was entered in it, when the user moves to the next field, before data is committed?

       

      I am stuck on how to limit the number of characters entered into the postal code and phone fields. I want to limit the number of numeric characters that can be entered in each phonenumber field ie  3 numbers, 3numbers and 4 numbers (999 999 9999)  And postal code field ie 3 characters and 3 characters (A9A 9A9)

       

      Also, once the user enters the required number of characters in the phone and postal code fields, the code should tab to the next field. And yes, I read about tab_first and next_tab, but don't understand how it works. The way I see it working is that once a phone or postal code field is filled with the required number of characters, control automatically tabs to the next field.

       

      I am using Adobe Acrobat Professional 8

       

      This code was written by trail and error using examples from various sources ie Acrobat JavaScript Scripting reference - version 7.0.5, Acrobat JavaScript Scripting Guide - version 7.0, and I have very little experience in creating a dialog box and its code - forgive the mess.

       

       

      //============================================================================

      var goon=true;

      var result;

      var address;

      var city;

      var province;

       

      var sign;

       

      var postalcodea;

       

      var postalcodeb;

       

      var homephone;

      var homephoneareacode;

      var homephoneprefix;

      var homephonenumber;

       

      var businessphone;

      var businessphoneareacode;

      var businessphoneprefix;

      var businessphonenumber;

       

      address = this.getField("Text1-2-Address").value;

      city = this.getField("Text1-2-City").value;

       

      var provincelist = new Array();

       

      provincelist[1] = " ";

      provincelist[2] = "Alberta";

      provincelist[3] = "British Columbia";

      provincelist[4] = "Manitoba";

      provincelist[5] = "New Brunswick";

      provincelist[6] = "Newfoundland & Labrador";

      provincelist[7] = "Northwest Territories";

      provincelist[8] = "Nova Scotia";

      provincelist[9] = "Nunavut";

      provincelist[10] = "Ontario";

      provincelist[11] = "Prince Edward Island";

      provincelist[12] = "Québec";

      provincelist[13] = "Saskatchewan";

      provincelist[14] = "Yukon";

       

      var sign = new Array();

       

      for (var i=0; i<15; i++)

                  {

                  sign[i] = "-";

                  if(provincelist[i] == this.getField("Client's Full Province Name").value)

                              {

                              sign[i] = "+";

                              }

                  }

       

      postalcodea = "";

      postalcodeb = "";

       

      if(this.getField("Text1-2-Postal-Code").value != "")

                  {

                  postalcodea = this.getField("Text1-2-Postal-Code").value;

                  postalcodea = util.printx("A9A", postalcodea);

                  postalcodeb = this.getField("Text1-2-Postal-Code").value;

                  postalcodeb = postalcodeb[4]  + postalcodeb[5] + postalcodeb[6];

                  }

       

      homephoneareacode = "";

      homephoneprefix = "";

      homephonenumber = "";

       

      if(this.getField("Text1-2-Home-Phone-Number").value != "")

                  {         

                  homephone = util.printx("9999999999", this.getField("Text1-2-Home-Phone-Number").value);

                  homephoneareacode = homephone[0] + homephone[1] + homephone[2];

                  homephoneprefix = homephone[3] + homephone[4] + homephone[5];

                  homephonenumber = homephone[6] + homephone[7] + homephone[8] + homephone[9];

                  }

       

      businessphoneareacode = "";

      businessphoneprefix = "";

      businessphonenumber = "";

       

      if(this.getField("Text1-2-Business-Phone-Number").value != "")

                  {         

                  businessphone = util.printx("9999999999", this.getField("Text1-2-Business-Phone-Number").value);

                  businessphoneareacode = businessphone[0] + businessphone[1] + businessphone[2];

                  businessphoneprefix = businessphone[3] + businessphone[4] + businessphone[5];

                  businessphonenumber = businessphone[6] + businessphone[7] + businessphone[8] + businessphone[9];

                  }

       

      var dialog2 =

                  {

                  initialize: function(dialog)

                              {

                               dialog.load(

                                                      {

                                                       stat:     "Client Address and Phone Information is required in forms you are about to link to. To save time, enter Address and Phone Information before linking to these documents.",

                                                      str1: address,

                                                      str2: city,

                                                      stra: postalcodea,

                                                      strb: postalcodeb,

                                                      str5: homephoneareacode,

                                                      str6: homephoneprefix,

                                                      str7: homephonenumber,

                                                      str8: businessphoneareacode,

                                                      str9: businessphoneprefix,

                                                      sts1: businessphonenumber,

       

                                                      str3:

                                                                  {

                                                                  "  ": (sign[1] + "1"),

                                                                  "Alberta": (sign[2] + "2"),

                                                                  "British Columbia": (sign[3] + "3"),

                                                                  "Manitoba": (sign[4] + "4"),

                                                                  "New Brunswick": (sign[5] + "5"),

                                                                  "Newfoundland & Labrador": (sign[6] + "6"),

                                                                  "Northwest Territories": (sign[7] + "7"),

                                                                  "Nova Scotia": (sign[8] + "8"),

                                                                  "Nunavut": (sign[9] + "9"),

                                                                  "Ontario": (sign[10] + "10"),

                                                                  "Prince Edward Island": (sign[11] + "11"),

                                                                  "Québec": (sign[12] + "12"),

                                                                  "Saskatchewan": (sign[13] + "13"),

                                                                  "Yukon": (sign[14] + "14"),

                                                                  }

                                                      }

                                          );

                  },

       

       

                  cancel: function(dialog)

                              {

                              return;

                              },

       

                  destroy: function(dialog)

                              {

                              return;

                              },

       

                  commit:function (dialog)

                              {

                              results = dialog.store();

                              var elements = dialog.store() ["str3"]

                              province = "";

                              for(var i in elements)

                                          {

                                          if(elements[i]  > 0)

                                                      {

                                                      province = i;

                                                      }

                                         

                                          }

       

                              return;

                              },

       

                              description:

                              {

                              name: "Address and Phone Information",

                              //align_children: "align_left",

                              //type: "static_text",

                              //char_height: 9,

                              //width: 350,

                              //height: 75,

                              elements:

                                          [

                                                      {

                                                      type: "cluster",

                                                      name: "",

                                                      align_children: "align_left",

                                                      elements:

                                                                  [

       

                                                                              {

                                                                              align_children: "align_top",

                                                                              alignment: "align_fill",

                                                                              type: "view",

                                                                              width: 254,

                                                                              elements:

                                                                                          [

                                                                                                       {

                                                                                                       alignment: "align_fill",

                                                                                                       bold: true,

                                                                                                       font: "default",

                                                                                                       char_height: 9,

                                                                                                       italic: true,

                                                                                                       item_id: "stat",

                                                                                                       multiline: false,

                                                                                                       type: "static_text",

                                                                                                       width: 150,

                                                                                                       height: 50,

                                                                                                       },

                                                                                          ]

                                                                              },

       

                                                                              {

                                                                              type: "view",

                                                                              align_children: "align_distribute",

                                                                              elements:

                                                                                          [

                                                                                                       {

                                                                                                       type: "static_text",

                                                                                                       name: "Address: "

                                                                                                       },

                                                                                                       {

                                                                                                       item_id: "str1",                         

                                                                                                       type: "edit_text",

                                                                                                       alignment: "align_left",

                                                                                                       char_width: 60,

                                                                                                       height: 20,

                                                                                                       }

                                                                                          ]

       

                                                                              },

                                                                              {

                                                                              type: "view",

                                                                              align_children: "align_distribute",

                                                                              elements:

                                                                                          [

                                                                                                       {

                                                                                                       type: "static_text",

                                                                                                       name: "       City: "

                                                                                                       },

                                                                                                       {

                                                                                                       item_id: "str2",

                                                                                                       type: "edit_text",

                                                                                                       alignment: "align_left",

                                                                                                       char_width: 16,

                                                                                                       height: 20,

                                                                                                       },

                                                                                                       {

                                                                                                       type: "static_text",

                                                                                                       name: "Province: "

                                                                                                       },

                                                                                                       {

                                                                                                       item_id: "str3",

                                                                                                       type: "popup",

                                                                                                       alignment: "align_left",

                                                                                                       char_width: 16,

                                                                                                       },

                                                                                                       {

                                                                                                       type: "static_text",

                                                                                                       name: "Postal Code: "

                                                                                                       },

                                                                                                       {

                                                                                                       item_id: "stra",

                                                                                                       type: "edit_text",

                                                                                                       alignment: "align_left",

                                                                                                       char_width: 3,

                                                                                                       height: 20,

                                                                                                       },

                                                                                                       {

                                                                                                       type: "static_text",

                                                                                                       name: "-"

                                                                                                       },

                                                                                                       {

                                                                                                       item_id: "strb",

                                                                                                       type: "edit_text",

                                                                                                       alignment: "align_left",

                                                                                                       char_width: 3,

                                                                                                       height: 20,

                                                                                                       }

       

                                                                                          ]

                                                                              },

       

       

                                                                              {

                                                                              type: "view",

                                                                              align_children: "align_distribute",

                                                                              elements:

                                                                                          [

                                                                                                       {

                                                                                                       type: "static_text",

                                                                                                       name: "Home Phone Number: ("

                                                                                                       },

                                                                                                       {

                                                                                                       item_id: "str5",

                                                                                                       type: "edit_text",

                                                                                                       alignment: "align_left",

                                                                                                       char_width: 3,

                                                                                                       height: 20,

                                                                                                       next_tab: 3,

                                                                                                       },

                                                                                                       {

                                                                                                       type: "static_text",

                                                                                                       name: ")"

                                                                                                       },

       

                                                                                                       {

                                                                                                       item_id: "str6",

                                                                                                       type: "edit_text",

                                                                                                       alignment: "align_left",

                                                                                                       char_width: 3,

                                                                                                       height: 20,

                                                                                                       },

                                                                                                       {

                                                                                                       type: "static_text",

                                                                                                       name: "-"

                                                                                                       },

       

                                                                                                       {

                                                                                                       item_id: "str7",

                                                                                                       type: "edit_text",

                                                                                                       alignment: "align_left",

                                                                                                       char_width: 4,

                                                                                                       height: 20,

                                                                                                       },

       

       

                                                                                                       {

                                                                                                       type: "static_text",

                                                                                                       name: "Business Phone Number: ("

                                                                                                       },

                                                                                                       {

                                                                                                       item_id: "str8",

                                                                                                       type: "edit_text",

                                                                                                       alignment: "align_left",

                                                                                                       char_width: 3,

                                                                                                       height: 20,

                                                                                                       },

                                                                                                       {

                                                                                                       type: "static_text",

                                                                                                       name: ")"

                                                                                                       },

       

                                                                                                       {

                                                                                                       item_id: "str9",

                                                                                                       type: "edit_text",

                                                                                                       alignment: "align_left",

                                                                                                       char_width: 3,

                                                                                                       height: 20,

                                                                                                       },

                                                                                                       {

                                                                                                       type: "static_text",

                                                                                                       name: "-"

                                                                                                       },

       

                                                                                                       {

                                                                                                       item_id: "sts1",

                                                                                                       type: "edit_text",

                                                                                                       alignment: "align_left",

                                                                                                       char_width: 4,

                                                                                                       height: 20,

                                                                                                       }

       

                                                                                          ]

                                                                              },

       

       

       

                                                                  ]

                                                      },

       

                                                      {

                                                      alignment: "align_center",

                                                      type: "ok_cancel",

                                                      ok_name: "Continue",

                                                      cancel_name: "Cancel"

                                                      },

                                          ]

                              }

       

                  };

       

       

      var dialog3 =

                  {

       

                  initialize: function (dialog)

                              {

                              },

       

                  cancel: function(dialog)

                              {

                              goon=false;

                              return;

                              },

       

                  destroy: function(dialog)

                              {

                              return;

                              },

       

                 

      };

       

      while (goon)

                  {

                  result = app.execDialog(dialog2);

       

                  if (result=="cancel")

                              {

                              goon=false;                  

                              }         

                 

                  if (result=="ok")

                              {

       

                              this.getField("Text1-2-Address").value = results["str1"];

                              this.getField("Text1-2-City").value = results["str2"];

                             

                              this.getField("Client's Full Province Name").value = province;

                                                                 

                              this.getField("Text1-2-Postal-Code").value = results["stra"] + " " + results["strb"];

                                                     

                              this.getField("Text1-2-Home-Phone-Number").value = results["str5"] + results["str6"] + results["str7"];

                              this.getField("Text1-2-Business-Phone-Number").value = results["str8"] + results["str9"] + results["sts1"];

                             

                              goon=false;

                              }

                             

                  }