Try this...

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.macromedia.com/2005/mxml"; 
xmlns="*">

 

<mx:Script>

        <![CDATA[

 

            // Import event class

            import mx.events.ValidationResultEvent;
            import mx.validators.Validator;
            import flash.events.Event;

            private function handleValid(eventObj:Event):Void
            {
                var result:ValidationResultEvent = Validator
(strV).validate();
                
                if(result.type==ValidationResultEvent.VALID)
                    sub_btn.enabled = true;
                else
                    sub_btn.enabled = false;
            }

 

            // Submit form is everything is valid. 

            private function submitForm():Void
            {
                test.send();
            }

        ]]>

</mx:Script>

 

<mx:StringValidator id="strV" source="{test1}" property="text" 
minLength="5" />

 

      <mx:HTTPService id="test" 
url="http://localhost/xml/template/test.xml"; method="POST" 
showBusyCursor="True">

            <mx:request xmlns="">

                  <test1>{test1.text}</test1>

                  <test2>{test2.text}</test2>

            </mx:request>           

      </mx:HTTPService>

 

      <mx:Canvas width="100%" height="100%">

            <mx:Form x="34" y="25">

                        <mx:Label 
text="{test.result.root.tblTest.success}"/>

                  <mx:FormHeading label="Test Form"/>

                  <mx:FormItem label="Test 1" id="test1_lbl">

                        <mx:TextInput id="test1" change="handleValid
(event)"/>          

                  </mx:FormItem>

                  <mx:FormItem label="Test 2" id="test2_lbl">

                        <mx:TextInput id="test2"/>

                  </mx:FormItem>

                  <mx:Button label="Submit" id="sub_btn" 
click="submitForm();" enabled="false"/> 

            </mx:Form>  

      </mx:Canvas>

</mx:Application>

What i have done here is when the change event is fired on the text1 
TextInput the handleValid function is called. This checks to see if 
the string is valid.

Let me know if this works,

Simon Barber


--- In flexcoders@yahoogroups.com, "Ken Bromberger" <[EMAIL PROTECTED]> 
wrote:
>
> Hi! I am new to flex and I am working on using the validators flex 
2.0
> includes.
> 
>  
> 
> I have set up a form and can submit data to my test database using
> HTTPService and the request tags and return a result. When I add a
> string validator to my code the form no longer submits the 
HTTPService
> request. If I remove the stringValidator from my code the form 
works
> just fine. What am I missing on this?? Is there a good resource 
with
> examples of how to implement validation? 
> 
> Thanks! - Ken
> 
>  
> 
> Here is my code:
> 
>  
> 
> <?xml version="1.0" encoding="utf-8"?>
> 
> <mx:Application xmlns:mx="http://www.macromedia.com/2005/mxml";
> xmlns="*">
> 
>  
> 
> <mx:Script>
> 
>         <![CDATA[
> 
>  
> 
>             // Import event class
> 
>             import mx.events.ValidationResultEvent;
> 
>             
> 
>             private function
> handleValid(eventObj:ValidationResultEvent):Void             {
> 
>                 if(eventObj.type==ValidationResultEvent.VALID)    
> 
>                     sub_btn.enabled = true;
> 
>                 else
> 
>                     sub_btn.enabled = false;
> 
>             }
> 
>  
> 
>             // Submit form is everything is valid. 
> 
>             private function submitForm():Void {
> 
>             test.send();
> 
>             }
> 
>  
> 
>         ]]>
> 
> </mx:Script>
> 
>  
> 
> <mx:StringValidator id="strV" source="{test1}" property="text"
> minLength="5" valid="handleValid(event)" invalid="handleValid
(event)"/>
> 
>  
> 
>       <mx:HTTPService id="test"
> url="http://localhost/xml/template/test.xml"; method="POST"
> showBusyCursor="True">
> 
>             <mx:request xmlns="">
> 
>                   <test1>{test1.text}</test1>
> 
>                   <test2>{test2.text}</test2>
> 
>             </mx:request>           
> 
>       </mx:HTTPService>
> 
>  
> 
>       <mx:Canvas width="100%" height="100%">
> 
>             <mx:Form x="34" y="25">
> 
>                         <mx:Label
> text="{test.result.root.tblTest.success}"/>
> 
>                   <mx:FormHeading label="Test Form"/>
> 
>                   <mx:FormItem label="Test 1" id="test1_lbl">
> 
>                         <mx:TextInput id="test1" 
change="handleValid(event)"/>          
> 
>                   </mx:FormItem>
> 
>                   <mx:FormItem label="Test 2" id="test2_lbl">
> 
>                         <mx:TextInput id="test2"/>
> 
>                   </mx:FormItem>
> 
>  
> 
>                         <mx:Button label="Submit" id="sub_btn"
> click="submitForm();" enabled="false"/>                   
> 
>  
> 
>             </mx:Form>  
> 
>       </mx:Canvas>
> 
>  
> 
> </mx:Application>
>







--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to