9 Replies Latest reply on Jul 21, 2006 8:05 PM by doug777

    DateField

    doug777 Level 1
      I set a DateField with a range of dates and then use the start and end date to preset DateField.text to indicate to the user that the whole range of dates is the default, but they can shorten the range if they wish.

      The last selectable date is the same as the end date in the text box.

      But the first selectable date is one day later than the start date in the text box.

      i.e. the rangeStart date itself is not included in the dates that are selectable.

      Have I done something wrong?

      Doug

        • 1. Re: DateField
          doug777 Level 1
          I can see that this is a bug in Flex.

          In the Flex Component Explorer DateField Component, it says all dates prior to June 1 are unavailable, but in fact June 1 is not available either.

          Do you plan to fix this error?

          Doug
          • 2. Re: DateField
            mac_martine Level 1
            Hi Doug--
            Can you share s code snippet so we can see exactly what you're seeing?
            When I do the most basic test of setting date ranges on a DateField it behaves as expected:

            <mx:DateField x="146" y="232" selectableRange="{{rangeStart : new Date(2006,0,1), rangeEnd : new Date(2006,5,30)}}"/>

            Thanks!
            Mac
            • 3. Re: DateField
              doug777 Level 1
              You can see the error at: http://examples.adobe.com/flex2/inproduct/sdk/explorer/explorer.html

              Select the DateField component. The text says: Disable dates before June 1, 2006., but June 1 is also disabled.

              If you set dateField.rangeStart to say July 1 and then put the same date in dateField.text, the control shows July 1, but July 1 is not selectable, only dates from July 2 are selectable.

              So if the customer chooses a different date, but then decides that after all he wants the date originally shown, he cannot select it.

              This is my code, tsearch is a container and the variables in main are preset before this page is called:

              var dformat:DateFormatter = new DateFormatter();
              dformat.formatString = main.dateformat;//doesn't seem to work with this control
              var rangest:Date = new Date(main.timenow.valueOf() - (7 * main.msperday));
              var rangeen:Date = new Date(main.timenow.valueOf() + (27 * main.msperday));
              var stdatelbl:Label = new Label();
              stdatelbl.text = "From:";
              var stdate:DateField = new DateField();
              stdate.selectableRange = {rangeStart: rangest, rangeEnd: rangeen};
              stdate.selectedDate = rangest;
              stdate.text = dformat.format(rangest);
              tsearch.addChild(stdatelbl);
              tsearch.addChild(stdate);
              var endatelbl:Label = new Label();
              endatelbl.text = "To:";
              var endate:DateField = new DateField();
              endate.selectableRange = {rangeStart: rangest, rangeEnd: rangeen};
              endate.selectedDate = rangeen;
              endate.text = dformat.format(rangeen);
              tsearch.addChild(endatelbl);
              tsearch.addChild(endate);

              Doug
              • 4. Re: DateField
                doug777 Level 1
                Oh sorry, I just noticed the example on your website is not an error. it uses rangeEnd and there is nothing wrong with rangeEnd.

                It's only rangeStart that's one day out.

                Doug
                • 5. Re: DateField
                  doug777 Level 1
                  Perhaps you should just rename it:

                  theDayAfterRangeStart
                  • 6. Re: DateField
                    doug777 Level 1
                    Okay now I've got Flex 2 fully working, I can see that you can't directly set the text in the text box.

                    That explains why the format didn't work, so having changed that to

                    stdate.formatString = "MMM D, YYYY";

                    the control displays 070713 2006 while the first selectable date is the 14th.

                    Doug
                    • 7. Re: DateField
                      doug777 Level 1
                      Sorry, I just realized that you cannot see the error if you just enter a date in my code in place of the variables.

                      The following code does show the error.

                      <?xml version="1.0" encoding="utf-8"?>
                      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns="*" creationComplete = "initApp()">

                      <mx:Script>
                      <![CDATA[
                      import mx.controls.DateField;
                      import mx.controls.Label;
                      import mx.formatters.DateFormatter;

                      public function initApp():void{
                      var msperday:Number = 24 * 60 * 60 * 1000;
                      var timestr:String = "Fri Jul 21 10:41:00 GMT+0800 2006";
                      var timenum:Number = Date.parse(timestr);
                      //timenum = timenum - (timenum%msperday);
                      var timenow:Date = new Date(timenum);
                      var startdate:Date = new Date(timenow.valueOf() - (7 * msperday));
                      var enddate:Date = new Date(timenow.valueOf() + (7 * msperday));
                      var stdatelbl:Label = new Label();
                      stdatelbl.text = "From:";
                      var stdate:DateField = new DateField();
                      stdate.selectableRange = {rangeStart: startdate, rangeEnd: enddate};
                      stdate.selectedDate = startdate;
                      stdate.formatString = "MMM D, YYYY";
                      hb.addChild(stdatelbl);
                      hb.addChild(stdate);
                      var endatelbl:Label = new Label();
                      endatelbl.text = "To:";
                      var endate:DateField = new DateField();
                      endate.selectableRange = {rangeStart: startdate, rangeEnd: enddate};
                      endate.selectedDate = enddate;
                      endate.formatString = "MMM D, YYYY";
                      hb.addChild(endatelbl);
                      hb.addChild(endate);
                      }
                      ]]>
                      </mx:Script>

                      <mx:Panel id="pan" width="450" height="150">
                      <mx:HBox id="hb" />
                      </mx:Panel>

                      </mx:Application>

                      In my application, I must have a reference to the current time. I use a RemoteObject call to get the server time and the data that is returned looks exactly the same as the string at timestr.

                      The problem looks as though it might be caused by the time element of the date returned so I tried removing this with the commented out line, but as you can see, it makes no difference when you remove the comment.

                      Can anyone see what is wrong with what I've done, or can suggest a better way to get the current server time?

                      Doug
                      • 8. Re: DateField
                        inlineblue Level 1
                        To me, this is a bug. The DateField is not expecting dates with a non-zero time portion when setting the range. It sets the range by choosing dates >= startdate, but that won't include the start date if the time portion is not zero. eg:

                        2006-7-14 00:00:01 > 2006-7-14

                        So the first date ends up being 2006-7-15. If you want it to include the start date as well, I suggest constructing a new start date using just the year, month, and day. ie.

                        newStartDate: Date = new Date(startdate.fulYear, startdate.month, startdate.date);

                        The DateField really should be donig this truncation internally.
                        • 9. Re: DateField
                          doug777 Level 1
                          Thanks so much, that has cured that problem, but do you see the error in the date format or not?

                          The following code includes your solution for the mismatched dates, but still shows the format error.

                          <?xml version="1.0" encoding="utf-8"?>
                          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns="*" creationComplete = "initApp()">

                          <mx:Script>
                          <![CDATA[
                          import mx.controls.DateField;
                          import mx.controls.Label;
                          import mx.formatters.DateFormatter;

                          public function initApp():void{
                          var msperday:Number = 24 * 60 * 60 * 1000;
                          var timestr:String = "Fri Jul 21 10:41:00 GMT+0800 2006";
                          var timenum:Number = Date.parse(timestr);
                          var startdate:Date = new Date(timenum - (7 * msperday));
                          var enddate:Date = new Date(timenum + (7 * msperday));
                          startdate = new Date(startdate.fullYear, startdate.month, startdate.date);
                          var stdatelbl:Label = new Label();
                          stdatelbl.text = "From:";
                          var stdate:DateField = new DateField();
                          stdate.selectableRange = {rangeStart: startdate, rangeEnd: enddate};
                          stdate.selectedDate = startdate;
                          stdate.formatString = "MMM D, YYYY";
                          hb.addChild(stdatelbl);
                          hb.addChild(stdate);
                          var endatelbl:Label = new Label();
                          endatelbl.text = "To:";
                          var endate:DateField = new DateField();
                          endate.selectableRange = {rangeStart: startdate, rangeEnd: enddate};
                          endate.selectedDate = enddate;
                          endate.formatString = "MMM D, YYYY";
                          hb.addChild(endatelbl);
                          hb.addChild(endate);
                          }
                          ]]>
                          </mx:Script>

                          <mx:Panel id="pan" width="450" height="150">
                          <mx:HBox id="hb" />
                          </mx:Panel>

                          </mx:Application>

                          Does anyone have any idea why the date format doesn't work?

                          Doug