Copy link to clipboard
Copied
How do you change the items in a dialog popup based on the selection of another dialog popup?
"[object Aggregate]" is the type of animal that is being displayed, i.e. it is the result of turning the list object into a string. If you want to see selected value then you need a script to search the list object for the selected value. Fortunately, such code is provided by AcroDialogs.
These two lines right here, which is from the commit function, returns the selected value.
var path = new Array();
this.strpop1 = ((this.GetListSel(oRslt["pop1"],path))?path.reverse():[""])[0];
BTW: the new AcroDi
...Copy link to clipboard
Copied
Hi David,
First, thanks for being a member of www.pdfscripting.com for such a long time, many years now.
DropDown lists in an Acrobat JS dialog are loaded with the "dialog.load()" function. The easiest way to see how this is done is to just create a dialog with a dropdown list in ACRODIALOGS OVERVIEW . In the script created by AcroDialogs the list is defined at the top of the code, and then loaded in the "initialize" function. But a new list can be loaded at any time, from any function in the Dialog definition object. All you need to do is to create a new list object and then load with "dialog.load". In your case you'll need to define a function for the droplist that changes the other droplist. To do this, create a new entry in the dialog definition object with the same name as the element. This function will be called every time the user makes a dropdown selection.
Copy link to clipboard
Copied
Hi Thom, I'm still using the desktop plug-in of Acrodialogs. I created additional lists at the top and figured how to load pop2 when pop1 changes, but how do I load pop2 based on pop1? Appreciate your help. Here's my script:
var listpop3 =
{
"A--1": -1,
"A--2": -1,
"A--3": -1,
"A--4": -1,
"A--5": -1,
};
var listpop4 =
{
"B1": -1,
"B2": -1,
"B3": -1,
"B4": -1,
"B5": -1,
};
var InvoiceStampsDig =
{
result:"cancel",
DoDialog: function(){return app.execDialog(this);},
strpop1:"",
strpop2:"",
SetListSel:function(list,path){if(path.length == 0) return;
eval("list[\""+ ((typeof path.join != "function")?path:path.join("\"][\"")) + "\"] = 1")},
GetListSel:function(oLstRslts,path){
for(var item in oLstRslts){
if( ((typeof oLstRslts[item]=="number")&&(oLstRslts[item]>0))
|| this.GetListSel(oLstRslts[item],path) )
{path.push(item);return true;}
}
return false;
},
initialize: function(dialog)
{
var listpop1 =
{
"Header1": -1,
"Header2": -1,
"Header3": -1,
"Header4": -1,
"Header5": -1,
};
this.SetListSel(listpop1, this.strpop1);
var listpop2 =
{
"A1": -1,
"A2": -1,
"A3": -1,
};
this.SetListSel(listpop2, this.strpop2);
var dlgInit =
{
"pop1": listpop1,
"pop2": listpop2,
};
dialog.load(dlgInit);
},
commit: function(dialog)
{
var oRslt = dialog.store();
var path = new Array();
this.strpop1 = (this.GetListSel(oRslt["pop1"],path))?path.reverse():"";
var path = new Array();
this.strpop2 = (this.GetListSel(oRslt["pop2"],path))?path.reverse():"";
},
"pop1": function(dialog)
{
dialog.load({pop2:listpop3});
},
description:
{
name: "Invoice Stamps",
elements:
[
{
type: "view",
elements:
[
{
type: "cluster",
item_id: "cls1",
char_width: 8,
char_height: 8,
font: "dialog",
bold: true,
elements:
[
{
type: "popup",
item_id: "pop1",
width: 118,
height: 23,
char_width: 8,
},
{
type: "popup",
item_id: "pop2",
width: 117,
height: 23,
char_width: 8,
},
{
type: "view",
width: 72,
height: 27,
char_width: 8,
char_height: 8,
alignment: "align_center",
elements:
[
{
type: "ok_cancel",
font: "dialog",
bold: true,
ok_name: "OK",
cancel_name: "CANCEL",
},
]
},
]
},
]
},
]
}
};
// Example Code
InvoiceStampsDig.strpop1 = "";
InvoiceStampsDig.strpop2 = "";
if("ok" == InvoiceStampsDig.DoDialog())
{
console.println("pop1:" + InvoiceStampsDig.strpop1);
console.println("pop2:" + InvoiceStampsDig.strpop2);
}
Copy link to clipboard
Copied
I'm not sure I understand the issue. You do it the same way as the other dropdown. Just make a function for pop2.
Copy link to clipboard
Copied
I want the function for pop1 to load pop2 based on pop1. The way it is now, it loads pop2 whenever pop1 changes:
"pop1": function(dialog)
{
dialog.load({pop2:listpop3});
}
I want it to be something like
if(pop1=="Header1"){dialog.load({pop2:listpop3})}
if(pop1=="Header2"){dialog.load({pop2:listpop4})}
I don't know how to get the return value of pop1 to do this. Thanks.
Copy link to clipboard
Copied
Use the dialog's store method to get the value of the field, just like you
would in the commit event.
Copy link to clipboard
Copied
"pop1": function(dialog)
{
Rslts=dialog.store();
app.alert(Rslts["pop1"]);
},
When I use the code above, the alert says "[object Aggregate]". What am I doing wrong?
Copy link to clipboard
Copied
"[object Aggregate]" is the type of animal that is being displayed, i.e. it is the result of turning the list object into a string. If you want to see selected value then you need a script to search the list object for the selected value. Fortunately, such code is provided by AcroDialogs.
These two lines right here, which is from the commit function, returns the selected value.
var path = new Array();
this.strpop1 = ((this.GetListSel(oRslt["pop1"],path))?path.reverse():[""])[0];
BTW: the new AcroDialogs online tool has a better function designed just for regular list elements. This one is intended to work for tree lists.
Copy link to clipboard
Copied
Thanks Thom. You da man!