I'm trying to prevent the click event of a button to fire when a text input 
field has the focus but its value has been changed to an invalid value. I've 
tried to cancel the valueCommit & focusOut events of the text input field but 
that doesn't seem to do the trick. Please find below some code that DOESN'T do 
the trick. Anyone an idea on how to fix this annoying problem?

<?xml version="1.0" encoding="utf-8"?>
<s:Application 
  xmlns:fx="http://ns.adobe.com/mxml/2009";
  xmlns:s="library://ns.adobe.com/flex/spark" 
  xmlns:mx="library://ns.adobe.com/flex/mx"
  minWidth="955" minHeight="600">
        <fx:Script>
                <![CDATA[
                        import mx.controls.Alert;
                        import mx.events.FlexEvent;
                        import mx.managers.FocusManager;

                        protected function 
textinput1_focusOutHandler(event:FocusEvent):void
                        {
                                trace("focusOut");
                        }
                        protected function 
ti_valueCommitHandler(event:FlexEvent):void
                        {
                                // Validation fails - how to prevent a tab 
navigator change or click on a button??
                                event.preventDefault();
                                event.stopPropagation();
                                event.stopImmediatePropagation();
                                trace("valueCommit");
                        }
                        protected function 
btn_clickHandler(event:MouseEvent):void
                        {
                                trace("click");
                        }
                ]]>
        </fx:Script>
        <mx:TabNavigator>
                <s:NavigatorContent
                        label="Tab 1">
                        <s:VGroup>
                                <s:TextInput
                                        id="ti"                                 
                                        
valueCommit="ti_valueCommitHandler(event)"
                                        
focusOut="textinput1_focusOutHandler(event)"/>
                                <s:Button
                                        id="btn"
                                        label="Click me"
                                        click="btn_clickHandler(event)" />
                        </s:VGroup>                     
                </s:NavigatorContent>
                <s:NavigatorContent
                        label="Tab 2">
                        <s:Button
                                label="Click me 2" />
                </s:NavigatorContent>
        </mx:TabNavigator>
</s:Application>


Reply via email to