While this does the trick, what if I have 3 inputs? While one passes the validation the sendForm() will be executed while the other 2 inputs are still unvalidated? I want to make sure all of them are validated before executing sendForm().
 
BTW, cool about the on change validation. One thing though... is there a way to make the error tooltip show up programatically instead of having to hover over my mouse pointer?
 
Thanks,
Alexander

Oriol Gual <[EMAIL PROTECTED]> wrote:
Hi,

What I do to validate a form, is somethig like this:

<mx:Script>
    <![CDATA[   

private function handleValid(eventObj:ValidationResultEvent) : void
        {
            if(eventObj.type==ValidationResultEvent.VALID ) {
                formValid = true;
            } else {
                formValid = false;
            }      
        }   
private function sendForm() : void
{
if(formValid) {
//do whatever you have to do to send the form
} else {
alert.show("Form is not valid!","Alert");
}
}

private var formValid : Boolean = false;

]]>
</mx:Script>

<mx:StringValidator source="{inputText}" property="text" minLength="3" maxLength="20"
 trigger="{inputText}" triggerEvent="change" valid="handleValid(event)" invalid="handleValid(event)"/>

<mx:Form>
<mx:FormItem label="Input some text" required="true" direction="horizontal" fontWeight="bold" textAlign="left">
<mx:TextInput id="inputText" width="80" maxChars="20"/>
 </mx:FormItem>
</mx:Form>
<mx:Button id="fromButton" label="Send form" click="sendForm()"/>
 
When the user inputs some text in the textinput the validation occurs automatically ( trigger="{inputText}" triggerEvent="change") and the function handleValid is called. Then, when clicking the button if the variable formValid it's true we can send the form.

By the way, I have a question, what is the meaning of the models with flex 2 and forms? Because they're declared in the examples but the validators don't use them.

Hope this helps,

Oriol


2006/4/2, Dreamer <[EMAIL PROTECTED]>:
Alex & Alex,

                 you can put the data be validated in a model.like this:
                        <mx:Model id="order">
                                <email>{email.text }</email>//email is a textInput controller's id
                        </mx:Model>
        then define a validator:

   <mx:EmailValidator field="order.email"/>

then write a function in the script tag:

  function confirmOrder(): Void {

        if (mx.validators.Validator.isStructureValid(this, 'order')) {
                mx.controls.Alert.show("Success!!");
                addMember();
          }
    else {
                mx.controls.Alert.show("Please enter valid data in the fields with errors and try again.", "Problem");
            }

}


Peace,

Dreamer  in china
[EMAIL PROTECTED]
2006-04-02

======= 2006-04-02 01:37:17 £º=======

>Hi Mike,
>
>I understand the login, but how do I reference the validation?
>
>I mean what would actually go where you have "validation is success".
>
>I'm not an actionscrip expert! I'm a cfforever guy ;-).
>
>Alexander
>
>
>--- In [email protected], "Dreamer" <[EMAIL PROTECTED]> wrote:
>>
>> Alex & Alex,
>>
>>      you can write a function,like that.
>>
>>      if(validation is success)
>>              addMember();
>>      else
>>              alert("invalid input!!!");
>>
>>
>>  Peace,
>>
>> Dreamer
>> [EMAIL PROTECTED]
>> 2006-04-01
>>
>> ======= 2006-04-01 18:32:22 £º=======
>>
>> >
>> >Hello,
>> >
>> >In a signup form, when I click the submit button I would like for
>all
>> >the validation to happen and then actually hit the addMember()
>> >function.
>> >
>> >But if a form fails the validation how can I prevent the
>execution of
>> >addMember().
>> >
>> >Thanks,
>> >Alexander
>> >
>> >
>> >
>> >
>> >
>> >--
>> >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
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>>
>> = = = = = = = = = = = = = = = = = = = =
>>
>>
>>
>>
>
>
>
>
>
>
>--
>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
>
>
>
>

= = = = = = = = = = = = = = = = = = = =






--
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/




YAHOO! GROUPS LINKS







--
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




Reply via email to