【问题标题】:Flex: force display of control's errorTip (error toolTip) on validation failureFlex:验证失败时强制显示控件的errorTip(错误工具提示)
【发布时间】:2009-11-18 23:05:13
【问题描述】:

当验证器(即 StringValidator、NumberValidator 等)由于验证失败而调度无效事件时,源控件(即 TextInput)的 errorString 属性设置为非空字符串,该字符串会在控件周围创建红色边框并且仅当鼠标悬停在控件上时才会显示工具提示 (errorTip)。

问题:您能否强制立即显示工具提示 (errorTip) 而不是等待用户将鼠标悬停在控件上?如果有,怎么做?

【问题讨论】:

    标签: apache-flex flex3 adobe


    【解决方案1】:

    zdmytriv's answer 中链接的 Aral Balkan 的文章值得阅读,并提倡为用户提供更好的整体验证交互。

    如果你只是想“强制”弹出错误提示,我会这样做:

        public function showErrorImmediately(target:UIComponent):void
        {
            // we have to callLater this to avoid other fields that send events
            // that reset the timers and prevent the errorTip ever showing up.
            target.callLater(showDeferred, [target]);
        }
    
        private function showDeferred(target:UIComponent):void
        {
            var oldShowDelay:Number = ToolTipManager.showDelay;
            ToolTipManager.showDelay = 0;
            if (target.visible)
            {
                // try popping the resulting error flag via the hack 
                // courtesy Adobe bug tracking system
                target.dispatchEvent(new MouseEvent(MouseEvent.MOUSE_OUT));
                target.dispatchEvent(new MouseEvent(MouseEvent.MOUSE_OVER));
            }
            ToolTipManager.showDelay = oldShowDelay;
        }
    
        public function clearErrorImmediately(target:UIComponent):void
        {
            target.callLater(clearDeferred, [target]);
        }
    
        private function clearDeferred(target:UIComponent):void
        {
            var oldDelay:Number = ToolTipManager.hideDelay;
            ToolTipManager.hideDelay = 0;
            if (target.visible)
            {
                // clear the errorTip
                try
                {
                    target.dispatchEvent(new MouseEvent(MouseEvent.MOUSE_OVER));
                    target.dispatchEvent(new MouseEvent(MouseEvent.MOUSE_OUT));
                }
                catch (e:Error)
                {
                    // sometimes things aren't initialized fully when we try that trick
                }
            }
            ToolTipManager.hideDelay = oldDelay;
        }
    

    【讨论】:

      【解决方案2】:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-11-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-08-18
        • 2020-03-10
        相关资源
        最近更新 更多