Thu 14 Sep 2006
Hi! I haven’t posted anything in awhile because (besides my usual laziness) I’ve been travelling a lot lately, visiting customers as part of our user research for the next version of Flex and Flex Builder. We did a mix of watching people work and showing them some early feature concepts, and as always, both parts were very enlightening.
This post is about a simple but useful Flex component I wrote recently: the “self-labeling” text input field. Instead of labeling a text field the usual way, by putting a label to the left of the field, you can put the label inside the text input field itself (in a light gray color); when the user clicks in the field, the label automatically goes away. It’s a nice way to conserve real estate and make the UI less visually noisy. Here’s an example:
(The search box at the bottom is another little component that uses the self-labeling text input field. In this case, the borders of the actual field are hidden, so it blends into the surrounding container. I implemented it in AS for no particularly good reason—it could easily have been an MXML component with a tiny bit of script.)
You have to be a little careful when choosing to use this type of field, because the user can’t actually see the label when they’re typing in it, or when the field is already filled in. So it’s best used when:
- the field’s meaning is obvious from context (e.g. the caption under a photo), or
- there’s an icon associated with the field (as in the search box above), or
- the form is very familiar, and the meaning of the fields is obvious even when they’re filled with actual content (as in the address example above; a username/password form would be another possible example).
Here’s the source code. Using the SelfLabelingTextInput is simple—it’s just like a TextInput with one extra parameter, label, that sets what the field should show when it’s empty.
Hope you find this useful!
[Update: Per Stacy Young's suggestion, I made it so the label also gets set as the tooltip for the field, so you can figure out what the field is even if it has content in it.]
digg this |
del.icio.us |
September 14th, 2006 at 1:11 pm
Sweet idea ! I wanted to peek at the source, but the usual right-click to “View Source” redirects to the post itself, not the source, maybe some url rewriting side effect ?
Nice blog BTW.
September 14th, 2006 at 6:14 pm
Oops, you\’re right. There\’s a separate link to the source later in the blog entry that does work; click here for the same link. I\’ll fix up the SWF later. Thanks!
September 14th, 2006 at 6:16 pm
How about also setting the tooltip to the field label? Then the user will see the label on mouseover etc.
September 14th, 2006 at 6:24 pm
Good idea–I’ll do that in my example. I do still think it’s not a good idea to use this heavily for unfamiliar forms that may need to be re-edited, since users won’t want to have to tooltip over fields to remind themselves what they are if they’re already filled in.
September 15th, 2006 at 8:23 pm
Thanks for posting this and the source code. I’ve added your action script classes to a project I’m working. I kept your comments in . Very cool.
Bruce
September 15th, 2006 at 9:23 pm
Glad you found it useful!
September 27th, 2006 at 7:41 am
[...] Компонент, в поле ввода которого можно увидеть его название. При наведении фокуса - название исчезает и позволяет ввести данные. [...]
October 15th, 2006 at 11:45 am
I had problems with this component when I had only typed in one character. It seems that the handleTextChange was dispatching an event before the text property was updated with the character. Fixed it by changing a line in SearchBox.as:
I replaced this:
dispatchEvent(new Event(Event.CHANGE));
with this:
callLater(dispatchEvent, [new Event(Event.CHANGE)]);
Works a treat for me! Thanks for the great component!
October 15th, 2006 at 5:52 pm
Adz–thanks for the bugfix! I’ve updated the source and sample with your code.
January 8th, 2007 at 1:29 am
I found bug!
March 6th, 2007 at 4:33 am
Thanks for posting this and the source code.really helped me.thanks.
July 20th, 2007 at 8:53 pm
Adz fix is not working for me. Have the same issue, even with the callLaterDispatch.
Thx for the code!
Wishlist: Visual Component for Flexbuilder for an easier design. An outline would be enough.
October 29th, 2007 at 5:31 pm
Thank you for the component. I have a somewhat related question: How can I disable the standard Windows context menu for TextInput under AIR/Windows (Cut/Copy/Paste/Select All). My email is tgs@arasoft.de