5 Replies Latest reply on Oct 19, 2009 6:06 AM by Jerry62712

    How Do I get error in validator

    Jerry62712 Level 1

      I have several validators.  When you do something invalid, it highlights the field and has a message displayed if you position to that field.  I understand that you can include an error object in the validator that will cause a popup window with the error.


      1) how do you do that?

      2) can the window's text be sizable?

      3) do I need multiple validators or can I use one and if so how would I change the message to reflect the field being checked?

        • 2. Re: How Do I get error in validator
          Jerry62712 Level 1

          If I understand it, this creates an array of validators and then uses a built-in method to validate all of them at once.  It cycles through the array and collects the field name and message.  That message may be explicit or magical (system generated perhaps by fairies).  The field name is concatenated to the message and pushed into another array.


          An alert box is created with the array and a "join" that I'm not familiar with but appears to be a implicit loop on the array.  I"m also not familiar with the "FormItem" that seems to find the name (id) of the form field from the err object.  Not too much for a newbie to get if I do in fact get it.


          Thanks for the pointer.  I'm off to try it out.

          • 3. Re: How Do I get error in validator
            Jerry62712 Level 1

            I tried it and got this error:


            //    TypeError: Error #1034: Type Coercion failed: cannot convert mx.validators::NumberValidator@ac37501 to mx.events.ValidationResultEvent.
            //    at FSCalc/swapToResultsState()[C:\Flex Builder 3\FSCalc\FSCalc\src\scripts\FSUtil.as:49]
            //    at FSCalc/__calculateButton_click()[C:\Flex Builder 3\FSCalc\FSCalc\src\FSCalc.mxml:1195]
            //    var validatorArray:Array = new Array();
            //    validatorArray.push(numValResidence);
            //    validatorArray.push(numValEarned);
            //    validatorArray.push(numValOther);
            //    validatorArray.push(numValAsset);
            //    validatorArray.push(numValDependentCare);
            //    validatorArray.push(numValCourtOrdered);
            //    validatorArray.push(numValElderly);
            //    validatorArray.push(numValRent);
            //    validatorArray.push(numValInsurance);
            //    var validatorMsgArray:Array = Validator.validateAll(validatorArray);
            //    var validatorPassed:Boolean = validatorMsgArray.length == 0;
            //    if (validatorPassed) {
            //        Alert.show("**Testing** all validator tests passed");
            //    }
            //    else {
            //        var validatorErr:ValidationResultEvent;
            //        var errorStringArray:Array = [];
            //        for each (validatorErr in validatorArray) {
            //            var errField:String = FormItem(validatorErr.currentTarget.source.parent).label;
            //            errorStringArray.push(errField + ": " + validatorErr.message);
            //        }
            //        Alert.show(errorStringArray.join("\n\n"),
            //                "Invalid form", Alert.OK);
            //    }


            I added the error after this ran so the numbers would be off a little, but I'm sure you will understand.

            • 4. Re: How Do I get error in validator
              paul.williams Level 4

              The line:


              for each (validatorErr in validatorArray) {


              Should be:


              for each (validatorErr in validatorMsgArray) {

              • 5. Re: How Do I get error in validator
                Jerry62712 Level 1

                You, sir, are a gentleman and a scholar.  And you have the eyes of an eagle.  It's now working was expected.