How to programmatically remove validation from a 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, since every time I create a new validator, so the popup window contains several messages, for example

This field is required. This field is required.

How to remove component error messages?

+3
source share
3 answers

The Validator.enabled property allows you to enable or disable authentication. When the value of the enabled property is true, the validator is enabled; when false, the validator is disabled. When the validator is disabled, it does not send any events, and the validate () method returns null.

, , , :

<?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>
+3

, , .

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

POG, !

, !

+4

. , validator , ( ). UIComponent (. UIComponent.errorObjectArray) . , , .

0
source

Source: https://habr.com/ru/post/1732329/


All Articles