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

发布于 2024-08-11 06:00:08 字数 209 浏览 2 评论 0原文

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

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

When a Validator (i.e. StringValidator, NumberValidator, etc) dispatches an invalid event due to validation failure, the errorString property of the source control (i.e. TextInput) is set to a non-empty string which creates a red border around the control and shows an toolTip (errorTip) ONLY when the mouse hovers over the control.

Question: Can you force immediate display of the toolTip (errorTip) rather than waiting for the user to hover over the control? If so, how?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

抚你发端 2024-08-18 06:00:08

zdmytriv 的答案中链接的 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;
    }

Aral Balkan's article linked in zdmytriv's answer is good reading and advocates a better overall validation interaction for the user.

If you just want to "force" the errorTip to pop up, here's what I do:

    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;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文