简体   繁体   中英

ComboBox functionality in FLEX 4

I am working on FLEX 4, and I've come across a curious problem regarding the FLEX 4combobox. Unlike a drop down list, the combo box permits the user to type in a value and the combobox will then display a list of suggested values. My problem is this: the combobox seems to permit the user to enter and save nonsensical values. For example, in the image below the list of permitted values is a collection of years from 1982 up to 2040.

在此处输入图片说明

However, the user can type "test" into the combobox and click save. The net result is that the end quarter/end year pair is 3-test . Obviously this is a nonsensical value.

Why is this happening? Is there a way to prevent this? I know the one can simply switch to drop down lists, but I prefer to keep comboboxes because of the "suggested value" functionality.

A follow-up question: Whatever fix there may be, is it possible to do it "globally"? Meaning, can we do a fix at one point in the code and it take effect throughout the entire project?

Thanks.

This is pretty standard behavior for this type of control. The ComboBox doesn't know what makes the input valid or invalid. It is designed to accept any input and it's our responsibility to validate that the input is appropriate for our applications.

There are a few things you can do, some combination of these should help:

  • Set the restrict property of the ComboBox to a string that contains only the valid characters you will allow for input, like the string "0123456789".

  • Use the maxChars property to limit the input to 4 characters.

  • Play around with the labelToItemFunction property. You can set this to a function that will decide what value to select based on the user's input.

  • Use a NumberValidator or DateValidator to validate the user has entered an appropriate value (or just add this logic yourself in the save button's click handler)

  • (probably less useful) Play around with the itemMatchingFunction property. You might be able to use this to automatically select the first/last (or whatever) value as a default rather than using the nonsensical input.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM