6 Replies Latest reply on Dec 29, 2009 8:25 AM by JabbyPandaUA

    Validation must pass twice to clear errorColor?

    PeakDigital Level 1

      I am using an external CSS file to style my app. In it I specify a custom errorColor property for TextInput controls.

       

      This StringValidator is placed on a TextInput:

      <mx:StringValidator id="validatorUserName"
              source="{textinputUserName}"
              property="text"
              required="true"
              minLength="4" maxLength="25" 
              tooShortError="Your username must be at least 4 characters long."
              tooLongError="Your username must be less than 25 characters long."
              trigger="{textinputUserName}" triggerEvent="valueCommit"
              valid="formatControlErrorStatus(textinputUserName,0)"
              invalid="formatControlErrorStatus(textinputUserName,1)"/>

       

      The StringValidator's valid and invalid events call a function to carry out further commands. I want the invalid field to be very boldy marked, so I have the function thicken its border and set the background color to orange. Once it validates, then it returns the control's formatting to the default.

       

      public function formatControlErrorStatus(theControl:Object,isError:Number):void
          {//valid/invalid trigger must pass name of target control and 0 for no error, 1 for error
          if(isError==1)
              {
              theControl.setStyle("borderColor","#FF4B00");
              theControl.setStyle("borderThickness",2);
              theControl.setStyle("backgroundColor","#FF4B00");
              theControl.setStyle("backgroundAlpha",.4);
              }
          else if (isError==0)
              {
              theControl.setStyle("borderColor","#7D6441");
              theControl.setStyle("borderThickness",1);
              theControl.setStyle("backgroundColor","#FFFFFF");
              theControl.setStyle("backgroundAlpha",.75);

              }
          }

       

      Here is the problem: When the StringValidator's "valid" event is fired, the code in formatControlErrorStatus is completed successfully, but the border of the TextInput remains the errorColor color rather than returning to its default color.  If I go into the field and exit it again without changing the value, then the errorColor border disappears and is replaced properly with the standard border. Why would the field have to pass validation twice to reset the border color?