2 Replies Latest reply on May 30, 2006 1:25 AM by ramasatoskar

    how to create my own validations

    j2eesatish Level 1
      Hi I am using String validatins. But i want check some some conditions from my inoput. Is it posible to write my own validations for the components?
      And also can change the look of the validation alert style!.


      Thanks
        • 1. Re: how to create my own validations
          ramasatoskar
          Hi have u read adobe flex2.0 help files there are many topics related to it. Regarding validation the topics lie under the titles
          Creating and Extending Flex 2.0 Components > Creating Nonvisual Flex Components > Creating Custom Validators

          Moreover there is an example that examines three input fields:

          package myValidators
          {
          import mx.validators.Validator;
          import mx.validators.ValidationResult;

          public class NameValidator extends Validator {

          // Define Array for the return value of doValidation().
          private var results:Array;

          public function NameValidator () {
          super();
          }

          override protected function doValidation(value bject):Array {

          var fName:String = value.first;
          var mName:String = value.middle;
          var lName:String = value.last;

          // Clear results Array.
          results = [];

          // Call base class doValidation().
          results = super.doValidation(value);
          // Return if there are errors.
          if (results.length > 0)
          return results;

          // Check first name field.
          if (fName == "" || fName == null) {
          results.push(new ValidationResult(true, "first", "noFirstName",
          "No First Name."));
          return results;
          }

          // Check middle name field.
          if (mName == "" || mName == null) {
          results.push(new ValidationResult(true, "middle", "noMiddleName",
          "No Middle Name."));
          return results;
          }

          // Check last name field.
          if (lName == "" || lName == null) {
          results.push(new ValidationResult(true, "last", "noLastName",
          "No Last Name."));
          return results;
          }

          return results;
          }
          }
          }
          • 2. Re: how to create my own validations
            ramasatoskar Level 1
            Also in another example , you use a NameValidator that validates an item containing three fields named first, middle, and last:

            <?xml version="1.0"?>
            <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns:MyComp="myValidators.*">

            <mx:Model id="person">
            <name>
            <first>{firstInput.text}</first>
            <middle>{middleInput.text}</middle>
            <last>{lastInput.text}</last>
            </name>
            </mx:Model>

            <mx:TextInput id="firstInput"/>
            <mx:TextInput id="middleInput"/>
            <mx:TextInput id="lastInput"/>

            <MyComp:NameValidator id="nameVal"
            source="{person}" property="name"
            listener="{firstInput}"/>

            <mx:Button label="Validate" click="nameVal.validate();"/>

            </mx:Application>