7 Replies Latest reply on Dec 13, 2014 6:34 PM by Brian3.14

    Trying to create a multi-line dialog box

    JLogan3o13 Level 1

      I have been working on a PDF study guide. At the end of each chapter is a self test, and I have some javascript that scores the exam when a user clicks a button. Currently I am using an app.alert window to advise the user which answers he got correct, and display explanations on the incorrect answers. Unfortunately some of the explanations can be a bit long, so I have had to split some of the longer self exams into multiple alerts. I have a snippet of code (below) as an example of doing a dialog box, but have been unable to find any examples of a multi-line dialog. A couple of thread had responses like "it isn't easy", but no solid examples. Does anyone have an example of a simple, multi-line dialog that I could adapt for my needs?

       

      var oDlg = { 
          description: { name: "Test Dialog", elements: [ { name: "Hello World", type: "static_text", }, { type: "ok", }, ] } 
      }; 
      // Dialog Activation 
      app.execDialog(oDlg);
      
      

       

       

      I attempted to do something like this, but it barfs on the first carriage return:

       

       

       

      var sText = "Question 5: Incorrect! The correct answer is B\r\rA, C, and D are incorrect. && and || are both short-circuit operators. With &&, when the left side evaluates to false the right side is never evaluated. And with ||, when the left side evaluates to true, the right side is never evaluated.\r\rIn the first statement, i1 does not equal 99 when it is evaluated, so the second expression is printed. However, it is decremented BEFORE the print statement, so the combined value of i and j is 299.\r\rIn the second statement, the left side of the equation evaluates to false, so the right side is never evaluated. Thus the second expression is printed out.\r\rIn the third statement, i3 equates to 100, so the first expression is printed out.\r\rFor the last statement, the left side of the expression is evaluated to true, so the right is never evaluated. The first expression is printed out.\r\rThe final result is 'Value2: 299, Value2: 300, Value1: 299, Value1: 300'";
      
      var oDlg = { 
      description: { name: "Test Dialog", elements: [ { name: SText, type: "static_text", }, { type: "ok", }, ] } 
      }; 
      // Dialog Activation 
      app.execDialog(oDlg);
      

       

      Any help would be appreciated.

        • 1. Re: Trying to create a multi-line dialog box
          George_Johnson MVP & Adobe Community Professional

          Here's a basic sample:

           

          var dialog1 = {

           

           

              DoDialog: function() {

                  return app.execDialog(this);

              },

           

           

              initialize: function (dialog) {

           

           

                  var dlgInit = {

                      "not1": this.strnot1

                  };

           

           

                  dialog.load(dlgInit);

              },

           

           

              description: {

                  name: "dlg1",

                  elements:

                      [

                          {

                          type: "view",

                          elements:

                          [

                              {

                              type: "cluster",

                              item_id: "cls1",

                              name: "Notes",

                              elements:

                              [

                                  {

                                  type: "static_text",

                                  multiline: "true",

                                  item_id: "not1",

                                  width: 300,

                                  height: 300,

                                  }

                              ]

                              }

                          ]

                          },

           

                          {

                              type: "ok",

                          }

                  ]

           

           

              }  // description

           

           

          };

           

           

          var sText = "Question 5: Incorrect! The correct answer is B\r\rA, C, and D are incorrect. && and || are both short-circuit operators. With &&, when the left side evaluates to false the right side is never evaluated. And with ||, when the left side evaluates to true, the right side is never evaluated.\r\rIn the first statement, i1 does not equal 99 when it is evaluated, so the second expression is printed. However, it is decremented BEFORE the print statement, so the combined value of i and j is 299.\r\rIn the second statement, the left side of the equation evaluates to false, so the right side is never evaluated. Thus the second expression is printed out.\r\rIn the third statement, i3 equates to 100, so the first expression is printed out.\r\rFor the last statement, the left side of the expression is evaluated to true, so the right is never evaluated. The first expression is printed out.\r\rThe final result is 'Value2: 299, Value2: 300, Value1: 299, Value1: 300'";

           

           

          dialog1.strnot1 = sText;

          dialog1.DoDialog();

          • 2. Re: Trying to create a multi-line dialog box
            JLogan3o13 Level 1

            Thank you very much! This was exactly the type of example I have been looking for; I was easily able to modify it to suit my needs.

            • 3. Re: Trying to create a multi-line dialog box
              Brian3.14 Level 1

              Great post, guys.

              As a follow up:

                     1) Is there anyway to adjust the font size of the "static_text" element and the font size of the name of the "cluster" which is 'Notes'?

               

              And out of curiosity, at least on mine, when you open the dialog box, the static text (the notes as to why the answer was incorrect) is selected (so every line is highlighted blue) and we've at the bottom of the explanation. Guess I figured the default would be no focus within the dialog and set to the top of the scrollable answer.

               

              Thanks!

              B

              • 4. Re: Trying to create a multi-line dialog box
                George_Johnson MVP & Adobe Community Professional

                You have limited control over the font size, and some of the control that's possible is undocumented and not supported on the Mac. If you set the font to "palette" and bold to true, you should see a difference, e.g.:

                 

                                    type: "cluster",

                                    item_id: "cls1",

                                    name: "Notes",

                                    font: "palette",

                                    bold: true,

                • 5. Re: Trying to create a multi-line dialog box
                  Brian3.14 Level 1

                  Wow - thanks for responding, GJ.

                   

                  Yeah, the MACs are the whole reason I'm doing this.  The messageBoxes when triggered on MAC don't seem to natively expand as wide as they do on PCs so I'm trying to make a simple dialog box that functions like a message box --- essentially just text and then an ok button.  If it's a dialog box, the MACs seem to respect the size.

                   

                  But if you don't use messageBox, then it seems like you lose the ability to have the messageBox icons, the notifcation beep and any input into the title bar where "JavaScript Window" appears at the top of the dialog box. Catch 22.

                   

                  Tips or examples on getting the icon back?  Or is that a goner?

                   

                  Thanks again; was a pleasant Friday surprise.

                   

                  B

                  • 6. Re: Trying to create a multi-line dialog box
                    George_Johnson MVP & Adobe Community Professional

                    You can include images in a custom dialog, but they don't make this easy to do. You can also include a customized dialog title and remove the JavaScript warnings, but this usually means placing the code in a folder-level JavaScript file.

                    • 7. Re: Trying to create a multi-line dialog box
                      Brian3.14 Level 1

                      Hi G,

                       

                      Yeah, folder level ain't gonna happen.  PDF needs to be self-contained.  But I've been doing some further research on the images. From what I've found, it looks like it's a 20X20 pixel image converted to hexadecimal ARGB notation.

                       

                      Surprisingly, there don't seem to be any "image file to hexadecimal ARGB string conversion programs/websites" out there.  Thought there would be since there's lots of places to get a hex value of a color.  Recommendations on how to get the string? 

                       

                      And any book recommendations on doing all this dialog window stuff would be greatly appreciated.

                       

                      Thanks much again.

                      B