How to add onchange event trigger in dropdowns?
Copy link to clipboard
Copied
Hi,
I try to add the onChange Event trigger in the font family dropdown. When changing the font family, load data to the font style dropdown based on the selections. I try multiple ways but had no luck. Please give your suggestions.
//get unique Array elements
Array.prototype.unique = function (){
var r = new Array();
o:for(var i = 0, n = this.length; i < n; i++){
for(var x = 0, y = r.length; x < y; x++){
if(r[x]==this[i]) continue o;}
r[r.length] = this[i];}
return r;
}
var sysFonts = app.fonts.everyItem();
sysFontsList = sysFonts.fontFamily.unique();
sysFontsList.unshift("- Select Font Family -");
var myDialog = app.dialogs.add({name:"Font"});
with(myDialog){
with(dialogColumns.add()){
with(dialogRows.add()){
with(dialogColumns.add()){
with(borderPanels.add()){
with(dialogColumns.add()){
with(dialogRows.add()){
with(dialogColumns.add()){
staticTexts.add({staticLabel:"Font:", minWidth:40});
}
with(dialogColumns.add()){
var dFontFamily = dropdowns.add({stringList:sysFontsList, selectedIndex:0});
}
with(dialogColumns.add()){
staticTexts.add({staticLabel:"Font Style:", minWidth:45});
}
with(dialogColumns.add()){
var dFontStyle = dropdowns.add();
}
}
}
}
}
}
}
}
var myResult = myDialog.show();
if(myResult == true){
}
Copy link to clipboard
Copied
Hi,
Actually, I load the data in another dropdown based on the first dropdown dynamically.
Copy link to clipboard
Copied
I don't think eventlisteners are set for the app.dialogs class and any of its properties. With dialogs, it"s all about building UI and use data once the dialog is closed.
For such events, you would like to use either ScriptUI in an extendscript script or html UI with UXP scripting:
https://developer.adobe.com/indesign/uxp/reference/uxp-scripting-samples/
HTH
Loic

