简体   繁体   中英

Flex 3 DateChooser Control - Date Selection Changes on MouseUp Event

If you have a DateChooser control next to a text control and you left click your mouse to select the text then continue holding down the mouse button and letting the mouse button up while over the datechooser control, the selectedDate value changes to the date you are hovering over. I have users that are having issues with this and it happens unintentionally because of the proximity of the two controls. I cannot find a way to stop this effect. Basically I would want the selectedDate to only change if the user actually clicks the calendar control ie. mouseDown or click. Calling functions in those events do not change this behavior. I need a way to disable the control from changing the date on the mouseUpEvent (I think).

That's an irritating bug because you cannot cancel events on the DateChooser. Here is a possible solution:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600">
    <mx:Script>
        <![CDATA[
            private function preventDateChooserBug(e:MouseEvent):void {
                //set the mouseChildren property to false, not enabled because
                //that could cause an irritating flickering when clicking the 
                //text input box for focus
                dtc.mouseChildren = false;

                //add the event listener to stage so we get the mouse up event even
                //outside of the text input control
                stage.addEventListener(MouseEvent.MOUSE_UP, function(e2:MouseEvent):void {
                    dtc.mouseChildren = true;
                });

            }
        ]]>
    </mx:Script>
    <mx:TextInput x="10" y="10" id="txt" mouseDown="preventDateChooserBug(event)" />
    <mx:DateChooser x="178" y="10" id="dtc" />
</mx:Application>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM