Setting the gap around the required indicator in a Flex form

by Peter deHaan on November 6, 2007

in Form, FormItem, Forms

The following example shows how you can set the gap around the required indicator in a Flex form by setting the indicatorGap style, as seen in the following snippet:

<mx:Style>
    FormItem {
        indicatorGap: 24;
    }
</mx:Style>

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/11/06/setting-the-gap-around-the-required-indicator-in-a-flex-form/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        creationComplete="init();">

    <mx:Style>
        FormItem {
            backgroundColor: haloSilver;
        }
    </mx:Style>

    <mx:Script>
        <![CDATA[
            import mx.events.SliderEvent;

            private var indicatorGapStyle:CSSStyleDeclaration;

            private function init():void {
                indicatorGapStyle = StyleManager.getStyleDeclaration("FormItem");
            }

            private function slider_change(evt:SliderEvent):void {
                indicatorGapStyle.setStyle("indicatorGap", evt.value);
            }
        ]]>
    </mx:Script>

    <mx:ApplicationControlBar dock="true">
        <mx:Label text="indicatorGap:" />
        <mx:HSlider id="slider"
                minimum="14"
                maximum="100"
                value="14"
                snapInterval="1"
                liveDragging="true"
                dataTipPlacement="bottom"
                dataTipPrecision="0"
                change="slider_change(event);" />
    </mx:ApplicationControlBar>

    <mx:Form>
        <mx:FormItem label="Lorem ipsum:">
            <mx:TextInput />
        </mx:FormItem>
        <mx:FormItem label="The quick brown fox jumped:" required="true">
            <mx:TextInput />
        </mx:FormItem>
        <mx:FormItem label="over the lazy dog:" required="true">
            <mx:Text text="The quick brown fox jumped over the lazy dog." />
        </mx:FormItem>
    </mx:Form>

</mx:Application>

View source is enabled in the following example.

{ 1 comment… read it below or add one }

1 Tim December 12, 2007 at 4:49 am

This is great. It takes care of the label area, but can it allow the textbox to expand. I would love to use this where the entry space is limited, but when a person has a really long name or text they could just stretch it out.

Reply

Leave a Comment

Sorry, this blog is terrible at eating HTML comments.
If you're pasting any HTML/XML/MXML code, you need to convert your < characters to &lt; and your > characters to &gt; .

You can 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="">

Anti-Spam Protection by WP-SpamFree

Previous post:

Next post: