Copy link to clipboard
Copied
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
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()
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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()
Copy link to clipboard
Copied
thanks a lot!! that worked like a charm!
Copy link to clipboard
Copied
Fabio, I never went back to try Klaus' advice, because the project was over by that time. I should have responded to thank him anyway... Klaus, my apologies for that. Please take a look at what Klaus suggests and accept my well-wishes for good luck .
Russ