wiln / flexlib

Automatically exported from code.google.com/p/flexlib
0 stars 0 forks source link

PromptingTextInput calls validator on focusIn #189

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. run the app below, click on the second text input item, and notice the 
tooltip is the error tip.  
2. I have tried it both with and without a prompt string.
3.

What is the expected output? What do you see instead?
On focus in there is a call to commit the text and that ends up calling the 
validator.

What version of the product are you using? On what operating system?
flexlib version .24, Mac 10.5, Windows XP

Please provide any additional information below.
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
xmlns:flexlib="flexlib.controls.*"
creationComplete="creationCompleteHandler()">

    <mx:Script>
        <![CDATA[
            import mx.validators.StringValidator;
            private function creationCompleteHandler() : void
            {
                var validator:StringValidator = new StringValidator();
                validator.source = ti2;
                validator.property = 'text';
                validator.minLength = 5;
                validator.tooShortError = "way too short";
            }

        ]]>
    </mx:Script>
    <flexlib:PromptingTextInput id="ti1" width="200" toolTip="non-error tip" />
    <flexlib:PromptingTextInput id="ti2" width="200" toolTip="non-error tip"/>

</mx:Application>

Original issue reported on code.google.com by nicho...@adobe.com on 22 Jan 2009 at 4:27

GoogleCodeExporter commented 8 years ago
I added the following code to PromptingTextInput:
    private var _dispatchAllowed:Boolean = true;

    override public function dispatchEvent(event:Event) : Boolean
    {
        if ( _dispatchAllowed )
            return super.dispatchEvent( event );
        else
            return false;
    }

and then modified the focusIn call like this:
    protected function handleFocusIn( event:FocusEvent ):void
    {
        _currentlyFocused = true;
        _dispatchAllowed = false;

        // If the text is empty, clear the prompt
        if ( _textEmpty )
        {
            super.htmlText = "";
            // KLUDGE: Have to validate now to avoid a bug where the format 
            // gets "stuck" even though the text gets cleared.
            validateNow();
        }
        _dispatchAllowed = true;
    }

This took care of it.  What are the chances of getting something like this into 
a release?

Original comment by nicho...@adobe.com on 22 Jan 2009 at 4:46

GoogleCodeExporter commented 8 years ago
Indeed, the flex validators can be a big pain.

I have a ValidationManager class in the pipe that could take care of the issue 
(Validates on change instead of 
value commit).

Original comment by olarivain@gmail.com on 29 Mar 2010 at 1:23