4 Replies Latest reply on Oct 12, 2011 2:00 AM by Anthony_Clarke

    custom Dialog boxes

    Anthony_Clarke

      Hello Guys,

      What I would like to do is to have a box that pops up with an information text and when the user does an action (click on a button, use a radio button or a check box or anything else..) the content of a text field changes.

       

      I found in the api reference guide how to make a custom dialog box on page 111: http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/js_api_reference.pdf 

      The code at the end of my message is the sample code provided in this document. It produces a dialog box where the user can check a checkbox: ckbx  with the text pet owner to enable the 3 radio buttons to enter the number of pets the user has.

      This is the event triggered when the user changes the checkbox. It enables the radio buttons.

                                   

                         

                     ckbx: function (dialog) {

                     // Process the checkbox, if the user has a pet, turn on radios                             Here I would need something like ckbx.name = "the new name"

                     this.hasPet = !this.hasPet;                                                                                or dialog.name ({"ckbx": "new name"} but I tried all tricks and no result

                     dialog.enable({

                     "rd01" : this.hasPet,

                     "rd02" : this.hasPet,

                     "rd03" : this.hasPet

                      });

                         },

       

       

      I tried everything I could think of to change the value of one of the text fields but it didn't work.

      Can we use the same kind of logic to change the text of a field in the dialog box?

       

      Thanks for your help guys,

       

       

      Source code below:

        

        

        

        

       

      var dialog2 =

      {

      initialize: function(dialog) {

      // Set a default value for radio button field

      dialog.load({"rd01": true });

      this.hasPet = false;

      // Disable radio button field

      dialog.enable({

      "rd01" : this.hasPet,

      "rd02" : this.hasPet,

      "rd03" : this.hasPet

      });

      },

      commit: function(dialog) {

      // When the user presses "Ok", this handler will execute first

      console.println("commit");

      var results = dialog.store();

      // Do something with the data, for example,

      var hasPet = (this.hasPet) ? "have" : "don't have";

      console.println("You " + hasPet + " a pet.");

      if (this.hasPet)

      console.println("You have " + this.getNumPets(results)

      + " pet(s).");

      },

      getNumPets: function (results) {

      for ( var i=1; i<=3; i++) {

      if ( results["rd0"+i] ) {

      switch {

      case 1:

      var nPets = "one";

      break;

       

      case 2:

      var nPets = "two";

      break;

      case 3:

      var nPets = "three or more";

      }

      }

      };

      return nPets;

      },

      ok: function(dialog) {

      // The handler for the Ok button will be handed after commit

      console.println("Ok!");

      },

      ckbx: function (dialog) {

      // Process the checkbox, if the user has a pet, turn on radios

      this.hasPet = !this.hasPet;

      dialog.enable({

      "rd01" : this.hasPet,

      "rd02" : this.hasPet,

      "rd03" : this.hasPet

      });

      },

      cancel: function(dialog) { // Handle the cancel button

      console.println("Cancel!");

      },

      other: function(dialog){ // Handle the other button

      app.alert("Thanks for pressing me!");

      dialog.end("other"); // End the dialog box, return "other"!

      },

      // The dialog box description

      description:

      {

      name: "More Personal Information",

      elements:

      [

      {

      type: "view",

      align_children: "align_left",

      elements:

      [

      {

      type: "static_text",

      name: "Personal Information",

      bold: true,

      font: "dialog",

      char_width: 30,

      height: 20

      },

      {

      type: "check_box",

      item_id: "ckbx",

      name: "Pet Owner"

      },

      {

        

        

        

        

       

      type: "view",

      align_children: "align_row",

      elements:

      [

      {

      type: "static_text",

      name: "Number of pets: "

      },

      {

      type: "radio",

      item_id: "rd01",

      group_id: "rado",

      name: "One"

      },

      {

      type: "radio",

      item_id: "rd02",

      group_id: "rado",

      name: "Two",

      },

      {

      type: "radio",

      item_id: "rd03",

      group_id: "rado",

      name: "Three or more",

      }

      ]

      }

      ]

      },

      {

      type: "gap", //Add a small vertical gap between

      height: 10 //..radio fields and buttons

      },

      {

      type: "ok_cancel_other",

      ok_name: "Ok",

      cancel_name: "Cancel",

      other_name: "Press Me"

      }

      ]

      }

      };

       

        

        

        

        

       

      var retn = app.execDialog(dialog2);