Note: Something wonky was going on the first time I tried this and it turns out that this is very easy to do without extending the ComboBox. Lesson learned: if you really, REALLY think something should work and it doesn’t then reboot and try again.
You would think that if you make a Flex ComboBox editable then it would be easy to get the value that the user typed in, right? I mean, why else give a ComboBox a property of editable. It’s one of those things that seems so obvious that I spent an hour running through the debuger looking for the value I had typed in that I thought I must be missing something.
If I’m missing something I’d appreciate it if someone would point out to me just how you can get the value*. As it turned out it was very easy to do by extending the ComboBox and overriding the textInput_changeHandler method. As I was trying to find an obvious way to get at the data I kept thinking, “Just override the frakking ComboBox to get at the data.” I should have listened to that inner voice sooner and saved an hour of frustration.
| view source |
After lots of searching about the only useful post I found was this one by strikefish at UniversalMind. They’re ComboBox-lookAhead is really cool. This is where I figured out to override the textInput_changeHandler to get at the data I needed.
I’d appreciate your comments if you can think of ways to improve this approach.
*Note: guessing that if it can be done Tink will be the first to comment the solution. Don’t let me down Tink. :-)





I just tested this out and you should be able to access what the user is typing into the combobox by
combobox.value
This parameter holds whatever is currently displayed in the “text” area of the combobox.
@Gareth, I swear to the gods I tried that. Over and over. Did it just now, to the same code I was working with before and it works.
Maybe my code had a 24-hour flu or something. :-)
[code]
[/code]
bugger that didn’t work very well huh!
I appreciate your confidence in me ;)
You can use ‘text’ or ‘value’.
I feel your pain :). There have been times that something is just not working, I try everything I can think of for an hour, I ask my fellow coders for help, they stand next to me (without changing anything), I re-compile, and what do you know…it works. :)
Hey thanks for the example. Rather than handling text input I overrode focusOutHandler to update the input text. This was much cleaner for me because it didn't force users to hit enter on the combo box and I didn't have to handle ListEvent.CHANGE and FlexEvent.ENTER events I could just bind to the inputText property
hey there ,
Can one just get the combo box property for what u intend to do ? I am pretty new to flex , but i think it can be done. Or did i miss something.
Sorry for posting a comment for a post this old .
Martin
@Martin, yes – you can just get the comboBox.value. That was mentioned in the comments. I tried that first and it didn't work so I went through these steps as a workaround. Turns out that my first guess was correct and I had just made a simple mistake.
Thanks for sharing. Very informative.
exemple from my source(chage yourself)
if (subwindow.xcombo.selectedLabel==null) {
thisSubNode.@x=subwindow.xcombo.prompt;
} else {
thisSubNode.@x=subwindow.xcombo.selectedLabel;
};
trace(subwindow.xcombo.selectedLabel);
if nothing- take prompt
if change or edit -take selected label
it works