ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Scripting - DropdownList Selection/Enabling issue

COW Forums : Adobe After Effects

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Will Poillion
Scripting - DropdownList Selection/Enabling issue
on Mar 22, 2019 at 10:35:46 pm

I have this UI issue I can't figure out. I have a dropdownlist in which I enable/disable options based on other fields and a checkbox. If an option is currently selected that is being disabled, I select the next enabled option. Sounds simple enough right? But I can't get the selection to go away.



In the screenshot you can see that the disabled option towards the bottom was the previous selection, but then it was disabled and the next available (1/8) is automatically selected. But I can't figure out why the disabled one is still selected, and it wouldn't be an issue if when the options were re-enabled it for some reason automatically selected the older option.

Here's the function that enables/disables and selects/de-selects the options:


var currentlySelectedIndex = (midi_smith.noteLengthDD.selection != null) ? midi_smith.noteLengthDD.selection.index: midi_smith.noteLengthDD.items.length-1 ;
midi_smith.noteLengthDD.selection = null;
for (var i =0; i < midi_smith.noteLengthDD.items.length; i++) {
midi_smith.noteLengthDD.items[i].selected = false;
if ((maxEase*(midi_smith.NOTE_LENGTH_ALLOW_FACTOR+1)) < (midi_smith.bpmNoteLengths[midi_smith.noteLengthDD.items[i].text])) {
midi_smith.noteLengthDD.items[i].enabled = false;
} else {
midi_smith.noteLengthDD.items[i].enabled = true;
}

}

var found = false;
if (midi_smith.noteLengthDD.items[currentlySelectedIndex].enabled == false) {
for (var i =midi_smith.noteLengthDD.items.length-1; i >= 0; i--) {
if (midi_smith.noteLengthDD.items[i].enabled == true && found == false) {
midi_smith.noteLengthDD.selection = midi_smith.noteLengthDD.items[i];
found = true;
}
}
}


Apologies for the lengthy variables, I'm posting all of it just in case it helps but mainly just worried about
midi_smith.noteLengthDD.selection = null
midi_smith.noteLengthDD.items[i].enabled = true/false

The intent was I get the current selected index and then nullify the selection. Then I loop through and disable/enable options. The next section checks if the currently selected index was disabled. If so, loops through the list, starting at the end, and selects the first enabled option.

All the documentation I can find says just the selection property of the dropdownlist object to null erases any selection
midi_smith.noteLengthDD.selection = null

Which I'm doing before I disabling any options. I thought it was getting stuck because I was nullifying the selection after I disabled it, but it's the first thing I do.

Any help would be greatly appreciated guys! Thank you so much!

Will


Return to posts index

Mike Sevigny
Re: Scripting - DropdownList Selection/Enabling issue
on Mar 27, 2019 at 11:52:28 am

Hey Will,

I've been working with dropdowns for a while now and I've never had to de-select anything. If I programmaticly select a new item in the dropdown, the previous item is automatically de-selected. I'm surprised to see that both items are selected in your screengrab so maybe I'm missing something but try to comment out the lines where you de-select the item and see if it works for you.

It's a bit difficult to put your code to the test with the given excerpt. I've found that I get a better response if I can boil the problem down to a small GUI (dropdown and checkbox) running the problematic function so that the code is easily executable for anyone to help. This is useful to help solve particularly sticky problems and it frames it in a way that is easy to post if it still can't be solved.

Mike


Return to posts index

Will Poillion
Re: Scripting - DropdownList Selection/Enabling issue
on Mar 27, 2019 at 8:20:33 pm

Thank you Mike!

I knew my code wouldn't be easily testable and I apologize for that. I was hoping someone would just provide their own experience and give me a hint to figure it out and you did.

When you said you never de-select I thought that might be doing it and it was at least partly.

Setting this doesn't work as you might expect:
midi_smith.noteLengthDD.selection = null;

It did de-select but I think it messed up the internal object structure of the dropdown. So I removed this and only changed the selection never nulled it out.

Which just means I had to add some extra error checking. What I also found was disabling options that were already disabled seemed to mess it up as well. I thought if I got the current selection index, I could enable/disable all the options (including enabling ones that were already enabled, etc) and then loop through all the options and if the currently selected index was now disabled, select the closest enabled option. Which meant re-selecting the same option if it wasn't disabled.

This just seemed to mess stuff up. When I added the error checking to only disable/enable options that weren't already in that state, and only change the selection if current selection was disabled, it's working fine now.

But just the hint of not de-selecting only changing the selection gave me the hint I needed 😉

Thanks!


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]