incubator-flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmcl...@apache.org
Subject svn commit: r1302313 - /incubator/flex/branches/patches/projects/apache/src/org/apache/flex/validators/PostCodeValidator.as
Date Mon, 19 Mar 2012 07:50:20 GMT
Author: jmclean
Date: Mon Mar 19 07:50:20 2012
New Revision: 1302313

URL: http://svn.apache.org/viewvc?rev=1302313&view=rev
Log:
Added errorsToLocale method that enables you to display errors for a validator in a locale
other than your own (assuming the correct resource bundles have been loaded).

Modified:
    incubator/flex/branches/patches/projects/apache/src/org/apache/flex/validators/PostCodeValidator.as

Modified: incubator/flex/branches/patches/projects/apache/src/org/apache/flex/validators/PostCodeValidator.as
URL: http://svn.apache.org/viewvc/incubator/flex/branches/patches/projects/apache/src/org/apache/flex/validators/PostCodeValidator.as?rev=1302313&r1=1302312&r2=1302313&view=diff
==============================================================================
--- incubator/flex/branches/patches/projects/apache/src/org/apache/flex/validators/PostCodeValidator.as
(original)
+++ incubator/flex/branches/patches/projects/apache/src/org/apache/flex/validators/PostCodeValidator.as
Mon Mar 19 07:50:20 2012
@@ -89,6 +89,12 @@ public class PostCodeValidator extends V
 {
     include "../../../../core/Version.as";
 
+	/**
+	 * Name of the bundle file error resource strings can be found.
+	 * Also defined in matadata tag [ResourceBundle("validators")]
+	 */
+	private static const BUNDLENAME:String = "validators";
+	
     /**
      * Value <code>errorCode</code> of a ValidationResult is set to when
      * the postcode contains an invalid charater.
@@ -622,7 +628,7 @@ public class PostCodeValidator extends V
         invalidCharErrorOverride = value;
 
         if (!value)
-            _invalidCharError = resourceManager.getString("validators", "invalidCharPostcodeError");
+            _invalidCharError = resourceManager.getString(BUNDLENAME, "invalidCharPostcodeError");
     }
 
 
@@ -668,7 +674,7 @@ public class PostCodeValidator extends V
         wrongLengthErrorOverride = value;
 
         if (!value)
-            _wrongLengthError = resourceManager.getString("validators", "wrongLengthPostcodeError");
+            _wrongLengthError = resourceManager.getString(BUNDLENAME, "wrongLengthPostcodeError");
     }
 
     //----------------------------------
@@ -713,7 +719,7 @@ public class PostCodeValidator extends V
         wrongFormatErrorOverride = value;
 
         if (!value)
-            _wrongFormatError = resourceManager.getString("validators", "wrongFormatPostcodeError");
+            _wrongFormatError = resourceManager.getString(BUNDLENAME, "wrongFormatPostcodeError");
     }
 
     //----------------------------------
@@ -759,7 +765,7 @@ public class PostCodeValidator extends V
 
         if (!value)
             _incorrectFormatError =
-                resourceManager.getString("validators", "incorrectFormatPostcodeError");
+                resourceManager.getString(BUNDLENAME, "incorrectFormatPostcodeError");
     }
 
     //--------------------------------------------------------------------------
@@ -844,6 +850,37 @@ public class PostCodeValidator extends V
 
         return localeID.getRegion();
     }
+	
+	/**
+	 *  Sets the error strings to be from a another locale.
+	 * 
+	 *  <p>When validating other countries postcode you may want to set the
+	 *  validation message to be from that country but not change the
+	 *  applications locale.</p>
+	 * 
+	 * <p>To work the locale must be in the locale chain.</p>
+	 *
+	 *  @param locale locale to obtain region from.
+	 * 
+	 *  @return True if error message have been changed otherwise false.
+	 *
+	 */
+	public function errorsToLocale(locale:String):Boolean
+	{
+		if (resourceManager.getResourceBundle(locale, BUNDLENAME) == null)
+			return false;
+		
+		invalidCharErrorOverride =
+			resourceManager.getString(BUNDLENAME, "invalidCharPostcodeError", null, locale);
+		wrongLengthErrorOverride =
+			resourceManager.getString(BUNDLENAME, "wrongLengthPostcodeError", null, locale);
+		wrongFormatErrorOverride =
+			resourceManager.getString(BUNDLENAME, "wrongFormatPostcodeError", null, locale);
+		incorrectFormatErrorOverride =
+			resourceManager.getString(BUNDLENAME, "incorrectFormatPostcodeError", null, locale);
+		
+		return true;
+	}
 
     /**
      *  Sets the suggested postcode formats for a given <code>locale</code>.
@@ -853,6 +890,7 @@ public class PostCodeValidator extends V
      *  <p>Currenly only a limited set of locales are supported.</p>
      *
      *  @param locale Locale to obtain formats for.
+	 *  @param changeError If true change error message to match local.
      *
      *  @return The suggested format (an array of strings) or an empty
      *  array if the locale is not supported.
@@ -861,7 +899,7 @@ public class PostCodeValidator extends V
      *  @playerversion Flash 10.2
      *  @productversion ApacheFlex 4.8
      */
-    public function suggestFormat(locale:String = null):Array
+    public function suggestFormat(locale:String = null, changeErrors:Boolean = false):Array
     {
         var region:String = getRegion(locale);
 
@@ -917,6 +955,9 @@ public class PostCodeValidator extends V
                 formats = [];
                 break;
         }
+		
+		if (changeErrors)
+			errorsToLocale(locale);
 
         return formats;
     }



Mime
View raw message