Flex in Validateall () method to achieve multiple item validation and the results of uniform hints _flex

Source: Internet
Author: User
Copy Code code as follows:

<?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" minwidth= "955" minheight= "600"
Creationcomplete= "Inithandler (event)" >
<fx:Script>
<! [cdata[
Import Mx.controls.Alert;
Import mx.events.FlexEvent;
Import mx.events.ValidationResultEvent;
Import Mx.validators.Validator;

private Var error1:string;

private Var error2:string;

private Var error3:string;

protected function Inithandler (event:flexevent): void
{

}


protected function Btn_clickhandler (event:mouseevent): void
{
TODO auto-generated Method Stub
var Validatearray:array=validator.validateall (
[Namevalidator,agevalidator,phonevalidator]);
if (validatearray.length==0)
{
Alert.show ("Success!") ");
}else
{
Alert.show (error1+ "\ n" +error2+ "\ n" +error3);
}
}

protected function Namevalidator_invalidhandler (event:validationresultevent): void
{
Error1 =event.message;
}

protected function Agevalidator_invalidhandler (event:validationresultevent): void
{
Error2 =event.message;
}

protected function Phonevalidator_invalidhandler (event:validationresultevent): void
{
Error3 =event.message;
}

]]>
</fx:Script>
<fx:Declarations>
<mx:stringvalidator id= "Namevalidator"
Source= "{username}"
property= "Text"
Minlength= "6" maxlength= "16"
Toolongerror= "cannot be more than 16 characters" tooshorterror= "cannot be less than six bits"
Required= "true"
Invalid= "Namevalidator_invalidhandler (event)"
/>
<mx:numbervalidator id= "Agevalidator" source= "{Age}"
domain= "int" allownegative= "false" maxvalue= "a" minvalue= "18"
Required= "true" property= "text"
Exceedsmaxerror= "can not be greater than" lowerthanminerror= "can not be less than 18"
Invalid= "Agevalidator_invalidhandler (event)"
/>
<mx:phonenumbervalidator id= "Phonevalidator"
mindigits= "One" property= "text"
Source= "{Phone}"
Required= "true"
Invalid= "Phonevalidator_invalidhandler (event)"/>
</fx:Declarations>
<mx:Panel>
<mx:Form>
<mx:formitem label= "Name" >
<mx:textinput id= "username"/>
</mx:FormItem>
<mx:formitem label= "Age" >
<mx:textinput id= "Age"/>
</mx:FormItem>
<mx:formitem label= "Phone" >
<mx:textinput id= "Phone"/>
</mx:FormItem>
<mx:FormItem>
<mx:button label= "Verify" id= "BTN" click= "Btn_clickhandler" (event)/>
</mx:FormItem>
</mx:Form>
</mx:Panel>
</s:Application>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.