10 Replies Latest reply on Dec 31, 2012 8:54 AM by gkaiseril

    Formatting Fields Within A Dialog Box

    Jim MacD Level 1

      How is a formatted field created within a AdobeScript Dialog Box? I've created a Dailog Box using Adobe Acrobat Professional 8 within my pdf.

        • 1. Re: Formatting Fields Within A Dialog Box
          try67 MVP & Adobe Community Professional

          The only formatting you can do is select the char width and height, the

          font (out of 3 options), and whether or not it's bold or italic.

          • 3. Re: Formatting Fields Within A Dialog Box
            gkaiseril MVP & Adobe Community Professional

            Exactly what formatting are you trying to modify?

             

            If it is text then there are the 3 options discussed and alignment, but with 'Rich Text' one can add weighting, subscript, and superscript.

             

            If it is a number, percentage, date, or time there are some built in functions that can change the format options for these fields dynamically.

            • 4. Re: Formatting Fields Within A Dialog Box
              try67 MVP & Adobe Community Professional

              In a dialog box?

              • 5. Re: Formatting Fields Within A Dialog Box
                gkaiseril MVP & Adobe Community Professional

                The functions have parameters like the thousand and decimal separate, the sign, the minimum digits to display and the number of decimals. This is documented in the Acrobat JS API Reference for Version 5.

                 

                Number: AFNumber_Format

                Percentage: AFPercent_Format

                Date: AFDate_FormatEx

                Time: AFTime_Format

                Special: AFSpecial_Format

                Custom: see document ion notes.

                 

                One could enter the entire string in an app.response or prompt for each needed parameter. With a dialog object one could use individual fields within the dialog display to select or enter the individual parameter values that are needed.

                 

                I use these functions to modify a numeric field to display a null value for currency and percentage results with a zero value if needed.

                • 6. Re: Formatting Fields Within A Dialog Box
                  Jim MacD Level 1

                  I've created a sample pdf with code I'm trying to format. GKaiseril, can you take a look at it and determine if fields can be formatted?

                   

                  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 - I'm a newbie!!

                   

                  I am stuck on how to limit the number of characters entered into a field. I want to limit the number of numeric characters that can be entered in each phonenumber field ie  3 numbers, 3numbers and 4 numbers. And postal code field ie 3 characters and 3 characters

                   

                  Also, once the user enters the required number of characters, the code should tab to the next field. And yes, I read about tab_first and next_tab, but didn't understand how it works.

                   

                  Thanks for the reference to Acrobat JS API Reference for Version 5, I'll read up on it.

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

                   

                   

                   

                  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"];

                                          if(province != "")

                                                      {

                                                      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;

                                          }

                                         

                              }

                  • 7. Re: Formatting Fields Within A Dialog Box
                    gkaiseril MVP & Adobe Community Professional

                    The phone number is the standard number for the U.S. and Acrobat has a Regular Expression for  that phone number format.

                     

                    The formats for postal codes are only for the U.S. Zip and Zip + 4 codes. You can write a custom script for keystrokes and format for the Canadian Postal code using Regular Expressions.

                     

                    From the Regular Expressions Cookbook by Jan Goyvaerts and Steven Levithan:

                     

                    ^[A-Z]{1,2}[0-9R][0-9A-Z]??[0-9][ABD-HJLNP-UW-Z]{2}$

                     

                    The advantage of the Regular Expression over the Custom provided by Adobe is that the inputted values can be verified at the time of input and not at the end as a validation script.

                     

                    • 8. Re: Formatting Fields Within A Dialog Box
                      Jim MacD Level 1

                      Hmmmm .... how can a Regular Expression be verified in a dialog box during data input? 

                      • 9. Re: Formatting Fields Within A Dialog Box
                        Jim MacD Level 1

                        Haven't been able to get it to work. Any change you can take a look at my sample code and add the code to check for the correct format for field 'postalcodea' which should be in the format of A9A?

                        • 10. Re: Formatting Fields Within A Dialog Box
                          gkaiseril MVP & Adobe Community Professional

                          I believe the Canadian Postal code is a little more complex than "A9A".

                           

                          The description is:

                          Canadian postal codes

                          simply use an alternating sequence of six alphanumeric characters with a space in the

                          middle.

                           

                          This would be a sequence like "A9A 9A9". Then there are certain values that will not appear.

                           

                          You can try the following function:

                           

                          function CheckCanadaPostal(cPostalCode) {
                          /*
                          Test the cPostalCode srting for complying with the Canada Postal Code format A9A 9A9
                          */
                          return /^(?!.*[DFIOQU])[A-VXY][0-9][A-Z] [0-9][A-Z][0-9]$/.test(cPostalCode);
                          } // end CheckCanada Postal function

                           

                           

                          You can check it with:

                           

                          CheckCanadaPostal("K1A 0B1");

                          Or use the string "H0H 0H0" for the following individual:

                           

                          SANTA CLAUS

                           

                          NORTH POLE  H0H 0H0

                          CANADA

                          or

                          PÈRE NOËL

                          PÔLE NORD  H0H 0H0

                          CANADA

                          And Canadian Forces Postal Service "K8N 5W6"

                           

                           

                          You could trim the abve down to the Postal Region

                           

                          function CheckCanadaPostalRegion(cPostalCode) {
                          /*
                          Test the cPostalCode srting for complying with the Canada Postal Code format A9A 9A9
                          */
                          return /^(?!.*[DFIOQU])[A-VXY][0-9][A-Z]$/.test(cPostalCode);
                          } // end CheckCanada Postal Region function