You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by jm...@apache.org on 2014/08/23 06:43:11 UTC
[2/2] git commit: [flex-utilities] [refs/heads/develop] - new post
code examples
new post code examples
Project: http://git-wip-us.apache.org/repos/asf/flex-utilities/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-utilities/commit/7ada6605
Tree: http://git-wip-us.apache.org/repos/asf/flex-utilities/tree/7ada6605
Diff: http://git-wip-us.apache.org/repos/asf/flex-utilities/diff/7ada6605
Branch: refs/heads/develop
Commit: 7ada6605b49e81bc62d3cb83dfc52e350011be1a
Parents: 06cf12e
Author: Justin Mclean <jm...@apache.org>
Authored: Sat Aug 23 14:42:54 2014 +1000
Committer: Justin Mclean <jm...@apache.org>
Committed: Sat Aug 23 14:42:54 2014 +1000
----------------------------------------------------------------------
.../formatters/PostCodeFormatterExample.mxml | 88 ++++++++++++++++++++
.../validators/PostCodeValidatorExample.mxml | 85 +++++++++++++++++++
2 files changed, 173 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/7ada6605/TourDeFlex/TourDeFlex3/src/apache/formatters/PostCodeFormatterExample.mxml
----------------------------------------------------------------------
diff --git a/TourDeFlex/TourDeFlex3/src/apache/formatters/PostCodeFormatterExample.mxml b/TourDeFlex/TourDeFlex3/src/apache/formatters/PostCodeFormatterExample.mxml
new file mode 100644
index 0000000..e6132e0
--- /dev/null
+++ b/TourDeFlex/TourDeFlex3/src/apache/formatters/PostCodeFormatterExample.mxml
@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+<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">
+ <s:layout>
+ <s:HorizontalLayout verticalAlign="middle" horizontalAlign="center" />
+ </s:layout>
+
+ <fx:Script>
+ <![CDATA[
+ import org.apache.flex.formatters.PostCodeFormatter;
+
+ private var formatter:PostCodeFormatter;
+
+ protected function formatPostCode(event:MouseEvent):void
+ {
+ formatter = new PostCodeFormatter();
+
+ if (aust.selected) {
+ formatted.text = checkAustralianPostCode(postcode.text);
+ }
+ else if (uk.selected) {
+ formatted.text = checkUKPostCode(postcode.text);
+ }
+ else if (can.selected) {
+ formatted.text = checkCanadianPostCode(postcode.text);
+ }
+ }
+
+ public function checkAustralianPostCode(postcode:String):String {
+ formatter.formats = ["NNNN"];
+
+ return formatter.format(postcode);
+ }
+
+ public function checkUKPostCode(postcode:String):String {
+ formatter.formats = ["AN NAA", "ANN NAA", "AAN NAA", "ANA NAA", "AANN NAA", "AANA NAA"];
+
+ return formatter.format(postcode);
+ }
+
+ public function checkCanadianPostCode(postcode:String):String {
+ formatter.formatString = "ANA NAN";
+
+ return formatter.format(postcode);
+ }
+ ]]>
+ </fx:Script>
+
+ <s:Panel title="Postcode Formatter Example" width="600" height="100%" color="0x000000" borderAlpha="0.15">
+ <s:layout>
+ <s:VerticalLayout paddingLeft="20" paddingTop="20" gap="10" />
+ </s:layout>
+ <s:HGroup verticalAlign="middle">
+ <s:Label text="Postcode" />
+ <s:TextInput id="postcode" text=""/>
+ </s:HGroup>
+ <s:HGroup verticalAlign="middle">
+ <s:Label text="Country" />
+ <s:RadioButton id="aust" label="Australia" selected="true" />
+ <s:RadioButton id="uk" label="UK" />
+ <s:RadioButton id="can" label="Canada" />
+ </s:HGroup>
+ <s:Button label="Show Formatted Postcode" click="formatPostCode(event)" />
+ <s:HGroup>
+ <s:Label text="Formatted Postcode" />
+ <s:Label id="formatted" />
+ </s:HGroup>
+ </s:Panel>
+</s:Application>
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/7ada6605/TourDeFlex/TourDeFlex3/src/apache/validators/PostCodeValidatorExample.mxml
----------------------------------------------------------------------
diff --git a/TourDeFlex/TourDeFlex3/src/apache/validators/PostCodeValidatorExample.mxml b/TourDeFlex/TourDeFlex3/src/apache/validators/PostCodeValidatorExample.mxml
new file mode 100644
index 0000000..eb10f2c
--- /dev/null
+++ b/TourDeFlex/TourDeFlex3/src/apache/validators/PostCodeValidatorExample.mxml
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+<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:a="http://flex.apache.org/ns">
+ <s:layout>
+ <s:HorizontalLayout verticalAlign="middle" horizontalAlign="center" />
+ </s:layout>
+
+ <fx:Script>
+ <![CDATA[
+ import org.apache.flex.validators.PostCodeValidator;
+
+ import spark.components.Alert;
+
+ protected function validatePostCode(event:MouseEvent):void
+ {
+ if (aust.selected) {
+ checkAustralianPostCode(postcode.text);
+ }
+ else if (uk.selected) {
+ checkUKPostCode(postcode.text);
+ }
+ else if (can.selected) {
+ checkCanadianPostCode(postcode.text);
+ }
+ }
+
+ public function checkAustralianPostCode(postcode:String):void {
+ validator.formats = ["NNNN"];
+ }
+
+ public function checkUKPostCode(postcode:String):void {
+ validator.formats = ["AN NAA", "ANN NAA", "AAN NAA", "ANA NAA", "AANN NAA", "AANA NAA"];
+ }
+
+ public function checkCanadianPostCode(postcode:String):void {
+ validator.format = "ANA NAN";
+ }
+ ]]>
+ </fx:Script>
+
+
+ <fx:Declarations>
+ <a:PostCodeValidator id="validator" source="{postcode}" property="text"
+ trigger="{checkPostcode}" triggerEvent="click"
+ invalid="Alert.show('Postcode incorrect format!', 'Postcode');"/>
+ </fx:Declarations>
+
+
+ <s:Panel title="Postcode Validator Example" width="600" height="100%" color="0x000000" borderAlpha="0.15">
+ <s:layout>
+ <s:VerticalLayout paddingLeft="20" paddingTop="20" gap="10" />
+ </s:layout>
+ <s:HGroup verticalAlign="middle">
+ <s:Label text="Postcode" />
+ <s:TextInput id="postcode" text=""/>
+ </s:HGroup>
+ <s:HGroup verticalAlign="middle">
+ <s:Label text="Country" />
+ <s:RadioButton id="aust" label="Australia" selected="true" />
+ <s:RadioButton id="uk" label="UK" />
+ <s:RadioButton id="can" label="Canada" />
+ </s:HGroup>
+ <s:Button id="checkPostcode" label="Validate Postcode" click="validatePostCode(event)" />
+ </s:Panel>
+</s:Application>