8 Replies Latest reply on Feb 29, 2008 9:18 AM by cosmacol

    ValidationResultEvent field issue

    Mongolian Beef Level 1
      Hi,

      I'm trying to validate a field that will be containing an email input using the mx:EmailValidator. I've followed the instructions on the Flex 3 Component Explorer Web site and it works out like advertised. However, when I try to access the field property of the ValidationResultEvent, its always returning null (or empty). I made sure to put the name and id properties when defining my FormItem and TextInput fields. Here is my sample code:

      <mx:FormItem name="emailItem" id="emailItem" label="Email" width="100%" fontSize="10" required="true">
      <mx:TextInput name="email" id="email" width="100%" fontSize="10"/>
      </mx:FormItem>

      <mx:EmailValidator
      id="emailValidator"
      source="{email}"
      property="text"
      valid="fieldValidation(event);"
      invalid="fieldValidation(event);"/>

      private function fieldValidation(eventObj:ValidationResultEvent):void {
      Alert.show(eventObj.field);
      }


      Now when I put in some wrong information in the email field above and then click on another field to invoke the event, the alert message always displays a blank... so its always coming in as null or ''. I would expect it to display either "emailItem" or "email".

      I also see a similar issue here, and is almost 2 years old, but no reply.

      Anyone have any ideas? Thanks in advanced.

      Los
        • 1. Re: ValidationResultEvent field issue
          Level 1
          try emailItem.email

          as email is a sub of emailItem
          • 2. Re: ValidationResultEvent field issue
            Mongolian Beef Level 1
            Hi,

            Thanks for the reply. Not sure what you mean though. I thought the ValidationResultEvent would do this automatically when calling it's field property. Hence doing something like this--Alert.show(eventObj.field)-- would display "email", "emailItem" or "emailItem.email". I need this because I'm using many different fields for validation and would like to identify the field that triggered the event so that I can handle it appropriately.

            Los

            • 3. Re: ValidationResultEvent field issue
              Level 1
              Vaidation Result would handle that but it seems you are not passing the value to the validator

              It is trying to get the text property of email while bypassing the form emailItem
              • 4. Re: ValidationResultEvent field issue
                Level 1
                disregard.

                You are correct.

                It seems your validator is not passing the field after validation
                • 5. Re: ValidationResultEvent field issue
                  Mongolian Beef Level 1
                  Thanks for the replies.

                  So is it something I'm doing wrong in my code, or you think this is a bug with Flex 3? (BTW, I'm using the latest version of Flex 3). Thanks again.

                  Los
                  • 6. Re: ValidationResultEvent field issue
                    Garyl Woolworth Level 1
                    I've never actually gotten the field property to work correctly. However here is a method I have used that I actually prefer over the field property because it gives you much more access to the data you are looking for on the result event.

                    <?xml version="1.0" encoding="utf-8"?>
                    <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">

                    <mx:Script>
                    <![CDATA[
                    import mx.controls.Alert;
                    import mx.events.ValidationResultEvent;

                    private function fieldValidation(eventObj:ValidationResultEvent):void {
                    var validator:EmailValidator = eventObj.currentTarget as EmailValidator;
                    Alert.show(validator.source.toString(), "Source");
                    Alert.show(validator.source.text.toString(), "Source Value");
                    Alert.show(validator.property, "Validating Property");
                    }
                    ]]>
                    </mx:Script>

                    <mx:EmailValidator
                    id="emailValidator"
                    source="{email}"
                    property="text"
                    valid="fieldValidation(event)"
                    invalid="fieldValidation(event)"/>

                    <mx:Form>
                    <mx:FormItem label="First Name" width="100%" fontSize="10" required="false">
                    <mx:TextInput id="firstName" fontSize="10"/>
                    </mx:FormItem>

                    <mx:FormItem label="Email Address" width="100%" fontSize="10" required="true">
                    <mx:TextInput id="email" fontSize="10"/>
                    </mx:FormItem>
                    </mx:Form>
                    </mx:Application>
                    • 7. Re: ValidationResultEvent field issue
                      Mongolian Beef Level 1
                      Hi,

                      Thanks for the reply. I tried out your solution (the source value comes out null). Although I see what you're trying to do, it seems like you need to do a bunch of "instanceof" type operations (Java-speak). Now say I follow your example and have 2 email fields, one as the original and the other to verify. How do I differentiate the two email fields? Now, say I add a bunch of normal fields (i.e. using mx:Validator) in addition to the email fields. With your example, I will need to do instanceof operations on the Event passed in, then try to determine what field that exactly is. I still am not sure how to do this with your example.

                      If the field property actually worked with the ValidationResultEvent, then I already know what field triggered the error and can act upon it... no casting and comparisons necessary, just switch statement.

                      Anyway, I've bypassed using this type of validation (been overwhelmed with frustration). Seems like this is a bug that existed for a while now (see my original post) and probably won't get fixed anytime soon. Thanks for all your help though.

                      Los
                      • 8. Re: ValidationResultEvent field issue
                        cosmacol Level 1
                        I have the same problem, 'field' property is always null. I searched the framework sources, and it seems that this property is never processed, see the handleResults() method of mx.validators.Validator - it simply creates a new ValidationResultEvent without specifying a value for 'field' in the constructor and never assign a value to the property later.

                        This is clearly a bug in my opinion. I didn't found a matching entry in the adobe jira database, so I created one:

                        http://bugs.adobe.com/jira/browse/SDK-14823

                        I hope that Adobe will fix this soon, it should be an easy one..