3 Replies Latest reply on Mar 29, 2012 10:08 AM by bucpatr1

    Validator not returning the results.

    yusufnazir Level 1

      Hi All,


      I have extended the StringValidator class in order the create a username validator. When a new user is being registered, the username is validated on the server to check if it exists.

      The code is not throwing errors and i know the remoteobject calls work. The push sets the message, but the problem is that the result is not returned.


      Is the flow correct?


      public class PosUsernameValidator extends StringValidator {
                private var userServiceRO:RemoteObject = new RemoteObject();
                private var validatorResults:Array = new Array();
                public function PosUsernameValidator(){
                     userServiceRO.destination = "UserService";
                     userServiceRO.getUserByUserName.addEventListener("result", getUserByUserNameRH);
                     userServiceRO.getUserByUserName.addEventListener("fault", getUserByUserNameFH)
                override protected function doValidation(value:Object):Array {
                     validatorResults = super.doValidation(value); 
                     return doForUserName(value);
                private function doForUserName(value:Object):Array{
                     return validatorResults;
                private function getUserByUserNameRH(r:ResultEvent, t:Object = null):void{
                     var user:User = r.result as User;
                          validatorResults.push(new ValidationResult(true, null, "Username error","Username already taken!"));
                private function getUserByUserNameFH(f:FaultEvent, t:Object = null):void{
        • 1. Re: Validator not returning the results.
          bucpatr1 Level 2

          At first glance I would say that trying to combine your client-side and server-side validation into a single class like that is not a good idea. In doForUserName() you are making an asyncronous server call. The validatorResults will get returned immediately, so by the time your handler method executes it is already too late. Rather than trying to do both sets of validation at once, remove the server-side code from this class and use it as a normal flex validator. Then in your component (or better yet in your controller class if you follow an MVC pattern) call your service method after the client side validator returns a valid result.

          1 person found this helpful
          • 2. Re: Validator not returning the results.
            yusufnazir Level 1

            If i use a normal flex validator, can i still send the message to the input field, as it is done by the validator?

            I don;t want to show an alert box, but cause the input field the change color and have a message highlighted when you are over the input field.

            If possible how can it be done?

            • 3. Re: Validator not returning the results.
              bucpatr1 Level 2

              Once you have the message string from the server-side error, bind it to the 'errorString' property of whichever input component you want to display the error on. Doing that will give you the red border and tooltip just like if you used a validator. Just remember to set the error string back to "" to clear the message once the validation passes.