blob: 00ef0027673b2dd8ef193302bcda18a1b383224a [file] [log] [blame]
<?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:Module 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="100%" height="100%">
<s:layout>
<s:VerticalLayout paddingLeft="10" paddingRight="10" paddingTop="10" paddingBottom="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:Module>