加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Flex:在验证失败时强制显示控件的errorTip(错误工具提示)

发布时间:2020-12-15 01:44:05 所属栏目:百科 来源:网络整理
导读:当Validator(即StringValidator,NumberValidator等)由于验证失败而调度无效事件时,源控件的errorString属性(即TextInput)将设置为非空字符串,该字符串在控件周围创建一个红色边框并显示toolTip(errorTip)仅当鼠标悬停在控件上时. 问题:您是否可以强制立即显
当Validator(即StringValidator,NumberValidator等)由于验证失败而调度无效事件时,源控件的errorString属性(即TextInput)将设置为非空字符串,该字符串在控件周围创建一个红色边框并显示toolTip(errorTip)仅当鼠标悬停在控件上时.

问题:您是否可以强制立即显示toolTip(errorTip)而不是等待用户将鼠标悬停在控件上?如果是这样,怎么样?

解决方法

Aral Balkan在 zdmytriv’s answer中链接的文章是很好的阅读,并提倡为用户提供更好的整体验证交互.

如果你只想“强制”弹出错误提示,这就是我的工作:

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;
    }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读