• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

dialog box with checkboxes

Explorer ,
Aug 19, 2020 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

TOPICS
Acrobat SDK and JavaScript

Views

759

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
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 19, 2020 Aug 19, 2020

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

...

Votes

Translate

Translate
Community Expert ,
Aug 19, 2020 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 = "";
}

 

Votes

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
community guidelines
Explorer ,
Aug 19, 2020 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 = "";
}

Votes

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
community guidelines
Community Expert ,
Aug 19, 2020 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.

Votes

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
community guidelines
Explorer ,
Aug 19, 2020 Aug 19, 2020

Copy link to clipboard

Copied

LATEST

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

Votes

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
community guidelines