4 Replies Latest reply on Jun 18, 2014 4:02 AM by myDavey

    Change contents of droplist

    myDavey Level 1


      Is it possible to change the contents of a droplist after its made?

      I have a dialog, and based on the user input, the droplist must change

      I've seen the possibility to add to a droplist, but I havent seen the possibility to change the whole list

      Is this possible?




        • 1. Re: Change contents of droplist
          Trevorׅ Adobe Community Professional
          #targetengine test
          var w = new Window ('palette'),
              d1 = w.add('dropdownlist', undefined, [1,2,3,4,5]),
              b1 = w.add('button', undefined, "Slow Refresh"),
              b2 = w.add('button', undefined, "Fast Refresh"),
              myNewItems = [6,7,8,9,10];
          b2.onClick = function () {refreshList (myNewItems)};
          b2.onClick = function () {refreshList2 (myNewItems)};
          d1.onChange = function () {alert(d1.selection)};
          function refreshList (newItems) {
              var l = d1.items.length,
              while (l--) d1.remove(d1.children[l]);
              l = newItems.length, c;
              for (c = 0; c < l; c++) d1.add('item', newItems[c]);
          function refreshList2 (newItems) {
              tempDropdownlist = w.add('dropdownlist', d1.bounds, newItems);
              tempDropdownlist.onChange = d1.onChange; // etc.
              w.remove (d1);
              d1 = tempDropdownlist;



          • 2. Re: Change contents of droplist
            myDavey Level 1

            Hi Trevor

            Thanks for the nice response

            It works great!


            Unfortunately, I didnt end up needing it

            I have a script which uses a modal dialog which allows user to choose a file from openDlg

            if and when the user chooses an INDD file, I have to update some info in the dialog. (One of them was this droplist)

            After I saw your code and went back to the script I realized that this is not possible because

            in order ot get the info from the iNDD file, I have to open it in the background, but since I have a modal dialog open.... the story ends here


            If anyone has any advice for this, I would appreciate it




            • 3. Re: Change contents of droplist
              Trevorׅ Adobe Community Professional

              It will work if you use 'palette' with a #targetengine as I did.

              You cannot use 'dialog' as you are trying.

              • 4. Re: Change contents of droplist
                myDavey Level 1

                Thanks Trevor

                I was thinking of that, but the script, and the dialog, is so long..... its not going to be an easy switch

                However, I started changing it and it seems like it might work

                I'm sure I'll need some tune-ups, but on the most part - its working!






                P.S. just to mention...

                In your sample script above, both functions seem to work well

                However, when I implemented it into my script

                First I tried "refresh2" and it didnt work

                The line " w.remove (d1);" was causing an error saying "inavlid parameter, object droplist"

                I am not sure why - it seems right

                I ended up using refresh1 and everything seems great