Search code examples
javascriptadobeacrobat

Getting checkbox data form user and checking dynamic stamp in Adobe Acrobat


I am building a dynamic stamp in Acrobat. It has 5 check boxes, and three text fields. I have the text fields fine, a dialog box pops up, ask Name, Project, they fill it in and it fills in the fields. The other text box is the date which I pull dynamically. The check boxes are the trouble. I know to check them with :

var f = this.getField("cb10");
f.checkThisBox(0,true);

Put I don't know how to include the choices in the dialog box and link them to the stamp box. Any help greatly appreciated.

EDIT

I have come up with this:

    var DiaBox =
{

result:"cancel",
DoDialog: function(){return app.execDialog(this);},
bChk1:false,
bChk2:false,
bChk3:false,
bChk4:false,
bChk5:false,
stredt1:"",
stredt2:"",
initialize: function(dialog)
{
var dlgInit = 
{
"Chk1": this.bChk1,
"Chk2": this.bChk2,
"Chk3": this.bChk3,
"Chk4": this.bChk4,
"Chk5": this.bChk5,
"edt1": this.stredt1,
"edt2": this.stredt2,
};
dialog.load(dlgInit);
},
commit: function(dialog)
{
var oRslt = dialog.store();
this.bChk1 = oRslt["Chk1"];
this.bChk2 = oRslt["Chk2"];
this.bChk3 = oRslt["Chk3"];
this.bChk4 = oRslt["Chk4"];
this.bChk5 = oRslt["Chk5"];
this.byName = oRslt["edt1"];
this.projNum = oRslt["edt2"];
},
description:
{
name: "Stamp",
elements:
[
{
type: "view",
elements:
[
{
type: "view",
char_height: 10,
elements:
[
{
type: "static_text",
item_id: "stat",
name: "Check only ONE box:",
width: 152,
height: 23,
char_width: 15,
alignment: "align_fill",
font: "dialog",
},
{
type: "check_box",
item_id: "Chk1",
name: "Approved",
},
{
type: "check_box",
item_id: "Chk2",
name: "Approved as Noted - Proceed",
},
{
type: "check_box",
item_id: "Chk3",
name: "Revise and Resubmit",
},
{
type: "check_box",
item_id: "Chk4",
name: "Not a required submittal - not Reviewed",
},
{
type: "check_box",
item_id: "Chk5",
name: "Rejected - Do Not Use",
},
{
type: "static_text",
item_id: "sta1",
name: "Project Number",
alignment: "align_row",
},
{
type: "edit_text",
item_id: "edt1",
char_width: 20,
char_height: 6,
alignment: "align_left",
},
{
type: "static_text",
item_id: "sta2",
name: "Name:",
},
{
type: "edit_text",
item_id: "edt2",
char_width: 20,
alignment: "align_left",
font: "palette",
},
]
},
{
type: "ok_cancel",
},
]
},
]
}
};

// Example Code
DiaBox.bChk1 = false;
DiaBox.bChk2 = false;
DiaBox.bChk3 = false;
DiaBox.bChk4 = false;
DiaBox.bChk5 = false;
DiaBox.stredt1 = "";
DiaBox.stredt2 = "";

if(event.source.forReal && (event.source.stampName == "#bsiloE85pqFs4ntcdBQCMC"))
{
  if ("ok" == app.execDialog(DiaBox))
  {
    var cMsg = DiaBox.byName;
    event.value = "Project # " + cMsg;
    event.source.source.info.exhibit = cMsg;

    cMsg = "By: " + DiaBox.projNum;
    this.getField("byNameField").value = cMsg;

    this.getField("cbx1").checkThisBox(0, DiaBox.bChk1);
    this.getField("cbx2").checkThisBox(0, DiaBox.bChk2);
    this.getField("cbx3").checkThisBox(0, DiaBox.bChk3);
    this.getField("cbx4").checkThisBox(0, DiaBox.bChk4);
    this.getField("cbx5").checkThisBox(0, DiaBox.bChk5);
  }
}

It works great in Acrobat, but in reader, the By Name field and check boxes don't get populated. I can't get a debugger in reader, so I have an issue tracking the problem. Can anyone see what it might be?


Solution

  • Since this is now coming up in the top of searches on Google, I will show you what I did, it is not perfect or elegant, but it works.

    {
    name: "Stamp",
    elements:
    [
    {
    type: "view",
    elements:
    [
    {
    type: "view",
    char_height: 10,
    elements:
    [
    {
    type: "static_text",
    item_id: "stat",
    name: "Check only ONE box:",
    width: 152,
    height: 23,
    char_width: 15,
    alignment: "align_fill",
    font: "dialog",
    },
    {
    type: "check_box",
    item_id: "Chk1",
    name: "Approved",
    },
    {
    type: "check_box",
    item_id: "Chk2",
    name: "Approved as Noted - Proceed",
    },
    {
    type: "check_box",
    item_id: "Chk3",
    name: "Revise and Resubmit",
    },
    {
    type: "check_box",
    item_id: "Chk4",
    name: "Not a required submittal - not Reviewed",
    },
    {
    type: "check_box",
    item_id: "Chk5",
    name: "Rejected - Do Not Use",
    }
    ]
    },
    {
    type: "ok_cancel",
    },
    ]
    },
    ]
    }
    };
    
    // Example Code
    //DiaBox.bChk1 = false;
    //DiaBox.bChk2 = false;
    //DiaBox.bChk3 = false;
    //DiaBox.bChk4 = false;
    //DiaBox.bChk5 = false;
    //DiaBox.stredt1 = "";
    //DiaBox.stredt2 = "";
    
    if(event.source.forReal && (event.source.stampName == "#bsiloE85pqFs4ntcdBQCMC"))
    {
      if ("ok" == app.execDialog(DiaBox))
      {
    
        this.getField("cbx1").checkThisBox(0, DiaBox.bChk1);
        this.getField("cbx2").checkThisBox(0, DiaBox.bChk2);
        this.getField("cbx3").checkThisBox(0, DiaBox.bChk3);
        this.getField("cbx4").checkThisBox(0, DiaBox.bChk4);
        this.getField("cbx5").checkThisBox(0, DiaBox.bChk5);
      }
    }
    
    if ("ok" == app.execDialog(DiaBox))
      {
        var cMsg = DiaBox.byName;
        event.value = "Project # " + cMsg;
        event.source.source.info.exhibit = cMsg;
      }
    

    Which separates the JS boxes, which was the only way I could capture the data for the stamp.