Jeremy Mitchell
Jeremy Mitchell

Reputation: 329

Flex: force display of control's errorTip (error toolTip) on validation failure

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?

Upvotes: 3

Views: 6251

Answers (2)

verveguy
verveguy

Reputation: 2148

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

Upvotes: 7

tefozi
tefozi

Reputation: 5480

Check this Better form validation in Flex

Upvotes: 0

Related Questions