Highlighted

dialog box with checkboxes

Community Beginner ,
Aug 19, 2020

Copy link to clipboard

Copied

Can someone pls help me. I'm trying to create dialog box but I got stuck at checkboxes and don't know how to proceed, I have looked
online for examples but still can't figure it out.
What i want is if checkbox is checked and when ok button is pressed to target specific field,
(example: ckb1 is checked and when ok button pressed field "text1" get value of 10, if ckb2 is checked "text1" get value 20...etc)
(I won't be checking both at the same time so it doesn't matter what happen if both are checked at the same time.)
I'm not asking for code just explanation or example how to do it. Thanks

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Before the dialog definition create a variable to hold the result, like this:

 

var ckb1, ckb2;

 

Then in the dialog's commit function apply the value of the check-boxes to those variables, like so:

 

commit: function (dialog) {
var results = dialog.store();
ckb1 = results["ckb1"];
ckb2 = results["ckb2"];
},

 

Then after the call to execDialog add something like this:

 

if (app.execDialog(dialog1)=="ok") {
if (ckb1) this.getField("text1").value = "10";
else if (ckb2) this.getField("text1").value = "20";
else this.getField("text1").value = "";
}

 

TOPICS
Acrobat SDK and JavaScript, How to

Views

42

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

dialog box with checkboxes

Community Beginner ,
Aug 19, 2020

Copy link to clipboard

Copied

Can someone pls help me. I'm trying to create dialog box but I got stuck at checkboxes and don't know how to proceed, I have looked
online for examples but still can't figure it out.
What i want is if checkbox is checked and when ok button is pressed to target specific field,
(example: ckb1 is checked and when ok button pressed field "text1" get value of 10, if ckb2 is checked "text1" get value 20...etc)
(I won't be checking both at the same time so it doesn't matter what happen if both are checked at the same time.)
I'm not asking for code just explanation or example how to do it. Thanks

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Before the dialog definition create a variable to hold the result, like this:

 

var ckb1, ckb2;

 

Then in the dialog's commit function apply the value of the check-boxes to those variables, like so:

 

commit: function (dialog) {
var results = dialog.store();
ckb1 = results["ckb1"];
ckb2 = results["ckb2"];
},

 

Then after the call to execDialog add something like this:

 

if (app.execDialog(dialog1)=="ok") {
if (ckb1) this.getField("text1").value = "10";
else if (ckb2) this.getField("text1").value = "20";
else this.getField("text1").value = "";
}

 

TOPICS
Acrobat SDK and JavaScript, How to

Views

43

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 19, 2020 0
Most Valuable Participant ,
Aug 19, 2020

Copy link to clipboard

Copied

Before the dialog definition create a variable to hold the result, like this:

 

var ckb1, ckb2;

 

Then in the dialog's commit function apply the value of the check-boxes to those variables, like so:

 

commit: function (dialog) {
var results = dialog.store();
ckb1 = results["ckb1"];
ckb2 = results["ckb2"];
},

 

Then after the call to execDialog add something like this:

 

if (app.execDialog(dialog1)=="ok") {
if (ckb1) this.getField("text1").value = "10";
else if (ckb2) this.getField("text1").value = "20";
else this.getField("text1").value = "";
}

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 19, 2020 0
Community Beginner ,
Aug 19, 2020

Copy link to clipboard

Copied

I tried to replicate what you told me but it's missing something can you take a look pls?

 

var dlg = {
var ckb1,ckb2;
commit: function(dialog)
{
var results = dialog.store();
ckb1 = results["ckb1"];
ckb2 = results["ckb2"];
},

description: { name: "", elements: [
{type: "cluster",name: "Choose value",align_children: "align_row", elements: [
{type: "check_box",item_id: "ckb1",name: "10"},
{type: "check_box",item_id: "ckb2",name: "20"},
]},
{ type: "ok_cancel",},
]}
};

app.execDialog(dlg);
if (app.execDialog(dlg)=="ok") {
if (ckb1) this.getField("text1").value = "10";
else if (ckb2) this.getField("text1").value = "20";
else this.getField("text1").value = "";
}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 19, 2020 0
Most Valuable Participant ,
Aug 19, 2020

Copy link to clipboard

Copied

The definition of the two variables should be OUTSIDE of the function definition, and you should only call execDialog once.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 19, 2020 0
Blaž LATEST
Community Beginner ,
Aug 19, 2020

Copy link to clipboard

Copied

Thank you for your help, it's working now.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 19, 2020 0