3 Replies Latest reply on Jun 26, 2008 11:31 AM by smgilson

    Weird validate/binding problem

      Hello all!

      I have a TextInput field that is to accept a date. There is a date validator attached to the
      field and the text property of the date field is bound to a property in another
      field. Here's the code:


      <mx:DateValidator id="validateBirthdayTI"

      <mx:Binding source="{Date.parse(birthdayTI.text)}"


      formIsValid = formIsValid && validate(validateBirthdayTI);

      When the validator runs, I get the following error when doing a try/catch, otherwise it fails silently.

      "The source attribute must be specified when the property attribute is specified."

      This seems to say that the source attribute for the validator isn't correct, but I don't see
      anything wrong with it (and other fields/properties are fine). It also seems to somehow be
      tied in to the binding as if I comment out the binding it works (and validates) just fine. I
      have a feeling I'm running up against one of those very strange Flex errors that don't mean
      what they say exactly ; )

      Any help is very much appreciated, I've been beating on this thing off and on for a week
      and am getting pretty frustrated.



        • 1. Re: Weird validate/binding problem
          smgilson Level 1
          I might be missing something, but to invoke a validator you use the DateValidator.validate() method. So, shouldn't your example use the line validateBirthdayTI.validate() to invoke the validator? Something like this:

          public var vResult:ValidationResultEvent;
          vResult = validateBirthdayTI.validate();

          if (vResult.type==ValidationResultEvent.VALID) {
          // Validation succeeded.
          else {
          // Validation failed.

          • 2. Re: Weird validate/binding problem
            gander55 Level 1
            Stephen, Thanks for the response. You got me, I accidentally left out some code.
            private function validate(validator:Validator):Boolean
            var validationResultEvent:ValidationResultEvent =
            validator.validate(null, false);

            return validationResultEvent.type == ValidationResultEvent.VALID

            So validate is a local method that calls the actual validator.

            That help at all?


            • 3. Re: Weird validate/binding problem
              smgilson Level 1
              Hmm, nothing sticks out to me. If you are invoking the DataValidator programmaticaly, try setting triggerEvent="" in the DateValidator. The only thing that I can think of is that the validator is getting invoked every time you update birthdayTI, and also when you invoke it by calling your validate() method.

              You might also try calling DateValidator.validate() with no args, since you are only passing the default values.