2 Replies Latest reply on Feb 3, 2018 11:43 PM by pierrep52392313

    AcroDialog : how to select the value of a field ?

    pierrep52392313

      I would like to use an AcroDialog window for updating a field in a PDF form and I need to populate an "edit text" with  the value of the field "Text1" existing in the form. How the following script must be modified to do so ?

      Probably very simple... but I stumble on the solution.

       

      Many thanks in advance for your advices

       

      ////////////////////////////////////////////////////////////////
      //  Acrobat JavaScript Dialog
      //

      var oJSDlg = {
      strEdt1:null,
      initialize:function(dialog){
      },
      validate:function(dialog){
        var bRtn = true;
        var oRslt = dialog.store();
        return bRtn;
      },
      commit:function(dialog){
        var oRslt = dialog.store();
        this.strEdt1 = oRslt.Edt1;
      },
      description:{
        name:"Dialog Box",
        elements:[{type:"view",width:634,height:405,elements:[
        {
         type:"static_text",
         item_id:"Sta2",
         name:"Veuillez saisir le texte du message :",
        },
        {
         type:"edit_text",
         item_id:"Edt1",
         width:614,
         height:306,
         multiline:true,
        },
        {
         type:"ok_cancel",
        },
      ]}]
      }
      }

      if("ok"==app.execDialog(oJSDlg))
      {
      console.println("strEdt1 = "+oJSDlg.strEdt1);
      }

        • 1. Re: AcroDialog : how to select the value of a field ?
          Thom Parker Adobe Community Professional

          This is something I'll be changing in the AcroDialog tool. The problem is that you didn't define a default value for "Edt1", so there is no initialization for this edit box.  To fix this you can go back to AcroDialogs and add an "initial value" to "Edt1" and recreate the dialog.  You might also consider changing the variable name to something that makes sense for the value. And also the "item_id". And also the dialog object variable name. But these are not necessary, it just makes the code easier to read.

           

          You'll get Something that looks like this

           

          var oJSDlg = {
          strEdt1:"My Value",
          initialize:function(dialog){
              dialog.load({"Edt1":this.strEdt});
          },
          ... Rest of dialog code...
          

           

          Then for using the dialog do this

           

          oJSDlg.strEdt1 = this.getField("Text1").value;
          if("ok"==app.execDialog(oJSDlg))
          {
              this.getField("TExt1").value = oJSDlg.strMyTest;
          }
          

           

           

          You can also just make these changes on your existing code. It's a good exercise to get you more familiar with dialog object scripting

          • 2. Re: AcroDialog : how to select the value of a field ?
            pierrep52392313 Level 1

            Thank you very much, Thom : that works exactly how I expected !

            I've just modified typos (in case other readers are interested in the subject )

            And I will take into account your advice for the readability of the code.

             

             

             

             

             

            var oJSDlg = { 

            strEdt1:"My Value", 

            initialize:function(dialog){ 

                dialog.load({"Edt1":this.strEdt1}); 

            }, 

             

             

             

            oJSDlg.strEdt1 = this.getField("Text1").value; 

            if("ok"==app.execDialog(oJSDlg)) 

            this.getField("Text1").value = oJSDlg.strEdt1

            }