Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    RelativeDateItem Does Not Fire Changed Event

    SmartClient Version: v8.3p_2013-01-22/LGPL Development Only (built 2013-01-22)

    FF 17.0.2 ESR

    GWT 2.4

    Windows 7

    Executed test in FF 17.0.2 ESR browser itself

    ---

    I discovered this morning that the RelativeDateItem does not fire the onChanged event if the user changes the text in the TextItem by using the keyboard. To reproduce, select a date with the date picker. It will fire the event. Now, begin changing the date by using the keyboard. The onChanged event does not fire.

    On the other hand, it appears that DateRangeItem does fire the onChanged event when you type in 3.0p. So it seems there is some inconsistency.
    Last edited by bwilkins30; 23 Jan 2013, 08:06.

    #2
    Here is some more information...

    If you choose the date picker, then switch back to the drop-down, the event does not fire on the first time you select the drop-down after going from a picker selection to drop-down. Select the drop-down a second time and then it fires the event.

    Comment


      #3
      More information...

      I tried to use a ChangeHandler.

      When you use event.getValue(), it returns null. However, if you call event.getOldValue(), it will return you the Date after you have cast the Object into a Date. It seems that it does not want to return the new value either. The old value is the previous value of course.. not the value I am particularly interested in.

      Comment


        #4
        Here is a test case using DateRangeItem. onChanged is not firing. I even get a warning in the Development Console of "10:42:18.804:IFCS8:WARN:StaticTextItem:isc_StaticTextItem_0[iconPlaceholder]:Attempting to apply event handlers to this item. Unable to get a pointer to this item's focus element" when the drop-down is changed.

        Code:
         @Override
         public void onModuleLoad() 
         {
            RootPanel rootPanel = RootPanel.get("app");
            rootPanel.add(appContainer, 0, 0);
            appContainer.setSize("100%", "100%");
            final DateRangeItem theRangeItem = new DateRangeItem(START_END_DATERANGE_NAME);
        
            theRangeItem.setShowTitle(false);
            theRangeItem.setAllowRelativeDates(true);
            theRangeItem.setRequired(true);         
        
            DateRange theDateRange = new DateRange();
            theDateRange.setRelativeStartDate(new RelativeDate(DEFAULT_REL_DATE));
                   
        theDateRange.setRelativeEndDate(RelativeDate.TODAY);
                 
            theRangeItem.setValue(theDateRange);
        
        theRangeItem.addChangedHandler(new ChangedHandler()
                 {
                    /*
                     * This should fire any time the user changes the Start or End Date.
                     */
                    @Override
                    public void onChanged(ChangedEvent event)
                    {
                       Date startDate = theRangeItem.getFromDate();
                       Date endDate = theRangeItem.getToDate();
        
                       SC.logWarn("Start Date: " + startDate);
                       SC.logWarn("End Date: " + endDate);
                       
                       if (endDate.compareTo(startDate) < 0)
                       {
                          theRangeItem.getForm()
                                      .setFieldErrors(START_END_DATERANGE_NAME, END_DATE_ERROR_MSG, true);
                       }
                       else
                       {
                          // Clear any errors on the field and save the changes to the model
                          theRangeItem.getForm()
                                        .clearFieldErrors(START_END_DATERANGE_NAME, true);
                          
                       }
                    }
                 });
            final DynamicForm form = new DynamicForm();
            form.setWidth(250);
            form.setFields(theRangeItem);
            rootPanel.add(form);
        
        }
        Last edited by bwilkins30; 23 Jan 2013, 08:25.

        Comment


          #5
          Get rid of rootPanel.add() and use draw() instead (see QuickStart Guide - you should always do this).

          Let us know if this doesn't fix the issue.

          Comment


            #6
            Originally posted by Isomorphic View Post
            Get rid of rootPanel.add() and use draw() instead (see QuickStart Guide - you should always do this).

            Let us know if this doesn't fix the issue.
            Ok, this is what I did.

            Went back to 3.0p. onChanged event does not fire when you change the date using the picker. It also does not fire when you change it manually in the TextBox using the keyboard. It only changes when you use the drop down. This is consistent with 3.1p. I thought 3.0p did not have this problem as I was using it until yesterday but I did several side-by-side comparisons and it seems both versions have the same issues.

            And changing it to draw had no effect on the behavior.

            Comment


              #7
              I am taking a wild guess here, but I wonder if it is related to this issue and the DateRangeItem is too strict?

              http://forums.smartclient.com/showthread.php?t=14203

              Comment


                #8
                Ah, going back to your first post, it's expected that change would not fire during text entry. If the user has changed the text and then focus leaves the field, change will fire.

                It would not be good for change to fire on every keystroke because the user has not necessarily completed a meaningful change - the user may have just entered one character, not yet a valid date.

                Comment


                  #9
                  Gotcha. At least in my use case, it would be useful to perhaps have an indication that the field was changed. Meaning, it would be nice if the field had a programmable delay until it fired the event to wait for the user to finish typing a valid date. That way you can validate the field on the fly. I completely understand what you are saying and it makes sense.
                  But you would have to have the user click out of the field or completely leave it in order to fire say an onBlur or an onEditorExit.

                  On the post about DateItem that I linked to previously, you stated:

                  not firing change until the user is done with input is an intentional behavior for DateItem.
                  Can the same be done for the TextItem that accompanies the DateRangeItem or RelativeDateItem? If this is how DateItem works, can we make it work the same?

                  Also, I am not sure if you saw one of my many posts (Sorry for the confusion in advance!), but if you do use the picker to change the date, it does not fire the onChanged event. It will only fire it one time if you had selected a preset option and then used the picker. However, if you use the picker a 2nd, 3rd, maybe 4th time, it does not fire the onChanged event. That should fire the event, I would think, because you are not manually editing it and prone to a mistake. It is done programatically.

                  I did try using the ShowValueHandler() because it mentions setting the value programatically from the DynamicForm, but that only fires once when you use the picker and does not fire on subsequent uses of the picker (and the value from the event is wrong).
                  Last edited by bwilkins30; 23 Jan 2013, 10:34.

                  Comment


                    #10
                    Looking at the Showcase sample "Various Form Controls", while it does not override the ChangedHandler, it shows that the text next to the control updates when you type. I have also changed the global date format, which is not done in the Showcase Sample. Again taking a wild guess, but maybe changing the global date format causes the disconnect?

                    It seems this control may have a few issues that need to be worked out.
                    Last edited by bwilkins30; 23 Jan 2013, 12:43.

                    Comment


                      #11
                      Found problem

                      Ok, the source of the problem is setting the date format. Once you don't do that, the control will fire the onChanged event - only if the date is valid! Which is what I wanted.

                      Something happens when you set the global date format to something other than the default. This is how I am setting the date format:

                      Code:
                      private void changeDateFormat()
                         {      
                            DateUtil.setShortDatetimeDisplayFormatter(new DateDisplayFormatter()
                            {
                               public String format(Date date)
                               {
                                  if(date == null)
                                  {
                                     return null;
                                  }
                                  else
                                  {
                                     final DateTimeFormat dateFormatter = DateTimeFormat.getFormat(DATE_FORMAT);
                                     return dateFormatter.format(date);
                                  }
                      
                               }
                            });
                         }

                      Comment


                        #12
                        Did you supply a corresponding parser in DateUtil for your custom date format? If you haven't, that would explain the problem.

                        Comment


                          #13
                          Solved - thanks Isomorphic!

                          Yep - that was it. Posting code for future readers:

                          Code:
                          DateUtil.setShortDatetimeDisplayFormatter(new DateDisplayFormatter()
                                {
                                   public String format(Date date)
                                   {
                                      if(date == null)
                                      {
                                         return null;
                                      }
                                      else
                                      {
                                         final DateTimeFormat dateFormatter = DateTimeFormat.getFormat(DATE_FORMAT);
                                         return dateFormatter.format(date);
                                      }
                          
                                   }
                                });
                          
                                DateUtil.setDateParser(new DateParser()
                                {
                                   public Date parse(String dateString)
                                   {
                                      final DateTimeFormat format = DateTimeFormat.getFormat(DATE_FORMAT);
                                      return format.parse(dateString);
                                   }
                                });

                          Comment

                          Working...
                          X