views:

1231

answers:

3

I need to include an icon to the left of a label in my form. it would probably work best if the icon was part of the label. it seems to me that a form item cannot have anything preceed the label on the left side, is there anyway around this?

A: 

Should have said this is a FLEX question

+1  A: 

If you check out the source code for the formItem it has two children. one is the label and the other is the indicatorSkin. So adding an icon/image isn't going to be possible without extending the formItem class or going with something different like the Grid (which will give a similar layout), but this will obviously not include any of the features that the form has (such as required fields etc.

check out this post on extending the FormItem to include an image/icon. http://kennethsutherland.com/2009/05/27/formitem-adding-an-icon/

I've edit this post as after a bit of thought my previous answer was crap :) The blog post will let you add an image to the formItem.

kenneth
thanks so much for your help. this looks good like a good solution, my images are not loading at the moment tho, i'm not sure why.
The demo loaded the images at runtime (unless you plan on changing them during runtime I'd recommend embedding the images). Try a HTTP tool such as fiddler (which is free) and you'll see if when you request the images if they are giving 404 errors. Thats usually the reason why images aren't showing (incorrect path which gives a 404)
kenneth
A: 

Your best bet is to extend the FormItem class and add a property so you can specify the image to be displayed. Then override commitProperties(), measure() and updateDisplayList() to create the icon, set the component's preferred size and position the icon, respectively.

cliff.meyers
After looking at the code for FormItem, you may actually want to copy the source for the component and modify it to suite your needs. There's just enough that is private / internal between Form and FormItem that extending it might be a big hassle.
cliff.meyers