-
Scripting – DropdownList Selection/Enabling issue
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/falseThe 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 = nullWhich 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