#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2011
    Posts
    2
    Rep Power
    0

    Set an Error message for custom validator


    I have custom validator apllied to many comboboxes in different tabs of application. Its is performing the same validation for all the comboboxes. The only difference is for ecah combobox the custom validator should return a different error messagae. How can error message be specified...?...like some error property in mxml or by somehow passing the error message as parameters to custom validator class, as I dont want to have one custom validator for each component..
    Any suggestions how this can be achieved...
  2. #2
  3. Plays with fire
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2003
    Location
    Barsoom
    Posts
    960
    Rep Power
    97
    This is a pretty big question and without more information we can't really help.
    “Be ashamed to die until you have won some victory for humanity.” -- Horace Mann

    "...all men are created equal." -- US Declaration of Independence
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2011
    Posts
    2
    Rep Power
    0
    Originally Posted by Frank Grimes
    This is a pretty big question and without more information we can't really help.
    here is the more info:The custom validator looks like:
    public class cmbRequiredValidator extends Validator
    {
    public function cmbRequiredValidator()
    {
    super();
    }

    override protected function doValidation(value:Object):Array {
    // create an array to return
    var ValidatorResults:Array = new Array();
    // Call base class doValidation().
    ValidatorResults = super.doValidation(value);
    /* var ErrorMessage:String=ErrorMessage;
    Alert.show(errMessage,"msg"); */
    // Return if there are errors.
    if (ValidatorResults.length > 0)
    return ValidatorResults;

    if (String(value).length == 0)
    return ValidatorResults;

    var newValue:String = value.toString();
    var noOfValues:int = 0;
    var error:Boolean = false;

    if(newValue == "--Select--")
    error = true;

    if (error == true)
    {
    ValidatorResults.push(new ValidationResult(true, null, "Error", ""));
    return ValidatorResults;
    }
    return ValidatorResults;
    }
    }
    }

    Specifying validator source: flexScript:cmbRequiredValidator id="cmbName1_Validator" source="{cmbName1}" property="text" Below is the comonent in mxml: mx:ComboBox id="cmbName1" dataProvider="{cmbArray}" labelField="Check" errorString="Please select Name"

    If i dont specify the errormessage in above custom validator it gives blank message. I dont want to specify it there because on many components i have to apply the same custom validator with a diff error message..

IMN logo majestic logo threadwatch logo seochat tools logo