2 Replies Latest reply on Feb 11, 2007 6:26 PM by rui_yangrh

    DateChooser - Not allowing deselection

    tnirenstein
      I am using a DateChooser control which I default to the current date. If the user clicks on a selected date, it unselects that date. Is there a way to force a selection so if the user clicks on the currently selected date, nothing will happen?

      Thanks in advance!
        • 1. Re: DateChooser - Not allowing deselection
          rui_yangrh
          hi, tnirenstein

          I met this problem when I using a DateField component. And I use a variable to store the currentlydate. if the user clicks on the currently selected date again, set the value of currentlydate variable back to the 'selectedDate' property. My english is not well, I hope the following code be useful to you.

          <?xml version="1.0"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">

          <mx:Script>
          <![CDATA[

          import mx.events.CalendarLayoutChangeEvent;

          private var date:Date;
          private function OnChange(evt:CalendarLayoutChangeEvent):void
          {
          if(DateField(evt.currentTarget).text == "")
          {
          df.selectedDate = date;
          }
          else
          {
          date = df.selectedDate;
          }
          }
          ]]>
          </mx:Script>

          <mx:DateField id="df" change="OnChange(event);"/>
          </mx:Application>
          • 2. Re: DateChooser - Not allowing deselection
            rui_yangrh Level 1
            I searched the web and found someone extends DataChooser Class to solve this problem, following is the content of the actionscript file named "NewDateChooser.as":

            package
            {
            import mx.controls.DateChooser;
            import mx.controls.CalendarLayout;
            import mx.core.mx_internal;
            import mx.events.CalendarLayoutChangeEvent;
            import mx.events.DateChooserEvent;

            use namespace mx_internal;

            public class NewDateChooser extends DateChooser
            {
            //Constructor
            public function NewDateChooser()
            {
            super();
            }

            override protected function createChildren():void
            {
            super.createChildren();

            if (mx_internal::dateGrid)
            {
            removeChild(dateGrid);
            mx_internal::dateGrid = new CalendarLayout();
            dateGrid.styleName = this;
            addChild(dateGrid);
            dateGrid.addEventListener(CalendarLayoutChangeEvent.CHANGE,
            changeHandler);
            dateGrid.addEventListener(DateChooserEvent.SCROLL,
            scrollHandler);
            }

            }

            /**
            * @private
            */
            private function scrollHandler(event:DateChooserEvent):void
            {
            dispatchEvent(event);
            }

            /**
            * @private
            */
            private function changeHandler(event:CalendarLayoutChangeEvent):void
            {
            if (selectedDate == event.newDate)
            {
            selectedDate = event.newDate;
            }
            else
            {
            selectedDate = CalendarLayout(event.target).selectedDate;
            }
            var e:CalendarLayoutChangeEvent = new
            CalendarLayoutChangeEvent(CalendarLayoutChangeEvent.CHANGE);
            e.newDate = event.newDate;
            e.triggerEvent = event.triggerEvent;
            dispatchEvent(e);
            }

            }
            }