2 Replies Latest reply on Dec 15, 2009 9:12 PM by Gregory Lafrance

    Disassociating Validator from TextInput

    Salesfarce

      Hi all,

       

      As the title says, I want to disassociate a validator from a TextInput, but cannot seem to do so.

       

      At one point in my program it makes sense to use validation on the TextInput, but at another point it does not.

       

      So when it does make sense to use the validator on the TextInput I would do the following:

       

      emailValid = new EmailValidator();

      emailValid.source = theTextInput;

      emailValid.property = 'text';

       

      ...and all is well.

       

      Later I want to use the same field, but not have the validator work on the field.

       

      I have tried:

      emailValid.source = null;

      AND

      emailValid.enabled = false;

      AND EVEN

      emailValid = new EmailValidator();

      emailValid.source = null;

      emailValid.enabled = false;

       

      ...and still this does nothing.  The validator is still somehow associated to the TextInput.

       

      So I did an ObjectUtil.toString on the TextInput and I can see that there is some type of association between the TextInput and the validator still.  I am pretty new to flex but to me it looked like emailValid became a property of theTextInput.

      So I tried:

      theTextInput.emailValid = null;

      ...and that expectedly just threw a syntax error.

       

      How do I disassociate the validator from the textinput?

       

      Thanks Much!

        • 1. Re: Disassociating Validator from TextInput
          Salesfarce Level 1

          So I think the proper answer to this question is that you cannot accomplish this.  As a workaround just use a second field and only keep the one you need visible.

          • 2. Re: Disassociating Validator from TextInput
            Gregory Lafrance Level 6

             

             

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
              <mx:Script>
                <![CDATA[
                  import mx.events.ValidationResultEvent;
                  import mx.validators.EmailValidator;
                  
                  private var emailValid:EmailValidator;
                  private function doValidate():void{
                    emailValid = new EmailValidator();
                    emailValid.source = theTextInput;
                    emailValid.property = 'text';        
                  }      
                  private function noValidate():void{
                    emailValid.dispatchEvent(new ValidationResultEvent(ValidationResultEvent.VALID));
                    emailValid.required=false;
                    emailValid.requiredFieldError="";
                  }      
                ]]>
              </mx:Script>
              <mx:TextInput id="theTextInput"/>
              <mx:Button label="Add Valildation" click="doValidate();"/>
              <mx:Button label="Remove Validation" click="noValidate();"/>
            </mx:Application>
            
            

            If this post answers your question or helps, please mark it as such.


            Greg Lafrance
            www.ChikaraDev.com

            Flex Development and Support Services

            1 person found this helpful