Skip to main content
Brainiac
December 18, 2014
Answered

How to trigger a refresh of a dropdown list when the selection is changed

  • December 18, 2014
  • 3 replies
  • 4415 views

Hi,

This is a general ExtendScript question, but since I'm working with FM, I'll ask here first. I have a bit of a paradox here and I'm not sure of the best way to handle it.

I have a dialog box with a dropdown list, where I want to refresh certain controls when the user changes the selection in the list (dropdownList.onChange). This includes refreshing the contents of the list itself. However, the problem is, as soon as I try to refresh the list contents, it triggers onChange again. So, if I put the call to refresh the box within the onChange handler, it results in an endless loop, because my refresher function triggers onChange when it refreshes the list.

Does anyone know a better methodology, where I can safely trigger a refresh of a dropdown list within the list's own onChange event handler? I really wish that onChange was reserved for a user action only, or there was at least some property to that effect.

Russ

This topic has been closed for replies.
Correct answer Klaus Göbel

Hi Fabio,

you can't "refresh" a dropdown menu.

But you can rebuild it.

You have to do it "manually".

The way I do it:

1. I have an array that I want to show in that dropdownlist.

2. I remove all children: myList.removeAll();

3 I rebuild the list via mylist.add("item","myArray[index] in a for - loop.

But if you know the exact position of the items to remove or to add, you can do it via splice()

3 replies

New Participant
January 15, 2016

Hi Russ, would it be possible if you could please tell me how did you do to make the dropdown refresh? A script of it would be super useful! thanks in advance!

Fabio

Klaus Göbel
Klaus GöbelCorrect answer
Brainiac
January 15, 2016

Hi Fabio,

you can't "refresh" a dropdown menu.

But you can rebuild it.

You have to do it "manually".

The way I do it:

1. I have an array that I want to show in that dropdownlist.

2. I remove all children: myList.removeAll();

3 I rebuild the list via mylist.add("item","myArray[index] in a for - loop.

But if you know the exact position of the items to remove or to add, you can do it via splice()

New Participant
January 15, 2016

thanks a lot!! that worked like a charm!

Klaus Göbel
Brainiac
December 31, 2014

Hi Russ,

you can stop that with "stopPropagation()"

You can find this in "Javascript Tools Guide" on page 150.

I'm not able at the moment to send you an example 'cause I'm in a hospital for a while.

Happy New Year!

frameexpert
Community Expert
December 18, 2014

Hi Russ, At this point, I don't have a direct answer, but since this is really a ScriptUI question and doesn't relate directly to FrameMaker, I would post this to the InDesign Scripting forum. There are some ExtendScript heavyweights on that forum that might have an answer for you. -Rick