Skip to main content
Participant
February 28, 2020
Answered

Action to happen depending on selection in dialog box

  • February 28, 2020
  • 2 replies
  • 761 views

Hi, I am still very much a js novice.

I have managed to create a dialog box with my choices using the code given here https://community.adobe.com/t5/acrobat/i-need-to-create-a-custom-dialog-box-containing-check-boxes/m-p/8950855?page=1 by George Johnson.  The code I have used follows below.

I am at a loss, however, as to how I get the selection to execute.

If the selection is Rad1 and the user clicks OK, then field "OC 1" must have the value of field "GP Loc 1" (I know how to do this :this.getField("OC 1").value = this.getField("GP Loc 1").value 😉 but where do I put this?

I the selection is Rad2 then the focus must move to "OC 1" (this.getField("OC 1").setFocus) but again where do I put this?

My modified code is:

    //Acrobat JavaScript Dialog
//Created by DialogDesigner from WindJack Solutions
var DocPrefs =
{

    result:"cancel",
    DoDialog: function(){return app.execDialog(this);},
    strGRP1:"",
    bChk1:false,
    GetRadioSel:function(oRslts,aCtrls){
      for(var strRtn=aCtrls[0];aCtrls.length>0;strRtn=aCtrls.pop()){
        if(oRslts[strRtn] == true)
          return strRtn;
      }
      return "";
    },
    initialize: function(dialog)
    {
        var dlgInit = 
        {
                "Chk1": this.bChk1,
        };
        dlgInit[this.strGRP1] = true;
        dialog.load(dlgInit);
    },
    commit: function(dialog)
    {
        var oRslt = dialog.store();
        this.strGRP1 = this.GetRadioSel(oRslt,["Rad1","Rad2"]);
        //this.bChk1 = oRslt["Chk1"];
    },
    description:
    {
        name: "Input preferences",
        elements:
        [
            {
                type: "view",
                elements:
                [
                    {
                        type: "view",
                        char_height: 10,
                        elements:
                        [
                            {
                                type: "static_text",
                                item_id: "stat",
                                name: "Please select input method",
                                char_width: 15,
                                alignment: "align_fill",
                                font: "dialog",
                            },
                            {
                                type: "cluster",
                                item_id: "cls1",
                                name: "Form Target",
                                char_width: 8,
                                char_height: 8,
                                elements:
                                [
                                    {
                                        type: "radio",
                                        item_id: "Rad1",
                                        group_id: "GRP1",
                                        name: "Use detail captured under general location (and amend if neccessary)",
                                    },
                                    {
                                        type: "radio",
                                        item_id: "Rad2",
                                        group_id: "GRP1",
                                        name: "Capture new information",
                                    },
                                ]
                            },
                            
                        ]
                    },
                    {
                        type: "ok_cancel",
                    },
                ]
            },
        ]
    }
};

// Example Code
DocPrefs.strGRP1 = "";
DocPrefs.bChk1 = false;
if("ok" == DocPrefs.DoDialog())
{

    console.println("GRP1:" + DocPrefs.strGRP1);
    console.println("Chk1:" + DocPrefs.bChk1);
}

Thanks

 

Raymond

This topic has been closed for replies.
Correct answer Thom Parker

The checkbox has been removed from this code, so you can also remove all references to it. 

To figure out what you need to do next you'll need to use the Console window. Notice that the code displays the result of the selection in the console. This is the value that will be used to decide the which field will be given focus. 

 

You'll find a tutorial on the Console Window here:

https://www.pdfscripting.com/public/Free_Videos.cfm#JSIntro

 

 

 

2 replies

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
February 29, 2020

The checkbox has been removed from this code, so you can also remove all references to it. 

To figure out what you need to do next you'll need to use the Console window. Notice that the code displays the result of the selection in the console. This is the value that will be used to decide the which field will be given focus. 

 

You'll find a tutorial on the Console Window here:

https://www.pdfscripting.com/public/Free_Videos.cfm#JSIntro

 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
March 2, 2020

Thanks to all for your help.  I managed to get it right.

I replaced 

console.println("GRP1:" + DocPrefs.strGRP1);

with

{
if(DocPrefs.strGRP1="Rad1")
{this.getField("OC 1").value = this.getField("GP Loc 1").value

Bernd Alheit
Community Expert
Community Expert
February 28, 2020

At the same place where you use console.println.