»User: »Password:   Remember Me? 
ScriptUI Forums / ScriptUI / ScriptUI Q&A / Numeric up-down in ScriptUI
Posted:  12 May 2009 22:19
Indesign has many numeric edittext's which has an up/down toggle on it's left side. Could someone post code to simulate that behavior.
Posted:  12 May 2009 22:41
Here is my code example:
Code:

var rapidDlg = new Window('dialog',"",undefined);
buildWindow();
rapidDlg.show();

function buildWindow(){

// Properties for rapidDlg.Panel1
    rapidDlg.Panel1 = rapidDlg.add('panel',undefined,undefined, {borderStyle:'grey'});
    rapidDlg.Panel1.margins= [0,0,0,0];
    rapidDlg.Panel1.orientation = "row";
    rapidDlg.Panel1.spacing = 1;
rapidDlg.Panel1.graphics.backgroundColor = rapidDlg.Panel1.graphics.newBrush(rapidDlg.Panel1.graphics.BrushType.SOLID_COLOR,[1,1,1],1);

// Properties for rapidDlg.Panel1.sb
    rapidDlg.Panel1.sb = rapidDlg.Panel1.add('scrollbar',undefined,100000,0,100000);
    rapidDlg.Panel1.sb.alignment = [' ','fill'];
    rapidDlg.Panel1.sb.preferredSize.width = 15;
    rapidDlg.Panel1.sb.onChanging = function(){
        this.parent.et.text=this.maxvalue-this.value;
    }
// Properties for rapidDlg.Panel1.et
    rapidDlg.Panel1.et = rapidDlg.Panel1.add("edittext{text:'0',justify:'center', properties:{borderless:true}}");
    rapidDlg.Panel1.et.characters = 8;
    rapidDlg.Panel1.et.onChanging =setScrollBar;
}
function setScrollBar(){
    //first make sure it' a number
    if (setScrollBar.staticNumber==undefined){setScrollBar.staticNumber='0'}
    if(!isNaN(+ this.text)){setScrollBar.staticNumber=this.text}
    else{
        this.text='';        //removes the new text
        this.textselection=setScrollBar.staticNumber        //adds the old text with selection at end of written text
    };    
    //set scrollbar to match number in edittext
    var sb = this.parent.sb;
    sb.value = sb.maxvalue-(parseInt(+this.text));
}


The windowless textedit might be CS4 only, but it can be changed a little for CS3, but then the scrollbar will not be included in white background.