6 Replies Latest reply: Nov 20, 2014 5:02 PM by Gespinha RSS

    DropDownList value selected by default?

    Gespinha Community Member

      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

        • 1. Re: DropDownList value selected by default?
          Philip Cord Community Member

          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(); 
          
          
          • 2. Re: DropDownList value selected by default?
            JJMack Community Member

            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[i] =  app.fonts[i].name;

                    }

              dlg.msgPnl.grp6a.dd1 = dlg.msgPnl.grp6a.add('dropdownlist',undefined,fontlist);

              dlg.msgPnl.grp6a.dd1.selection=1;

            • 3. Re: DropDownList value selected by default?
              Gespinha Community Member

              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.

              • 4. Re: Re: DropDownList value selected by default?
                Philip Cord Community Member

                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(); 
                
                • 5. Re: DropDownList value selected by default?
                  csuebele CommunityMVP

                  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))

                  • 6. Re: DropDownList value selected by default?
                    Gespinha Community Member

                    Thanks guys it worked