2 Replies Latest reply on Nov 11, 2011 1:25 AM by PaddyMc2010

    s:TextInput for time




      Would anyone be able to advise of an approch for entering time into a textInput box.  I only want to give the user ability to enter 4 chars.  2 for hours and 2 for mins.  Seperated by a constant : value. i.e 12 : 31.  How can i have a default character for seperating my hours and mins.



        • 1. Re: s:TextInput for time
          Vibhuti Gosavi(InfoCepts) Level 3



          Please go through this:



          Create a Custom Formatter





          You want to create a custom formatter that will accept any appropriate string and return it with the correct formatting.




          Extend the Formatter class and override the format() method.




          In the format() method of the Formatter, you’ll create a SwitchSymbolFormatter instance and pass to its formatValue() method a string of hash marks representing the characters you want replaced with your original string. For example, if provided the format ###-### and the source 123456, the formatValue() method will return 123-456. You’ll then return this value from the format() method of your custom formatter.

          The Formatter class uses a string of hash marks that will be replaced by all the characters in the string passed to the format() method. Replacing those characters is simply a matter of looping through the string and, character by character, building out the properly formatted string and then replacing the original:

          package oreilly.cookbook { import mx.formatters.Formatter; import mx.formatters.SwitchSymbolFormatter;  public class ISBNFormatter extends Formatter {  public var formatString : String = "####-##-####";  public function ISBNFormatter() { super(); }  override public function format(value:Object):String { // we need to check the length of the string // ISBN can be 10 or 13 characters if( ! (value.toString().length == 10 || value.toString().length == 13) ) { error="Invalid String Length"; return "" }  // count the number of hash marks passed into our format string var numCharCnt:int = 0; for( var i:int = 0; i<formatString.length; i++ ) { if( formatString.charAt(i) == "#" ) { numCharCnt++; } }  // if we don't have the right number of items in our format string // time to return an error if( ! (numCharCnt == 10 || numCharCnt == 13)  ) { error="Invalid Format String"; return "" }  // if the formatString and value are valid, format the number var dataFormatter:SwitchSymbolFormatter = new SwitchSymbolFormatter(); return dataFormatter.formatValue( formatString, value ); }  } }



          I am giving you the link also:

          http://oreilly.com/flex/excerpts/flex-4-cookbook/validation-formatting-regular-expressions .html




          Thanks and Regards,

          ------------------------------------------------------------------------------------------ --

          Vibhuti Gosavi | vgosavi@infocepts.com | www.infocepts.com

          ------------------------------------------------------------------------------------------ --