0 Replies Latest reply on Nov 4, 2007 2:12 AM by Giribabums

    setting selectableRange in DataChooser 

    Giribabums Level 1
      problem in setting selectableRange, 1st selected date is unselected after selecting another date, i dont know the reason
      why it is happening and in this array arrSelectedDates selected dates are adding properly but dateRanges its showing wrong data.
      1st selected value is disappearing and adding last selected date 2 times @ 0th position (index) and @last position.
      Can anyone tell me whats wrong in my code, and i want to to deselect when i click on selectedDate and remove from arrSelectedDates
      and dateRanges, check the code in debug mode.

      main.mxml
      [code]
      <?xml version="1.0"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns:ns2="myComponents.*">
      <ns2:CalendarDemo width="214" height="228">
      </ns2:CalendarDemo>
      </mx:Application>
      [/code]

      CalendarDemo.mxml
      [code]
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml" width="192" height="198">
      <mx:Script>
      <![CDATA[
      import mx.formatters.DateFormatter;
      private var dateRanges:Array = [];
      private var arrSelectedDates:Array = new Array();

      private function SetSelectableRange():void
      {
      var startDate:Date = new Date();
      dcHoliday.selectableRange = {rangeStart:new Date(startDate),
      rangeEnd:new Date((startDate.fullYear+1), startDate.month, startDate.date)};
      }
      private function dcHolidayChange():void
      {
      if(dcHoliday.selectedDate != null)
      {
      var selDate:Date = new Date( dcHoliday.selectedDate );
      var sDateObject:Object = { rangeStart:selDate, rangeEnd:selDate };
      dateRanges.push( sDateObject );
      dcHoliday.selectedRanges = dateRanges;
      var tempDate:String = myDateFormat( dcHoliday.selectedDate,"YYYY-MM-DD" );
      if(arrSelectedDates.length == 0)
      {
      arrSelectedDates.push(tempDate);
      }
      else
      {
      var cnt:int = 0;
      for(var i:int = 0; i < arrSelectedDates.length; i++)
      {
      if( arrSelectedDates == tempDate)
      {
      cnt = cnt + 1;
      }
      }
      if(cnt <= 0)
      {
      arrSelectedDates.push(tempDate);
      }
      }
      }
      }
      private function myDateFormat(date:Date,strDateFormat:String):String
      {
      var fDate:String;
      var mydf:DateFormatter = new DateFormatter();
      mydf.formatString = strDateFormat;
      return fDate = mydf.format(date);
      }
      ]]>
      </mx:Script>
      <mx:DateChooser id="dcHoliday" x="10" y="10" cornerRadius="2" visible="true"
      change="dcHolidayChange();" creationComplete="SetSelectableRange();"/>
      </mx:Canvas>
      [/code]

      Thanks in advance