tags:

views:

1387

answers:

4

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?

A: 

Check this Better form validation in Flex

zdmytriv
+2  A: 

Aral Balkan's article linked above 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;
    }
verveguy
A: 

I got this to work for one field. When I tried it with 2 fields the first stops displaying the error tip. Could you tell me what I have to do?

Mike Foregger
A: 

thanks very much

qqq