3 Replies Latest reply on Nov 27, 2006 12:49 PM by deepa subramaniam (adobe)

    Validators' bug

    dimival Level 1
      Ok this is really absurd, i am using a NumberValidator which, as the name implies, VALIDATES that a String contains a valid number so if the String IS NOT a valid number it should throw an INVALID ValidationResult.

      The thing is that if i set the validator's required property to false (because in my Form this value is optional) and then type an invalid number, the validator DOES NOT throws the invalid result. If i set it to true, then it WORKS.

      So WHAT'S THE DEAL WITH THIS????????? it is really absurd that if iset the required property to false it stops validating properly.

      Here's the example from the Adobe Flex 2 Language Reference itself which if you set the required property to false doesn't validate properly. Try it, type something that is not a number ("Hello" for example) and then press the button and it won't do anything, it won't throw an invalid result or a valid result either. So HOW DO I MAKE THIS WORK? have a non-required textInput whose input must be a valid number which is validated by a NumberValidator?

      <mx:NumberValidator source="{age}" property="text" integerError="Enter Integer value"
      minValue="18" maxValue="50" domain="int" required="false"
      trigger="{myButton}" triggerEvent="click"
      valid="Alert.show('Validation Succeeded!');"/>

      <mx:Panel title="NumberValidator Example" width="75%" height="75%"
      paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10">

      <mx:FormItem label="Enter an age between 18 and 50: ">
      <mx:TextInput id="age" width="100%"/>

      <mx:FormItem >
      <mx:Button id="myButton" label="Validate" />
        • 1. Re: Validators' bug
          deepa subramaniam (adobe) Level 2
          This was a bug in the Flex 2 release. It has been fixed in internal builds and will be included in the next public drop of Flex, which will be soon.

          As a workaround, you can remove the NumberValidator.isRealValue() method and your validator will validate correctly. NumberValidator.isRealValue() was adding an unnecessary isNaN check that caused the bug.

          • 2. Re: Validators' bug
            dimival Level 1
            Thanks for your reply, i wonder if this bug happens on other validator subclasses.

            You said that as a workaround i should remove a method, but what you mean by remove? extend the component, override the method and have an empty implementation? Or do you mean to modifiy the flex original source code to remove this?

            Thanks again for the quick reply
            • 3. Re: Validators' bug
              deepa subramaniam (adobe) Level 2
              You can hack the original source code, but the better way would be to extend NumberValidator and override the isRealValue() method to do exactly the logic in Validator.isRealValue().