Hello. I have a new blog.

I've moved this blog to the following URL Kerkness.ca. Thank you for visiting, please update your bookmarks.

Tuesday, May 20, 2008

Multiple AutoComplete Input Controls in a single Flex Form

A very nice component which is available from Adobe is their AutoComplete ComboBox. The AutoComplete Combo box looks like a regular TextInput component but will provide suggestions to the user as they type. This is very handy when you want to let users select from a long list of options ( such as a list of Countries ).

Jen Krause has posted a modified version of the component which allows the user to press ENTER, TAB or click their mouse button to select the first selected item. This is a very nice modification.

A problem I ran into however was using multiple AutoComplete components in the same Flex form. If you try and put more than one AutoComplete component in the form, the first component looses the label of the selected item when you begin using the second component. I wasn't able to determine the cause of this problem but I was able to provide a simple work around.

If you've run into a same problem, you can fix it by making the following change to the class' focusOutHandler method.

// Change this method ...
override protected function focusOutHandler(event:FocusEvent):void
{
super.focusOutHandler(event)
if(keepLocalHistory && dataProvider.length==0)
addToLocalHistory();
}

// To this ....
override protected function focusOutHandler(event:FocusEvent):void
{
super.focusOutHandler(event)
if(keepLocalHistory && dataProvider.length==0)
addToLocalHistory();
_typedText = textInput.text; // replace typedText with textInput.text
}

I'm not sure if there are any ramifications to this fix but I haven't found any additional problems in my own application.

UPDATE
Turns out there are numberous implications when using multiple AutoComplete Input controls in the same form specifically when you want to try and set the value of the controls with actionscript. If you only need one AutoComplete input control then this component works really well and is very user friendly. However if you need multiple controls you may want to re-consider your form design choices.

1 comment:

  1. Hey, I ran into a bunch of issues myself with the AutoComplete component and ended up writing my own.

    You can check it out at http://hillelcoren.com/2008/11/10/flex-autocomplete-component-a-new-take-on-an-old-standard/

    Best,
    Hillel

    ReplyDelete

Thank you for the comments.