Updating dropdown list on click

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
benroll

Hi Guys,

I've been banging my head against a brick wall with this for two days now. I have a ScriptUI with a dropdown list of 3D layers. The list needs to update when the user clicks the dropdown. So I capture the focus event with an onActivate, and rebuild the list as the user clicks. The problem is that rebuilding the list prevents the list from displaying, requiring a second click to show it. I'm guessing that rebuilding the list triggers an onChange event that automatically hides the list.

OK...it's not disastrous, but it's annoying.

I thought of forcing the dropdown list to show at the end of the onActivate handler, but can't find any command that does this. I've tried capturing the events further up the UI hierarchy, but without much luck. I've tried the show() method, faking UI or custom events with dispatch() and notify(), but nothing works. I'm clutching at straws now.

I'm wondering if there is even a scripting way to pop up a dropdown menu.

The best workaround I've got so far is updating the list on a mouseover which doesn't interfere with the click, but if one of the 3D layers in the list has been removed in the meantime, there's a nasty jump on rollover.

Can anyone help before I go insane? :)

Thanks.

Ben.
benroll

I've been working a bit further and I'm going to condense my question:

Is there a way to change the contents of a dropdown menu when a user clicks it without the menu disappearing (or failing to show)?

And is there a way to drop down a dropdown menu from script without the user clicking it?

Hope that's a bit more succinct.

Thanks if you can help.

Ben.
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

Why does your listbox disappear when clicked? Is that something you've coded it to do?

If you have an "onChange" function that you don't want to be called, you can temporarily set it to null (e.g. listbox.onChange = null) while updating the listbox, then reassign it to the onChange function when you're done.

Do you have some test code you could post so we don't have to write a test script from scratch?

Paul
benroll

Hi Paul,

It seems that changing the contents of a drop down list at the point the user clicks it automatically makes the dropdown disappear.

I made the script linked below to test the UI, with a big edit text window to show the events as they're caught by handlers at various levels in the UI hierarchy. Incidentally... the event order I get doesn't seem to quite correspond to the capture / target / bubble described in the documentation.

If you run the script in AE with a couple of 3D layers selected, you see the problem. On the first click of the dropdown, nothing happens... on the second it works. Then it continues to work until the focus is taken away from the dropdown (by clicking the clear button for instance) and then the process repeats. Here the list is being initialised when focus lands on the dropdown.

If I remove the call to the ddInit(); function at line 135, the functionality of the dropdown returns. If I put the ddInit() on the mouseDown instead of focus by uncommenting line 104 and commenting out line 97, then the dropdown never drops down at all. The only reason it works after the first click with the focus method is that the focus is already on the dropdown.

http://www.benrollason.com/temp/aenhancers/UItest4.jsx (The test script is 300 lines or so, so I thought I'd post a file rather than clog up the browser window)

If you've got time and energy, let me know if you can make head or tail of it.

Thanks.

Ben.
Post Reply