Small tool tips for Adobe Flex validation errors

If you are using Adobe Flex forms, chances are you have come across validators. I do not like the way validators work out of the box, and it is a real pain to work against them. I will post a better way to validate your forms later. For now, I want to show you how to save real estate in your Flex forms when using validators.

The error tool tips associated with validators are big. I will show you how to make them smaller.

Add this CSS to your Flex project (mx:style tag or external css file):

.errorTip { 
			borderColor: #0000FF;
			paddingTop: 0;
			paddingBottom: 0;
			paddingLeft: 4;
			paddingRight: 4;
			fontWeight: bold;
			fontSize: 9px;
			backgroundColor: #0000ff;
			cornerRadius: 8;
		}
ToolTip{
     borderSkin: ClassReference("com.your_project_name.skins.SmallToolTip");
}

Then put a file called SmallToolTip.as in your com.__________.skins (fill in the blank) directory with these contents:

package com.your_project_name.skins
{
	import mx.skins.halo.HaloBorder;
	import mx.core.mx_internal;
	import flash.display.Graphics;
 
	use namespace mx_internal;
 
	public class SmallToolTip extends HaloBorder
	{
		public function SmallToolTip()
		{
			super();
		}
 
		override mx_internal function drawBorder(w:Number, h:Number):void{
			super.drawBorder(w,h);
			// Draw a small tail at the bottom left side of the tooltip
			var gr:Graphics = graphics;
			gr.beginFill(getStyle('borderColor'), 1);
			gr.moveTo(x + 7, y + h);
			gr.lineTo(x + 10, y + h + 4);
			gr.lineTo(x + 13, y + h)
			gr.moveTo(x + 7, y + h);
			gr.endFill();
		}	
	}
}

This only works for drawing a tool tip with the tail at the bottom left. But you can draw a tail wherever you want by altering the Graphics code which is super easy. Removing the padding and drawing a smaller tail are the two big ways to make the tool tip take up less real estate, with the least amount of work.

Before:

bigtt_1f

After:

smalltt_2f

smalltt_1f

No TweetBacks yet. (Be the first to Tweet this post)
Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • MySpace
  • Slashdot
  • StumbleUpon
  • Technorati
  • TwitThis

If you enjoyed this post, make sure you subscribe to my RSS feed!

This entry was posted in Software and tagged , , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

5 Comments

  1. Posted August 13, 2009 at 12:43 pm | Permalink

    I don’t like the way Flex handles validation either and this is way better. Thanks for this!

  2. Posted August 13, 2009 at 12:51 pm | Permalink

    Thanks Zachary. One day I will get around to posting a better complete validation solution if Flex does not come up with one. Their validation is truly limited. Also nice blog, I am subscribed. Small recommendation – move the subscribe links to the top to get more subscribers!

  3. Posted September 14, 2009 at 10:19 am | Permalink

    Tony – this is great stuff. My question to you: did you have a custom class you were using in the “before” picture? I don’t know how to make the tooltips align to the top of the text field rather than the right, which is something mandatory for a project I’m on.

  4. Posted September 14, 2009 at 10:37 am | Permalink

    It’s been a while since I have messed with this code, but maybe you need something like this:

    private function createAndShowToolTip(target:Object, message:String):void{
    var errorTip:ToolTip;
    // Otherwise create it
    var pt:Point = target.contentToGlobal( new Point(0,0) );
    errorTip = ToolTipManager.createToolTip(message, pt.x + 5, pt.y - target.height + 12, "errorTipAbove") as ToolTip;
    errorTip.setStyle("styleName", "errorTip");

    // Save a reference to the error message ToolTip in a hash for later use.
    errorMessageToolTips[target.name] = errorTip;
    }

  5. Posted September 14, 2009 at 12:23 pm | Permalink

    Thanks – it’s too bad this isn’t something that can be accomplished with MXML or CSS. But at least it’s not complicated. :)

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">