2

I have a Flex UI and want the numeric stepper to add a preceeding '0' to the displayed value if it's between 0 and 9, so that it's always 2 digits. How do I do this?

ketan
  • 19,129
  • 42
  • 60
  • 98
fred basset
  • 9,774
  • 28
  • 88
  • 138

1 Answers1

7

Use the valueFormatFunction of the NumericStepper:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx">

    <fx:Script>
        <![CDATA[
            protected function formatNumber(value:Number):String
            {
                if (value < 10)
                    return '0' + value;

                return value.toString();
            }
        ]]>
    </fx:Script>

    <s:NumericStepper valueFormatFunction="formatNumber"
                      minimum="0"
                      maximum="100" />

</s:Application>
Jason Sturges
  • 15,855
  • 14
  • 59
  • 80