Copy link to clipboard
Copied
Hello Members,
I have created a PDF DYNAMIC STAMP, consisting of 4 text fields and 4 checkboxes. Everything is working fine except for the checkboxes.
When I put data in the dialog box including the checkbox, The results of checkboxes (Checked/Unchecked) not showing up in Stamp.
//Checkbox Fields Name:
Check Box1
Check Box2
Check Box3
Check Box4
I have attached a ScreenShot of the stamp and JAVASCRIPT that I'm using now;
Thanks.
Software: Adobe Acrobat Pro DC.
var FormRouting = {
return: 'cancel',
DoDialog: function () {
return app.execDialog(this);
},
bChk1: false,
bChk2: false,
bChk3: false,
bChk4: false,
str1: '',
str2: '',
str3: '',
str4: '',
initialize: function (dialog) {
var dlgInit = {
Chk1: this.bChk1,
Chk2: this.bChk2,
Chk3: this.bChk3,
Chk4: this.bChk4,
Str1: this.str1,
Str2: this.str2,
Str3: this.str3,
Str4: this.str4,
};
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.str1 = oRslt['str1'];
this.str2 = oRslt['str2'];
this.str3 = oRslt['str3'];
this.str4 = oRslt['str4'];
},
description: {
titlename: "Personal Data",align_children: "align_left", width: 500, height: 400, elements:
[
{
type: "cluster", name: "Data Entry", align_children: "align_left", elements:
[
// Text Field Code Below
{
type: "view", align_children: "align_row", elements:
[
{
type: "static_text", name: "Field 1:"
},
{
item_id: "str1", type: "edit_text", alignment: "align_fill", width: 400, height: 20
}
]
},
{
type: "view", align_children: "align_row", elements:
[
{
type: "static_text", name: "Field 2:"
},
{
item_id: "str2", type: "edit_text", alignment: "align_fill", width: 400, height: 20
}
]
},
{
type: "view", align_children: "align_row", elements:
[
{
type: "static_text", name: "Field 3:"
},
{
item_id: "str3", type: "edit_text", alignment: "align_fill", width: 400, height: 20
}
]
},
// Check Box Field Code below
{
type: "view", align_children: "align_row", elements:
[
{
item_id: "Chk1", type: "check_box", alignment: "align_fill", width: 5, height: 20
},
{
type: "static_text", name: "CheckBox 1"
}
]
},
{
type: "view", align_children: "align_row", elements:
[
{
item_id: "Chk2", type: "check_box", alignment: "align_fill", width: 5, height: 20
},
{
type: "static_text", name: "CheckBox 2"
},
]
},
{
type: "view", align_children: "align_row", elements:
[
{
item_id: "Chk3", type: "check_box", alignment: "align_fill", width: 5, height: 20
},
{
type: "static_text", name: "CheckBox 3"
},
]
},
{
type: "view", align_children: "align_row", elements:
[
{
item_id: "Chk4", type: "check_box", alignment: "align_fill", width: 5, height: 20
},
{
type: "static_text", name: "CheckBox 4"
},
]
},
// By Field
{
type: "view", align_children: "align_row", elements:
[
{
type: "static_text", name: "By: "
},
{
item_id: "str4", type: "edit_text", alignment: "align_fill", width: 400, height: 20
}
]
},
]
},
{
alignment: "align_right",
type: "ok_cancel",
ok_name: "ok",
cancel_name: "Cancel"
}
],
},
};
if (event.source.forReal && event.source.stampName == "Sohail") {
if ('ok' == FormRouting.DoDialog()) {
// Checkboxes Fields
if (FormRouting.bChk1) {
this.getField('Check Box1').checkThisBox(0, true);
}
if (FormRouting.bChk2) {
this.getField('Check Box2').checkThisBox(0, true);
}
if (FormRouting.bChk3) {
this.getField('Check Box3').checkThisBox(0, true);
}
if (FormRouting.bChk4) {
this.getField('Check Box4').checkThisBox(0, true);
}
// string fields
this.getField('Field 1').value = FormRouting.str1;
this.getField('Field 2').value = FormRouting.str2;
this.getField('Field 3').value = FormRouting.str3;
this.getField('By').value = FormRouting.str4;
}
}
Copy link to clipboard
Copied
There is no need for the "if" statement used to set the checkbox value. Write it like this:
this.getField('Check Box1').checkThisBox(0, FormRouting.bChk1);
this.getField('Check Box2').checkThisBox(0, FormRouting.bChk2);
this.getField('Check Box3').checkThisBox(0, FormRouting.bChk3);
this.getField('Check Box4').checkThisBox(0, FormRouting.bChk4);
And after looking through the code again I found your error. In the dialog "commit" function the item_id for the checkbox is spelled incorrectly.
Here is the corrected code:
this.bChk1 = oRslt['Chk1'];
this.bChk2 = oRslt['Chk2'];
this.bChk3 = oRslt['Chk3'];
this.bChk4 = oRslt['Chk4'];
Note also that the "str" item_id's are also spelled wrong in the "initialize" function. There are however, not being used at this time, so it doesn't have any effect on the stamp behavior.
Copy link to clipboard
Copied
There's nothing obviously wrong with the code. However, the checkboxes are only getting set in one direction. This may or may not be important.
Here are two better variations:
1.
this.getField('Check Box1').checkThisBox(0, FormRouting.bChk1);
2.
this.getField('Check Box1').value = FormRouting.bChk1?"Yes":"Off";
What kind of debug have you done?
Copy link to clipboard
Copied
Also, the stamp name needs to be prefixed with "#" so the full stamp name is "#Sohail"
The "#" tells Acrobat to run the script everytime the stamp is applied.
Copy link to clipboard
Copied
Hello Thom, thanks for your help.
I have tried both variations, but the issue remains the same.
-Is anything reported in the console window?
No, I'm not seeing any errors in the console or Script window. 😞
And yes, I have added '#' to the stamp name. Thanks for letting me know. 🙂
Copy link to clipboard
Copied
There is no need for the "if" statement used to set the checkbox value. Write it like this:
this.getField('Check Box1').checkThisBox(0, FormRouting.bChk1);
this.getField('Check Box2').checkThisBox(0, FormRouting.bChk2);
this.getField('Check Box3').checkThisBox(0, FormRouting.bChk3);
this.getField('Check Box4').checkThisBox(0, FormRouting.bChk4);
And after looking through the code again I found your error. In the dialog "commit" function the item_id for the checkbox is spelled incorrectly.
Here is the corrected code:
this.bChk1 = oRslt['Chk1'];
this.bChk2 = oRslt['Chk2'];
this.bChk3 = oRslt['Chk3'];
this.bChk4 = oRslt['Chk4'];
Note also that the "str" item_id's are also spelled wrong in the "initialize" function. There are however, not being used at this time, so it doesn't have any effect on the stamp behavior.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
A Best Answer on my response would be helpful,
Thanks!
Copy link to clipboard
Copied
Hi Sonny .. just wondering if you might be able to share yout script with me for the check boxes .. your stamp does exaclt what i need but i have no scripting experiance other than copy and pasting the basic from the web - and there is nothe to help me here - i dont even know where to add teh script in the form propries for the cehckbox.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now