The following example shows how you can hide the text input field on the MX DateField control in Flex 3 by setting the Boolean visible and includeInLayout properties on the internal text field (using the getTextField() method in the mx_internal namespace).

Since this example uses the mx_internal namespace, you can't always depend on this behavior to work in future versions of the Flex SDK. Use at your own risk.

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2010/03/28/hiding-the-text-field-on-an-mx-datefield-control-in-flex-3/ -->
<mx:Application name="MX_DateField_getTextInput_test"
                xmlns:mx="http://www.adobe.com/2006/mxml"
                layout="vertical"
                verticalAlign="top"
                backgroundColor="white">
 
    <mx:Script>
        <![CDATA[
            import mx.controls.TextInput;
 
            protected function init():void {
                var tf:TextInput = df.mx_internal::getTextInput();
                tf.visible = false;
                tf.includeInLayout = false;
            }
        ]]>
    </mx:Script>
 
    <mx:DateField id="df" initialize="init();" width="23" />
    <mx:Label text="{df.selectedDate}" />
 
</mx:Application>
 
Tagged with:
 
About The Author

Peter deHaan

Peter deHaan currently works for Adobe on the Flex SDK QA team. While not working on Flex, Flash, and ColdFusion applications, Peter enjoys making up bios and writing in 3rd person. Peter's rarely updated blog can be found at blogs.adobe.com/pdehaan/, actionscriptexamples.com, airexamples.com, and coldfusionexamples.com.

4 Responses to Hiding the text field on an MX DateField control in Flex 3

  1. Anonymous says:

    I really love all your examples, keep up the good work , u legend!

  2. ecar26 says:

    It was exactly that i was looking for.

    Many thanks!

    Erika

  3. Tahir Alvi says:

    Hi Peter,

    How i make date field of Flex with water mark?
    or refer me any url that implement this.

    Thanks.

Leave a Reply

Your email address will not be published.

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

Anti-Spam Protection by WP-SpamFree