All,

I am unable to call event handler(validateMe) when focus out of my
control.In this case i cant use focusOut.But I need validation when
leave control.

My flex code

<?xml version="1.0" encoding="utf-8"?>
<!-- Simple example to demonstrate StringValidator. -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";>

    <mx:Script>
        <![CDATA[
                import mx.core.UIComponent;
                import mx.collections.ArrayCollection;
                import mx.controls.Label;
                import mx.events.ValidationResultEvent;

                import mx.controls.Alert;
                private var vResult:ValidationResultEvent;

                private var errorMessages:ArrayCollection=new ArrayCollection();
                private function submitForm():void
                {
                    if(isFormValid())
                    {
                        //TODO Save Form
                        Alert.show("Form is valid");

                    }
                    else
                    {
                        //TODO Show Error message in better way
                        showError();
                    }
                }
                private function isFormValid():Boolean
                {
                        errorMessages.removeAll();
                        var source:Object=new Object();
                        source.name='First Name';
                        source.listener=fname;
                        validateText(source);

                        source.name='Last Name';
                        source.listener=lname;
                        validateText(source);
                        if(errorMessages.length==0)
                        {
                                return true;
                        }
                        return false;
                }
                private function validateMe(name:String,ui:TextInput):void
                {

                        var source:Object=new Object();
                        errorMessages.removeAll();
                        source.name=name;
                        source.listener=ui;
                        validateText(source);
                        showError();
                }
                 private function showError():void
                {
                        var strMessage:String=null;
                        for each(var errorObject:Object in errorMessages)
                        {
                                if(strMessage==null)
                                strMessage=errorObject.message
                                else
                                strMessage+="\n"+errorObject.message;
                                errorObject.source.errorString='';
                        }
                        if(errorMessages.length>0)
                        Alert.show(strMessage);
                }


                private function validateText(source:Object):Boolean
                {
                         validator.listener=source.listener;
                         if(validator.required);
                         {
                          validator.requiredFieldError=source.name+' is
required.'
                         }
                     vResult=validator.validate(source.listener.text);
                         if (vResult.type==ValidationResultEvent.VALID)
                         {
                               return true;
                         }
                         else
                         {
                            errorMessages.addItem
({source:source.listener,message:vResult.message});
                            return false;
                         }
                }
        ]]>
    </mx:Script>

    <mx:StringValidator  id="validator"  required="true" />

    <mx:Panel title="Employee Information" width="75%" height="75%"
        paddingTop="10" paddingLeft="10" paddingRight="10"
paddingBottom="10">
            <mx:Form>
                <mx:FormItem label="First Name: ">
                    <mx:TextInput id="fname" width="100%"
change="validateMe('First Name',fname);"/>
                </mx:FormItem>
                                <mx:FormItem label="Last Name: ">
                    <mx:TextInput id="lname" width="100%"
change="validateMe('Last Name',lname);"/>
                </mx:FormItem>
                <mx:FormItem  width="100%" >
                <mx:HBox>
                    <mx:Button id="submitButton" label="Submit"
click="submitForm();"  />
                    <mx:Button id="clearButton" label="Clear"
click="fname.text='';lname.text=''"  />
                </mx:HBox>
                </mx:FormItem>
            </mx:Form>
    </mx:Panel>
</mx:Application>


Regards,
Arul Murugan

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Flex 
India Community" group.
To post to this group, send email to flex_india@googlegroups.com
To unsubscribe from this group, send email to 
flex_india+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/flex_india?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to