views:

247

answers:

1

Hello, How to remove validation programmatically from flex component This is my method

public static function validateRequired(txt:TextInput, errorMessage:String="This field is required"):Boolean
        {
                var v:Validator = new Validator();

                v.listener = txt;
                var result:ValidationResultEvent = v.validate(txt.text);
                var returnResult:Boolean = (result.type == ValidationResultEvent.VALID);
                //Alert.show("validation result is " + returnResult);
                if (!returnResult) {
                    v.requiredFieldError = errorMessage;
                }
                return returnResult;
        }

But, as each time i am creating new validator, so pop-up contains multiple messages like

This field is required.
This field is required.

How to remove error messages attached with component?

A: 

The Validator.enabled property lets you enable and disable a validator. When the value of the enabled property is true, the validator is enabled; when the value is false, the validator is disabled. When a validator is disabled, it dispatches no events, and the validate() method returns null.

For example, you can set the enabled property by using data binding, as the following code shows:

<?xml version="1.0"?>
<!-- validators\EnableVal.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"&gt; 

    <mx:ZipCodeValidator id="zcVal" 
        source="{inputA}" 
        property="text" 
        required="true" 
        enabled="{enableV.selected}"/>

    <mx:TextInput id="inputA"/> 
    <mx:TextInput/> 
    <mx:CheckBox id="enableV" 
        label="Validate input?"/>
</mx:Application>
Todd Moses
hmm.. thats okay.. but my problem is I don't want to write all the validator in mxml. I want to check like Util.validateRequired(txt) on submit.. when i press submit twice without writing anything in textbox so validation falis, I get same error message twice in error pop-up.
Nachiket
Turn off the other validator and then call your validator funtion from a button click event.<mx:Button label="Submit" click="Util.validateRequired(txt);"/>
Todd Moses