• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Mentor ,
Dec 18, 2014 Dec 18, 2014

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

TOPICS
Scripting

Views

3.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Jan 15, 2016 Jan 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()

Votes

Translate

Translate
Community Expert ,
Dec 18, 2014 Dec 18, 2014

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Dec 31, 2014 Dec 31, 2014

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 15, 2016 Jan 15, 2016

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 15, 2016 Jan 15, 2016

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 15, 2016 Jan 15, 2016

Copy link to clipboard

Copied

LATEST

thanks a lot!! that worked like a charm!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jan 15, 2016 Jan 15, 2016

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines