<?xml version="1.0"
encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" verticalAlign="top"
horizontalAlign="center"
backgroundGradientColors="[#570A0A, #731F1F]" paddingTop="0"
backgroundGradientAlphas="[1.0, 1.0]">
<mx:Script>
<![CDATA[
// Import necessary classes.
import mx.controls.Alert;
import
mx.events.ValidationResultEvent;
// Event listener for the
valid and invalid events.
private function
handleValid(eventObj:ValidationResultEvent):void {
if(eventObj.type==ValidationResultEvent.VALID)
// Enable Submit button.
submitButton.enabled = true;
else
submitButton.enabled = false;
}
// Submit form is everything
is valid.
private function submitForm():void {
Alert.show("Form Submitted!");
}
]]>
</mx:Script>
<!-- The Validator class
defines the required property and the validator events
used
by all validator subclasses. -->
<mx:Validator id="reqValid" required="true"
source="{fname}" property="text"
valid="handleValid(event)" invalid="handleValid(event)"/>
<mx:Panel title="Validator Example" layout="vertical" color="0xffffff" borderAlpha="0.15"
paddingTop="10" paddingRight="10" paddingBottom="10" paddingLeft="10" horizontalAlign="center" x="10" y="10">
<mx:Form color="0x323232">
<mx:Text width="100%"
text="Enter a value in the Name
field before you can submit. The E-mail field is optional."/>
<mx:FormItem label="Name: " required="true">
<mx:TextInput id="fname" width="100%"/>
</mx:FormItem>
<mx:FormItem label="E-mail address: " required="false">
<mx:TextInput id="email" width="100%"/>
</mx:FormItem>
<mx:FormItem>
<mx:Button id="submitButton" enabled="false"
label="Submit"
click="submitForm();"/>
</mx:FormItem>
</mx:Form>
</mx:Panel>
</mx:Application>
No comments:
Post a Comment