【问题标题】:Flex, any way to programmatically highlight a field in red the way the validators do?Flex,有什么方法可以像验证器那样以编程方式突出显示红色字段?
【发布时间】:2012-04-22 20:56:03
【问题描述】:

我正在对表单中的某些字段值进行一些编程验证,Actionscript 中是否有任何方法可以像验证器那样以红色突出显示该字段?

【问题讨论】:

    标签: apache-flex actionscript flex4 flex3 adobe


    【解决方案1】:

    您只需要在程序验证错误上设置 errorString 属性

    <s:TextInput errorString="error string value" />
    <mx:TextInput errorString="error string value" />
    

    【讨论】:

    • 好答案。我认为要求 AS3 解决方案意味着它是一个 AS3 对象。但是,如果您正在启动/使用 Flex,您确实希望使用 Flex 提供的工具。您能否扩展您的评论并展示如何在 AS3 代码中而不是在标记中设置此值?
    • 谢谢,我刚刚测试了在验证失败时设置 errorString 属性并且效果很好。但是,您如何清除验证错误?将 errorString 设置为 null 无效。
    • errorString 存在正确重置的问题,我所在的团队必须使用空字符串 ("") 来清除它。
    【解决方案2】:

    使用:

    var textField:TextField = new TextField();
    addChild(textField);
    

    在 AS3 中突出显示背景:

    textField.background = true;
    textField.backgroundColor = 0xFFF000;
    

    在 AS3 中高亮边框:

    textField.border = true;
    textField.borderColor = 0xFFF000;
    

    要关闭它,只需将适当的布尔值设置为false

    【讨论】:

      【解决方案3】:

      尝试使用辉光滤镜:

      <fx:Declarations>
          <s:GlowFilter id="gf" color="#ff0000" alpha="1" blurX="5" blurY="5" />
      </fx:Declarations>
      
      <s:TextInput id="ti" width="80%"/>
      <s:ToggleButton id="btn" label="glow on/off" click="ti.filters = btn.selected?new Array(gf) : null;"/>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-06-08
        • 2023-03-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多