1 Reply Latest reply on Mar 1, 2007 1:52 AM by Graeme Harker

    Validator - Event listening

    jamProg
      I need to change the trigger event for a validator so it checks as soon as information is entered in a text area.
      1. Currently I have to click on something else before the Validator checks to see if anything is in the text area. I would like it to check as soon as data is entered into the text area. (like somehow linking it to the dataChange event of the text Area)
      NB The Validator is attached to a custom component that is dynamically created when the application is run.

      2. I have a group of labels which change color based on the validator when it is clicked on. Likewise each label only updates when I click on another label and then click back on the original label. I am somewhat new to Flex 2 so I am a bit confused about how event listening works and how events can be handled.

      My code follows below:

      // Event listener for the valid and invalid events - in script
      public function handleValid(eventObj:ValidationResultEvent):Boolean
      {
      if(eventObj.type==ValidationResultEvent.VALID){
      isValid = true;
      }
      else
      {
      isValid = false;
      }
      return isValid;
      }

      // Constructor
      <mx:Validator id="reqValid" required="true"
      source="{feedbackText}" property="text"
      valid="handleValid(event)" invalid="handleValid(event)"/>
        • 1. Re: Validator - Event listening
          Graeme Harker Level 1
          Either
          a) use the triggerEvent="change" attribute of the Validator so that the Validator is reevaluated after each key press (by default the Validator is triggered by the source's "valueCommit" event (which is only dispatched when focus leaves the TextInput)
          or
          b) create your own event handler for the TextInput's change event and call the Validator's validate() method programatically from your handler