ComboBox Bug
So here is the situation, you want to display data in a ComboBox and make sure the user chooses something from the dropdown. You do not want the first thing showing to be real data as this could cause the user to leave it as is and also void your validation routine. So, you decide that you will all a blank as the first position by adding an empty value to the Array that is the dataProvider for the ComboBox like this:
private var dataP1:Array = [”, ‘one’,'two’,'three’,'four’,'five’,’six’,’seven’,'eight’,'nine’,'ten’];
Doing this exposes a bug within the ComboBox where the value will be replaced by a blank space on each repeat of the rowCount property. The example below has the rowCount set to 3 which is why you see one, two and then a blank where three should be. If you were to change the rowCount to , the blank would then show where the five and ten should have been.
A workaround is to use an blank space instead of an empty string in the first position of the Array like this:
private var dataP2:Array = [’ ‘,’one’,'two’,'three’,'four’,'five’,’six’,’seven’,'eight’,'nine’,'ten’];
However, all of this mess can be avoided by simply using the prompt property to add the blank space at the top of the ComboBox. It should also be noted that the blank space added by the prompty property actually sits at a selectedIndex of -1 while the workarouns above would have the blank space at a selectedIndex of 0. This doesn’t effect then functionality of the ComboBoxbut should be taken into consideration when validating.
Click here to run the application
Rich




February 26th, 2007 at 5:30 pm
Hi Rich,
I had a similar situation recently. Unfortunately, the prompt property did not work because it goes away once a user selects an item and I needed to leave a blank option. Also, the dataprovider for the ComboBox was dynamic, so I could not add the empty space beforehand.
Here is the solution that I worked out:
March 1st, 2007 at 5:02 am
Hey Darron,
Unfortunately, the code didn’t make it (damn WordPress). Can you give me a link to your solution?
May 21st, 2007 at 12:55 am
Great post, I didn’t even know the ‘Prompt’ property even existed. The only problem with the Prompt property is that it doesn’t add a blank item into the list. So if you accidentally choose a value in the ComboBox, you can’t undo it in any obvious way.
Although, there is no doubt a secret nerds-only hidden keystroke combination that can ‘unselect’ the combobox value, this won’t help the average user.
May 21st, 2007 at 12:52 pm
You can set the ComboBox back to the prompt value by setting the selectedIndex to -1.
September 5th, 2007 at 1:57 pm
Yes, one can reset the ComboBox programmatically, but how would the user do that if an item has been selected?
September 5th, 2007 at 2:15 pm
The user could not. You would need you provide a reset button.
September 17th, 2007 at 3:47 am
I now believe the prompt property is pure evil and should be avoided at least in Flex 2.
We’ve found (what for us is) a showstopping bug:
Suppose I have a typical set of interlinked comboboxes for country/state/suburb.
Picking the country restricts the states which restricts the suburbs.
We don’t want a specific value to default into any of the comoboboxes, so we used the prompt value.
Country/State and Suburb are optional fields. One or more could be filled in.
The values are saved to the database. So far, so good.
HOWEVER, they can also be retrieved from the database and edited and saved again.
The damn prompt property, however, seems to override the selectedIndex and selectedItem properties……sometimes. (PS: We’re using the enhanced combobox from forta.com which has a “selectedValue” property on it. Can’t fathom how the folks at Macromedia missed that one, by the way)
This means that the comboboxes get their values blanked out by the prompt property.
I think there are issues with competing forces trying to set the selected value of the combobox and events aren’t firing in a predictable order. Is it possible that the Prompt property is sometimes evaluated after CreationComplete?
The whole interlinked comboboxes scenario is a really typical scenario for us, but we’ve had to introduce a rule “No Prompt Properties” allowed in our dev team until we can find a fix, (which may be to override the behaviour and fix the bug)
PS: We’ve also found that setting the selectedIndex to -1 doesn’t work at all when your combobox has it’s selectedValue bound to something.
Disobedient controls are really frustrating!
September 17th, 2007 at 3:53 am
And no, selectedItem and selectedValue aren’t the same thing.
September 27th, 2007 at 12:53 am
Hi, I’m using OS 10.2 with developer tools installed from the CD in the box. I was trying to build an AS Studio application with a combo box in the interface and I came accross a strange bug. I set the combo box to generate “should begin editing” and “should end editing” events. However, whenever I would start editing the contents of the box or hit return after editing the contents, I would get an error “NSCannotCreateScriptCommandError (10)” and the event handlers wouldn’t be called. I was able to reproduce this bug reliably in the simplest manner possible. I created a new Applescript Application in Project Builder with a window in its interface and nothing in the window but a combo box set to generate “should begin editing” and “should end editing” events.
Can anybody reproduce this bug? Is it a known isssue with AS Studio? I searched all my saved emails from the AS Studio list and was unable to find any mention of this.
light bars
http://www.truckaccessorywholesale.com/specials/light_bars.html
November 8th, 2007 at 2:50 am
Hi Rich. here in tokyo.
great! thanks for your solution.
I’ve worried about this problem for a week!
thanks again~
March 20th, 2008 at 2:57 pm
That’s not a bug. There’s an empty string in the ComboBox’s list of values, why should it treat that object any different from any of the other objects in it’s list?
It’s an easy way (or alternative way) to reset the combobox back to an unselected value if you don’t want to use the ‘prompt’ setting (as mentioned above, it has issues).
Otherwise, you’d be *forced* to use a reset button to reset the form/combobox - no, we don’t want that at all.