Ok…this is one of those things that plagued me mentally because I blocked out possibilities. My main obstacle was in the approach. Should I add a key listener and check to see what field you’re in then have the appropriate buttons click event called? Nope…that sucks. Should I add a listener, to the _TextInput_ fields, for _keyUp_ or _keyDown_ and check to see if it was the _ENTER_ key? Nope…sucks too.

This wasn’t a big issue for me but I saw the question around a few times. Normally I had a situation where I was building a form and in that form you could assign a _defaultButton_ which would take care of calling the _click_ event for the _defaultButton_. That’s cool but using _Form_ means a vertical layout, right? WRONG! This is where I went wrong in my own mind.

I wrote this on (mental) stone tablets: “All display objects inside a _Form_ tag shall be _Formitem_ tags.” True but not. You can have a nice vertical form using _FormItem_ tags but sometimes you might not need all of the extra padding, etc that comes with _FormItem_’s and you might just want a _TextInput_ with a _Button_ to the right of it. Well, _Form_ is still your quick and easy answer.

bq. <mx:Form defaultButton=”{loadButton}”>
<mx:TextInput id=”feedURL” />
<mx:Button id=”loadButton” label=”Load” click=”someHandler(event)” />

That’s it. Now clicking _loadButton_ with the mouse or hitting the _ENTER_ key will call _someHandler_, _loadButton_’s _click_ event handler.

Hopefully this helps someone. Keep reading for a couple clarities.

1) I know _FormItem_ has a _direction_ property which has a _horizontal as one of the options so vertical layouts are not the only type you can achieve with a _Form_/_FormItem_ combination. If you look at the space/padding for the _label_ of a _FormItem_ it isn’t as clean as throwing the _Form_ in an _HBox_ or putting an _HBox_ as the first child in the _Form_.
2) There are scenarios, I’m sure…somewhere in the world, where a listener for the _ENTER_ key in a _TextInput_ is needed. I’m not bashing all scenarios…just the general one of assigning a default button.

That’s all of the clarities I think. 🙂 L8rz!