如何以编程方式从 flex 组件中删除验证 [英] How to remove validation programmatically from flex component

查看:29
本文介绍了如何以编程方式从 flex 组件中删除验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以编程方式从 flex 组件中删除验证这是我的方法

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

此字段为必填项.
此字段为必填字段.

如何删除组件附带的错误信息?

How to remove error messages attached with component?

推荐答案

Validator.enabled 属性允许您启用和禁用验证器.当 enabled 属性的值为 true 时,验证器被启用;当值为 false 时,验证器被禁用.当验证器被禁用时,它不会调度任何事件,并且 validate() 方法返回 null.

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.

例如,您可以使用数据绑定来设置 enabled 属性,如下代码所示:

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>

这篇关于如何以编程方式从 flex 组件中删除验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆