Copy link to clipboard
Copied
Hi there,
I've got the following DropDownList, but it gets rendered with no options selected. How can I make ''one" the default option for this element?
var w, layout;
layout = "dialog { \
dropdown: DropDownList { \
size: [100,20] \
properties: { \
items: ['one','two','three'] \
} \
} \
}";
w = new Window(layout);
w.show();
Thanks
There are various ways here is one way to show the value when it is changed.
var w, layout;
layout = "dialog { \
dropdown: DropDownList { \
size: [100,20] \
properties: { \
items: ['one','two','three'] \
} \
} \
}";
w = new Window(layout);
w.dropdown.selection=0;
w.dropdown.onChange= function(){
alert(w.dropdown.selection.text);
}
w.show();
Copy link to clipboard
Copied
You just have to set the selection, example.
var w, layout;
layout = "dialog { \
dropdown: DropDownList { \
size: [100,20] \
properties: { \
items: ['one','two','three'] \
} \
} \
}";
w = new Window(layout);
w.dropdown.selection=0;
w.show();
Copy link to clipboard
Copied
Thanks, that worked
Btw, how do I return the value that is selected?
For example, I change the dropdown to 'three' and I want it to return to me the number of the selected option.
Copy link to clipboard
Copied
There are various ways here is one way to show the value when it is changed.
var w, layout;
layout = "dialog { \
dropdown: DropDownList { \
size: [100,20] \
properties: { \
items: ['one','two','three'] \
} \
} \
}";
w = new Window(layout);
w.dropdown.selection=0;
w.dropdown.onChange= function(){
alert(w.dropdown.selection.text);
}
w.show();
Copy link to clipboard
Copied
Thanks guys it worked
Copy link to clipboard
Copied
The drop down list will show either the text or a number. with processing the result from a dropdownlist, you want to make sure you specify what you want or you will run into issues. To get the number of the selection you would werite:
alert(parseInt(w.dropdown.selection))
Copy link to clipboard
Copied
You need to default one. I your case 0, 1 or 2. I don't know Photoshop ScriptUI only steal other UI example and modify for my application. Here how a made font select-able note I set dd1 selection to 1 dd1 could also be change by remembering the previous run and changing dd1 prior to displaying the dialog.
dlg.msgPnl.grp6a =dlg.msgPnl.add('group');
dlg.msgPnl.grp6a.orientation='row';
dlg.msgPnl.grp6a.alignment='fill';
dlg.msgPnl.grp6a.st1 = dlg.msgPnl.grp6a.add('statictext',undefined,'Font');
fontlist = new Array();
for (var i=0,len=app.fonts.length;i
fontlist = app.fonts.name;
}
dlg.msgPnl.grp6a.dd1 = dlg.msgPnl.grp6a.add('dropdownlist',undefined,fontlist);
dlg.msgPnl.grp6a.dd1.selection=1;