Use Validator defined in MXML and call its validate method : Validator « Development « Flex






Use Validator defined in MXML and call its validate method

Use Validator defined in MXML and call its validate method
        

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:Script>
        
            import mx.controls.Alert;
            import mx.events.ValidationResultEvent;
            import mx.validators.PhoneNumberValidator;
            
            private var nameVResult:ValidationResultEvent;

            private function doValidate():void
            {

                    
                nameVResult = nameV.validate();
                    
                if(nameVResult.type==ValidationResultEvent.VALID) {
                    Alert.show("The FormItem has been succesfully validated !", "Validation Message", 4);
                        
                }  else if(nameVResult.type==ValidationResultEvent.INVALID) {
                    Alert.show("The FormItem has NOT been validated !", "Validation Message", 4);
                }
            }
          
    </mx:Script>
    <mx:StringValidator id="nameV"
                        source="{myModel}"
                        property="surname"
                        required="true"
                        maxLength="10"
                        minLength="2"
                        tooLongError="This field contains 10 chars"
                        tooShortError="You have to insert 2 chars at least"
                        listener="{surnameTxt}"
                        />
    <mx:Model id="myModel">
         <root>
             <name>{nameTxt.text}</name>
             <surname>{surnameTxt.text}</surname>
             <phone>{phoneTxt.text}</phone>
         </root>
    </mx:Model>
    <mx:Form id="myForm">
        <mx:HBox>           
            <mx:TextInput id="nameTxt"  />
            <mx:Label id="myLbl" text="" visible="false" />
        </mx:HBox>
        <mx:FormItem label="Insert Surname">
            <mx:TextInput id="surnameTxt" />
        </mx:FormItem>
        <mx:FormItem label="Insert Phone Number">
            <mx:TextInput id="phoneTxt" />
        </mx:FormItem>
        
    </mx:Form>
    
    <mx:Button label="Validate" click="doValidate();" x="284" y="172"/>
    
        
</mx:Application>

   
    
    
    
    
    
    
    
  








Related examples in the same category

1.A basic validator for requirementA basic validator for requirement
2.Set source and trigger for validatorSet source and trigger for validator
3.Set source and property for ValidatorSet source and property for Validator
4.Validate model data with ValidatorValidate model data with Validator
5.Declare validators in ActionScriptDeclare validators in ActionScript
6.Assigning a validator to the data modelAssigning a validator to the data model
7.Set validator property to textSet validator property to text
8.Set validator domainSet validator domain
9.Validator returns ValidationResultEventValidator returns ValidationResultEvent
10.Use Validator.validateAll() to invoke validators in an ArrayUse Validator.validateAll() to invoke validators in an Array
11.Assign validator targetAssign validator target
12.MXML validator classesMXML validator classes
13.Call validator validate method in button click action handlerCall validator validate method in button click action handler
14.Use a Button control to invoke a validatorUse a Button control to invoke a validator
15.Use Validators in functionUse Validators in function
16.Run a list of validators defined in an ArrayRun a list of validators defined in an Array
17.Display validation result for a list of validator one by oneDisplay validation result for a list of validator one by one
18.Use a validator along with a data binding to validateUse a validator along with a data binding to validate
19.Create and invoke a validator programmatically in when a user clicks a Button controlCreate and invoke a validator programmatically in when a user clicks a Button control
20.Invoking multiple validators in a functionInvoking multiple validators in a function
21.Explicitly handing validator validation eventsExplicitly handing validator validation events
22.Create an array with the validatorsCreate an array with the validators
23.Create and invoke a validator programmatically when a user clicks a Button controlCreate and invoke a validator programmatically when a user clicks a Button control
24.Use method to invoke two validators in response to the click event for the Button controlUse method to invoke two validators in response to the click event for the Button control
25.Use a Button control to invoke a validator, but the application first determines which validator to executeUse a Button control to invoke a validator, but the application first determines which validator to execute
26.Use Email validatorUse Email validator
27.Use Array.filter() filter out disabled validatorUse Array.filter() filter out disabled validator
28.Use button event to trigger a validation eventUse button event to trigger a validation event
29.ActionScript based ValidationActionScript based Validation
30.Form data validationForm data validation
31.Triggering validation by using eventsTriggering validation by using events
32.Triggering validation by using the default eventTriggering validation by using the default event
33.Call validation method in a user methodCall validation method in a user method
34.ValidationResultEvent propertyValidationResultEvent property
35.Changing the color of the validation error messageChanging the color of the validation error message
36.Clearing a validation errorClearing a validation error
37.Validate one component but have validation results apply to a different componentValidate one component but have validation results apply to a different component
38.Explicitly handling component validation eventsExplicitly handling component validation events
39.More than one field date validationMore than one field date validation
40.Data Validation Through EventsData Validation Through Events
41.Data Validation Through ActionScriptData Validation Through ActionScript
42.Triggering validation with EventsTriggering validation with Events
43.Write the performValidation() functionWrite the performValidation() function
44.Perform a validation on a required input fieldPerform a validation on a required input field
45.Reset Value based on validation resultReset Value based on validation result
46.Set errorString to create an error tip without performing any validationSet errorString to create an error tip without performing any validation
47.validate handler and invalid handlervalidate handler and invalid handler
48.Run the validate() method and assign the result to a variableRun the validate() method and assign the result to a variable
49.Required field Error messageRequired field Error message