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 | 16 Comments
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.
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!
How about also setting the tooltip to the field label? Then the user will see the label on mouseover etc.
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.
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
Glad you found it useful!
[...] Компонент, в поле ввода которого можно увидеть его название. При наведении фокуса – название исчезает и позволяет ввести данные. [...]
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!
Adz–thanks for the bugfix! I’ve updated the source and sample with your code.
I found bug!
Thanks for posting this and the source code.really helped me.thanks.
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.
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
Hi,
I used as input text control and gave this an id named “iname”. Now I just wanted to do that when someone enter any text it should display in label . But it won’t work
hi I used this package into my website, look n feel was great but have some problem in text fetched.
Very good work! I really enjoyed this component solved my problem in a simple and elegant. Thank you very much.