2 Replies Latest reply on Sep 25, 2006 3:58 PM by dimival

    How to validate multiple controls using a single Validator?

    dimival Level 1
      I am trying to do an HourValidator because Flex doesn't have this, so i am extending from the Validator class. I read in the Creating and extending Flex components document the following:

      "A validator can validate more than one field at a time. For example, you could create a custom
      validator called NameValidator to validate three input controls that represent a person’s first,
      middle, and last names.
      To create a validator that examines multiple fields, you can either define properties on the
      validator that let you specify the multiple input fields, as does the Flex DateValidator class
      class, or you can require that the single item passed to the validator includes all of the fields to
      be validated."


      So according to the document i need to define properties so i defined 4 properties:

      startHourSource: the input control containing the starting hour
      startHourProperty: the control's property (in this case the text property)
      endHourSource: the input control containing the end hour
      endHourProperty: the control's property (in this case the text property)

      The thing is that when i call the doValidation of the superclass (to validate the required property) it does return a validation error but it doesn't mark the input control with the red frame that indicates there's a validation error. I assume that is because the source and property properties of the validator are null but that's ok because i am not using them, instead i am using the 4 properites mentioned above.

      So what do i need to do or override so the red frame appears in the input controls??
        • 1. Re: How to validate multiple controls using a single Validator?
          Simeon
          The input controls have a property called "errorString" you can set this on the control you want to be red. Just errorString is datatyped as string and is the message you want displayed in the red flag.

          HTH

          sim
          • 2. Re: How to validate multiple controls using a single Validator?
            dimival Level 1
            Yeah i already know that, but when you use the doValidation method, which does the requiredField validation, by default marks the input control with the red frame, so that's why i am trying to do, doing it so it will do it by default.
            For example, try this:

            <mx:TextInput id="test"/>
            <mx:Validator id="validateTest" source="{test}" property="text" required="true" requiredFieldError="The field is empty"/>

            If you do validateTest.validate( ) and the textinput is empty, it will mark it with the red frame by default, that's the kind of behave i want for my HourValidator, but if it is not possible then the solution you suggested would be the only one to do this.