2 Replies Latest reply on Jan 18, 2011 8:35 AM by JabbyPandaUA

    DateValidator, Configuration error: Incorrect formatting string

    Bertrand75123

      Hi guys,

       

      I am struggling with a DateValidator issue, I hope someone can help me

       

      Here is the parts of code needed to check what's wrong:

       

      public const DATE_FORMAT:String = "DD/MMMM/YYYY";
      
      <mx:DateFormatter id="dateFormatter" formatString="{DATE_FORMAT}" />
      
      <mx:DateValidator
       id="firstDateValidator" inputFormat="{DATE_FORMAT}" required="true" 
      source="{firstDate}" property="text" />
      
      <mx:DateFiel id="firstDate" labelFunction="doLabel" />
      
      private function doLabel(item:Date):String
      {
           return dateFormatter.format(item);
      }
      
      

      I need to format and validate the following example: 13/January/2011

       

      When I use DATE_FORMAT = "DD/MM/YYYY", I have no problem to format and validate the Datefield, I have 13/01/2011.

       

      But when I use DATE_FORMAT = "DD/MMMM/YYYY", I have the following error message with the validator (the formatter is working well):

      Configuration error: Incorrect formatting string.

       

      Thank you very much for your help.

        • 1. Re: DateValidator, Configuration error: Incorrect formatting string
          Gregory Lafrance Level 6

          The DateValidator class validates that a String, Date, or Object contains a proper date and matches a specified format. Users can enter a single digit or two digits for month, day, and year. So you can't have MMMM, as the DateValidator validates dates that have DD MM YYYY.

           

          If this post answers your question or helps, please mark it as such. Thanks!

          http://www.stardustsystems.com
          Adobe Flex Development and Support Services

          1 person found this helpful
          • 2. Re: DateValidator, Configuration error: Incorrect formatting string
            JabbyPandaUA Level 3

            Standard Flex validator out of the box is very fragile when it comes to validate "non-standard" date formats. You should extend this DateValidator with your own version like I do, that re-implements "format" function call and rewrites private function "validateFormatString" from the the scratch.

             

            Here is the my implementation of this function:

             

             

            private static function validateFormatString(validator : DateRangeValidator,
                                                                 separatorSign : String,
                                                                 formatPartsArray : Array,
                                                                 baseField : String) : ValidationResult {
                        
                        var formatPartsValidationObject : Object = {dayValid : false,
                            monthValid : false,
                            yearValid : false};
                        var formatsLength : int = formatPartsArray.length; 
                        
                        var mask:String;            
                        for (var i : int  = 0; i < formatsLength; i++) {
                            mask = formatPartsArray[i];                
                            switch (mask) {
                                case "M" :
                                case "MM" :
                                case "MMM" :                        
                                case "MMMM" :
                                    formatPartsValidationObject.monthValid = true;
                                    break;
                                case "YY" :
                                case "YYYY" :
                                    formatPartsValidationObject.yearValid = true;
                                    break;                    
                                case "D" :
                                case "DD" :                    
                                    formatPartsValidationObject.dayValid = true;                        
                                    break;                        
                            }    
                        }           
                        if (formatPartsValidationObject.monthValid && 
                            formatPartsValidationObject.dayValid &&
                            formatPartsValidationObject.yearValid) {
                            return null; // Passes format validation
                        } else {
                            return new ValidationResult(
                                true, baseField, "format",
                                validator.formatError);
                        }
                    }
            

             

             

            formatPartsArray is calculated as follows:  

             

            var formatPartsArray : Array = inputFormat.split("/");