Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove validation programmatically from flex component

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?

like image 584
Nachiket Avatar asked Dec 01 '25 21:12

Nachiket


2 Answers

I had the same problem, I understood that i had to clear the last validation before the next one.

private function resetValidationWarnings():void {
                for each (var validator:Validator in arrValidators) {
                    validator.dispatchEvent(new ValidationResultEvent(ValidationResultEvent.VALID));
                }
            }

this is a kinda POG but it got the job done!

hope it helps !

like image 114
Vinícius Hoffmann Fontoura Avatar answered Dec 04 '25 15:12

Vinícius Hoffmann Fontoura


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"> 

    <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>
like image 39
Todd Moses Avatar answered Dec 04 '25 13:12

Todd Moses