2 Replies Latest reply on Aug 5, 2014 1:25 PM by creativejoan0425

    Dropdown list remember last selected

    creativejoan0425 Level 1

      I have a dropdownlist dialog, and I want to remember last selected, and next time when I run the script the selectedIndex will be the last selected index, for example, when I select number 3, it will type 3 in the insertionPoints, and next time I run the script again, I want the Selected:3

       

       

      myDisplayDialog();

      function myDisplayDialog(){

      var myDialog = app.dialogs.add({name:"Symbol_v1.0"});

        with(myDialog.dialogColumns.add()){

        with(dialogRows.add()){

        with(dialogColumns.add()){

        staticTexts.add({staticLabel:"Selected: "});

                      var mySymbolArray = ["1","2","3","4","5"];

                      var myEachSymbol = mySymbolArray.toString().split(",");

                    with(dialogColumns.add()){

                         var myDropdownsTran = dropdowns.add({stringList:mySymbolArray, selectedIndex:0});

                          //myDropdownsTran = dropdowns.add({stringList:mySymbolArray, selectedIndex:0});

                          

                     }

                  }

              }

          }

       

       

       

       

      var myResult = myDialog.show();

        if(myResult == true){

       

       

              app.selection[0].texts[0].contents  = myEachSymbol[myDropdownsTran.selectedIndex];

      }

      }

        • 1. Re: Dropdown list remember last selected
          Jump_Over Level 5

          Hi,

           

           

          What if nothing selected... or unintentionally some text is selected... or you will run a dialog after few days of break...

          Filling a contents of some doc's textFrame is a weak solution.

           

          You could use app.insertLabel("key_name","key_value") method.

          It will keep "key_value" till your app.preferences stay unreset. Check it:

          myDisplayDialog();
          function myDisplayDialog(){
          var myDialog = app.dialogs.add({name:"Symbol_v1.0"});
          var mSel = Number(app.extractLabel("Dialog_1_dropdown_sel"));    // to read a value
          if ( isNaN(mSel) ) mSel = 0;     //     to set 1st run with 0
            with(myDialog.dialogColumns.add()){
            with(dialogRows.add()){
            with(dialogColumns.add()){
            staticTexts.add({staticLabel:"Selected: "});
            var mySymbolArray = ["1","2","3","4","5"];
            var myEachSymbol = mySymbolArray.toString().split(",");
            with(dialogColumns.add()){
            var myDropdownsTran = dropdowns.add({stringList:mySymbolArray, selectedIndex:mSel});
            }
            }
            }
            }
          var myResult = myDialog.show();
          if(myResult == true){
            app.insertLabel( "Dialog_1_dropdown_sel", String(myDropdownsTran.selectedIndex) );     // to write a value
            }
          }
          

           

          Warning. You need to remember "key_name" cause there is no way to list existing keys.

           

          Jarek

          • 2. Re: Dropdown list remember last selected
            creativejoan0425 Level 1

            Thx Jarek, it very helpful