Permanent ComboBox Prompt in Flex 2

Gent pinged me on AIM.

“How do I get a ComboBox prompt?”

“Use the ComboBox prompt property.”

“Yeah, but it leaves once you select an item.”

“Put the prompt as the first item in the dataProvider.”

“Can’t do that for this context.”

“Make a custom list that has a prompt above it, and replace ComboBox’ dropdown with your new list.”

“I can’t, I’m about to go pimpin’ on a Friday night, and your not, so code it, sucka!”

“Pssff, you wish you had this grill. Fine…”

So, I attempted to do so in 2 hours, and gave up. Here are my results. Basically, you put a Label above the List. You then extend ComboBox to override the drop down factory so it uses your List instead. The only uncool part is you have to extend ListBase; kind of frustrating when I’m implementing all those interfaces, only to be forced into an inheritance tree… bleh! Extending ComboBox is a pain in the neck because everything is private; frustrating. Anyway, definitely not production code, but should get you started.

After talking to her majesty, there is actually a usability issue with drop downs on web pages in that, once you select an item, you can no longer “de-select” an item by selecting the prompt again if one doesn’t exist. Therefore, I stick to my original suggestion; throw the prompt item in the dataProvider instead.

Permanent ComboBox Prompt – View Source | ZIP

6 Replies to “Permanent ComboBox Prompt in Flex 2”

  1. The Prompt is weird. Here’s my thinking:

    Let’s say you have a user who is selecting a country from a drop down list. That user also has to select a region. Well, some ISO countries have no regions, like, for example, Aruba. So the prompt always has to be conditional based on the length of the dataprovider.

    I think most people like myself are going crazy with the prompt. I use it as a default in a custom combobox subclass. In the view, I usually run some added logic for a second prompt if the drop down list may or may not have values. For example, if (country_cbo.dataProviders.length > 0 ? prompt = select region } else { prompt = no regions available for selection). Mind you, that’s seudo code. :)

    What the combobox needs is an attribute that says, ‘isSelectedItemAPrompOfValues’ It’s long, but it’s specific. :)

    Then, I can ensure that my users have interacted with my combobox ever after it has changed AND, I can be certain the combobox should be selected. I clearly can’t use selectedIndex > 0, and I most certainly can’t check the prompt of the box because it changes for usability and internationalization would be a nightmare.


  2. Hi Jesse,
    I was looking for something else regarding Flex’s ComboBox and somehow ended up here.

    Anyway, you can use the selectedIndex and set it to -1 to show the prompt again.


    Almog Kurtser

Comments are closed.