Skip to main content
Inspiring
August 19, 2020
Answered

dialog box with checkboxes

  • August 19, 2020
  • 1 reply
  • 1442 views

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

This topic has been closed for replies.
Correct answer try67

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 = "";
}

 

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
August 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";
else this.getField("text1").value = "";
}

 

blazbAuthor
Inspiring
August 19, 2020

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 = "";
}

try67
Community Expert
Community Expert
August 19, 2020

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