Sunday, August 26, 2007
ScriptUI Dialog with drop-down
			  I found the documentation for drop-down lists to be less easy to follow than for simpler objects. The script ended up being a lot simpler than I was at first led to believe by the combination of scant information in the Tools Guide and the structure of the object model. Here's what I ended up with:
			  
			
 
  //DESCRIPTION: Simple ScriptUI Drop-down ListI had the following difficulties:
listStrings = ["25%", "50%", "75%", "90%", "100%", "110%", "125%", "140%", "200%", "400%"];
myDlg = new Window('dialog', 'Drop-down List');
myDlg.orientation = 'column';
myDlg.alignment = 'right';
//add drop-down
myDlg.DDgroup = myDlg.add('group');
myDlg.DDgroup.orientation = 'row';
myDlg.DDgroup.add('statictext', undefined, "Zoom Percentage");
myDlg.DDgroup.DD = myDlg.DDgroup.add('dropdownlist', undefined, undefined, {items:listStrings})
myDlg.DDgroup.DD.selection = 4;
myDlg.closeBtn = myDlg.add('button', undefined, 'OK');
// add button functions
myDlg.closeBtn.onClick = function() {
this.parent.close();
}
result = myDlg.show();
alert(myDlg.DDgroup.DD.selection);
- I didn't know how many undefineds to include in the add statement for the list. I arrived at two by trial and error. I imagine that the first one is for the dimension information. I'm not sure what the second one is.
- I expected to have to create an array of listItems for the items property of the drop-down, but the array of strings sufficed.
- I went through a number of hoops trying to work out how to set the initial value of the selection before stumbling on the simple use of the index to 100%.
- As a result of that, I was amazed to discover that the selection returns the selected value and not the index into the list.
	
			Comments:
			
			
 
<< Home
				 
				Have you considered to use the scriptui resource language rather than coding all those initalizations? I can't yet recommend because I haven't tried it myself.
				
				
			
			
			
				 
				In response to point 4. If that alert had read:
alert(Number(myDlg.DDgroup.DD.selection));
then the index would have been returned.
To extract the number from the string, I could have used:
alert(Number(String(myDlg.DDgroup.DD.selection).replace(/\D/,"")));
				
				
			
			
			Post a Comment
	
	alert(Number(myDlg.DDgroup.DD.selection));
then the index would have been returned.
To extract the number from the string, I could have used:
alert(Number(String(myDlg.DDgroup.DD.selection).replace(/\D/,"")));
<< Home



