incubator-flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmcl...@apache.org
Subject svn commit: r1300731 - in /incubator/flex/whiteboard/jmclean/validators/src: PostCodeValidationExample.mxml tests/PostCodeFormatterTests.as tests/PostCodeValidatorTests.as
Date Wed, 14 Mar 2012 21:36:16 GMT
Author: jmclean
Date: Wed Mar 14 21:36:16 2012
New Revision: 1300731

URL: http://svn.apache.org/viewvc?rev=1300731&view=rev
Log:
change to use apache namesapce. Added tests and modified example for Portuguese locale.

Modified:
    incubator/flex/whiteboard/jmclean/validators/src/PostCodeValidationExample.mxml
    incubator/flex/whiteboard/jmclean/validators/src/tests/PostCodeFormatterTests.as
    incubator/flex/whiteboard/jmclean/validators/src/tests/PostCodeValidatorTests.as

Modified: incubator/flex/whiteboard/jmclean/validators/src/PostCodeValidationExample.mxml
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/jmclean/validators/src/PostCodeValidationExample.mxml?rev=1300731&r1=1300730&r2=1300731&view=diff
==============================================================================
--- incubator/flex/whiteboard/jmclean/validators/src/PostCodeValidationExample.mxml (original)
+++ incubator/flex/whiteboard/jmclean/validators/src/PostCodeValidationExample.mxml Wed Mar
14 21:36:16 2012
@@ -1,73 +1,94 @@
 <?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"
-			   xmlns:validators="mx.validators.*" xmlns:formatters="mx.formatters.*"
-			   width="100%">
-	<s:layout>
-		<s:VerticalLayout gap="10" paddingLeft="20" paddingTop="20" />
-	</s:layout>
-	
-	<fx:Declarations>
-		<validators:PostCodeValidator id="pcv" formats="{postCodeFormats}" source="{postcode}"
property="text" />
-		<formatters:PostCodeFormatter id="pcf" formats="{postCodeFormats}" />
-	</fx:Declarations>
-	
-	<fx:Script>
-		<![CDATA[
-			import mx.collections.ArrayList;
-			import mx.events.ValidationResultEvent;
-			import mx.validators.ValidationResult;
-			
-			[Bindable] protected var postCodeFormats:Array = ["AA-NNNN"];		
-			[Bindable] protected var countries:ArrayList = new ArrayList([
-				{country:"Australia", locale:"en_AU"},
-				{country:"Canada", locale:"en_CA"},
-				{country:"United Kingdom", locale:"en_GB"},
-				{country:"United States", locale:"en_US"}
-				]);
-			
-			protected function validate(event:Event):void {
-				var result:ValidationResultEvent = pcv.validate();
-				
-				errors.dataProvider = new ArrayList(result.results);
-				
-				formatted.text = pcf.format(postcode.text);
-			}
-			
-			protected function displayError(data:Object):String {
-				var error:ValidationResult = data as ValidationResult;
-				
-				if (error) {
-					return error.errorCode + ": " + error.errorMessage;
-				}
-				
-				return "";
-			}
-			
-			protected function changeCountry(event:Event):void {
-				postCodeFormats = pcv.suggestFormat(country.selectedItem.locale);
-				validate(event);
-			}
-		]]>
-	</fx:Script>
-
-	<s:Form>
-		<s:FormItem label="Select Country">
-			<s:List id="country" dataProvider="{countries}" labelField="country" change="changeCountry(event)"
/>	
-		</s:FormItem>
-		<s:FormItem label="Enter Format">
-			<s:TextInput id="format" text="{postCodeFormats.toString()}" restrict="AN -" change="postCodeFormats
= [format.text.split()]"  />
-		</s:FormItem>
-		<s:FormItem label="Enter Postcode">
-			<s:TextInput id="postcode" change="validate(event)"  />
-		</s:FormItem>
-		<s:FormItem label="Formatted Postcode">
-			<s:Label id="formatted" />
-		</s:FormItem>
-		<s:FormItem label="Errors">
-			<s:List id="errors" labelFunction="displayError" />	
-		</s:FormItem>
-	</s:Form>
+<s:Application 
+    width="100%"
+    xmlns:fx="http://ns.adobe.com/mxml/2009"
+    xmlns:s="library://ns.adobe.com/flex/spark"
+    xmlns:mx="library://ns.adobe.com/flex/mx"
+	xmlns:a="http://www.apache.org/flex">
+    <s:layout>
+        <s:VerticalLayout 
+            paddingLeft="20"
+            paddingTop="20"
+            gap="10"/>
+    </s:layout>
+
+    <fx:Declarations>
+        <a:PostCodeValidator id="pcv"
+            source="{postcode}"
+            formats="{postCodeFormats}"
+            property="text"/>
+        <a:PostCodeFormatter id="pcf"
+            formats="{postCodeFormats}"/>
+    </fx:Declarations>
+
+    <fx:Script>
+        <![CDATA[
+            import mx.collections.ArrayList;
+            import mx.events.ValidationResultEvent;
+            import mx.validators.ValidationResult;
+
+            [Bindable]
+            protected var postCodeFormats:Array = [ "AA-NNNN" ];
+
+            [Bindable]
+            protected var countries:ArrayList =
+                new ArrayList([{ country: "Australia", locale: "en_AU" },
+                                 { country: "Canada", locale: "en_CA" },
+                                 { country: "United Kingdom", locale: "en_GB" },
+                                 { country: "United States", locale: "en_US" },
+								 { country:"Portugal", locale:"pt_PT" }]);
+
+            protected function validate(event:Event):void
+            {
+                var result:ValidationResultEvent = pcv.validate();
+
+                errors.dataProvider = new ArrayList(result.results);
+
+                formatted.text = pcf.format(postcode.text);
+            }
+
+            protected function displayError(data:Object):String
+            {
+                var error:ValidationResult = data as ValidationResult;
+
+                if (error)
+                    return error.errorCode + ": " + error.errorMessage;
+
+                return "";
+            }
+
+            protected function changeCountry(event:Event):void
+            {
+                postCodeFormats = pcv.suggestFormat(country.selectedItem.locale);
+                validate(event);
+            }
+        ]]>
+    </fx:Script>
+
+    <s:Form>
+        <s:FormItem label="Select Country">
+            <s:List id="country"
+                dataProvider="{countries}"
+                labelField="country"
+                change="changeCountry(event)"/>
+        </s:FormItem>
+        <s:FormItem label="Enter Format">
+            <s:TextInput id="format"
+                text="{postCodeFormats.toString()}"
+                change="postCodeFormats = [format.text.split()]"
+                restrict="AN -"/>
+        </s:FormItem>
+        <s:FormItem label="Enter Postcode">
+            <s:TextInput id="postcode"
+                change="validate(event)"/>
+        </s:FormItem>
+        <s:FormItem label="Formatted Postcode">
+            <s:Label id="formatted"/>
+        </s:FormItem>
+        <s:FormItem label="Errors">
+            <s:List id="errors"
+                labelFunction="displayError"/>
+        </s:FormItem>
+    </s:Form>
 
 </s:Application>

Modified: incubator/flex/whiteboard/jmclean/validators/src/tests/PostCodeFormatterTests.as
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/jmclean/validators/src/tests/PostCodeFormatterTests.as?rev=1300731&r1=1300730&r2=1300731&view=diff
==============================================================================
--- incubator/flex/whiteboard/jmclean/validators/src/tests/PostCodeFormatterTests.as (original)
+++ incubator/flex/whiteboard/jmclean/validators/src/tests/PostCodeFormatterTests.as Wed Mar
14 21:36:16 2012
@@ -1,7 +1,7 @@
 package tests
 {
-	import mx.formatters.PostCodeFormatter;
-	import mx.validators.PostCodeValidator;
+	import org.apache.flex.formatters.PostCodeFormatter;
+	import org.apache.flex.validators.PostCodeValidator;
 	
 	import org.flexunit.asserts.assertTrue;
 

Modified: incubator/flex/whiteboard/jmclean/validators/src/tests/PostCodeValidatorTests.as
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/jmclean/validators/src/tests/PostCodeValidatorTests.as?rev=1300731&r1=1300730&r2=1300731&view=diff
==============================================================================
--- incubator/flex/whiteboard/jmclean/validators/src/tests/PostCodeValidatorTests.as (original)
+++ incubator/flex/whiteboard/jmclean/validators/src/tests/PostCodeValidatorTests.as Wed Mar
14 21:36:16 2012
@@ -2,9 +2,11 @@ package tests
 {
 	import mx.resources.IResourceManager;
 	import mx.resources.ResourceManager;
-	import mx.validators.PostCodeValidator;
 	import mx.validators.ValidationResult;
 	
+	import org.apache.flex.validators.PostCodeValidator;
+	
+	import org.flexunit.asserts.assertEquals;
 	import org.flexunit.asserts.assertTrue;
 
 	public class PostCodeValidatorTests
@@ -482,6 +484,19 @@ package tests
 		}
 		
 		[Test]
+		public function portuguesePostCodes():void {
+			var results:Array;
+			var valid:Array = ["4770-459", "4770 459", "4770"];
+			
+			validator.suggestFormat("pt_PT");
+			
+			for each (var postcode:String in valid) {
+				results = PostCodeValidator.validatePostCode(validator, postcode, null);
+				assertTrue("Valid Postcode", results.length == 0);
+			}
+		}
+		
+		[Test]
 		public function multipleFormats():void {
 			var validator1:PostCodeValidator = new PostCodeValidator();
 			var validator2:PostCodeValidator = new PostCodeValidator();
@@ -632,6 +647,11 @@ package tests
 			validator.suggestFormat("en-CA");
 			assertTrue("Australian format", validator.format == "ANA NAN");
 			
+			validator.suggestFormat("pt_PT");
+			assertEquals("PT format", "NNNN-NNN", validator.formats[0]);
+			assertEquals("PT format", "NNNN NNN", validator.formats[1]);
+			assertEquals("PT format", "NNNN", validator.formats[2]);
+			
 			validator.suggestFormat("en_US");
 			assertTrue("US format", validator.formats[0] == "NNNNN");
 			assertTrue("US format", validator.formats[1] == "NNNNN-NNNN");



Mime
View raw message