Announcement

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

    How to Set a DateItem's Default Time Values?

    I have a DateItem. I initialize the value to a new Date(), with the time values zeroed out (HH:MM:SS == 00:00:00).

    When I click the DateChooser icon, it resets the time value to "12:00:00."

    How can I set the default time values for a given DateItem's chooser? For a given DateItem, I might want the time value to always be 00:00:00, or 23:59:59, etc.

    How to?

    #2
    The time value for a Date produced by a DateItem is meant to be ignored, and for internal housekeeping / timezone reasons, it needs to be noon, not midnight (Brazil switches to DST at midnight, so there are some days when midnight literally does not exist in Brazil).

    If you intend to have the time value be meaningful, use a "datetime" field and DateTimeItem.
    Last edited by Isomorphic; 6 Sep 2011, 08:51.

    Comment


      #3
      Originally posted by Isomorphic
      If you intend to have the time value be meaningful, use a "datetime" field and DateTimeItem.
      Thanks for your suggestion, but could you please give simple example of using it or indicate where I find how to use a datetime field and a DateTime Item with each other?

      Comment


        #4
        Originally posted by Isomorphic
        If you intend to have the time value be meaningful, use a "datetime" field and DateTimeItem.
        I tried that first, but the default input component (single text box with format 'MM/DD/YYYY HH:MM' ) was not a good fit for my Form.

        So just for layout reasons, I went with separate DateItem & TimeItems, then combine the values to build a Timestamp whose value I pass to a DS field of type datetime.

        I'm guessing I could get the DateTimeItem input component to look like anything I want, with setEditorType or some such. Of course what I'd really want is some easy static methods for setting alternate appearance of a DateTimeItem.

        But that does lead me to another question: Is it possible to create a custom editor type composed of multiple FormItems? (E.g., "Bob" = DateItem + TimeItem) Then have other FormItems call that? (e.g., anotherDateTimeItem.setEditorType(Bob) ).

        If yes, any guidance/examples appreciated.

        Comment


          #5
          You could subclass CanvasItem to produce a custom, reusable formItem containing any components in you want. In your case, you'd probably have the "canvas" be set to a DynamicForm containing a DateItem and a TimeItem.
          In order to handle values, you'd need to have changed handlers on your DateItem / TimeItem which would combine values from these items into a single Java Date object with appropriate date and time set, and call "storeValue()". You'd also want a showValueHandler() which would take the value passed in and split it into date and time values, and update the 2 items in the embedded form.

          There's an example in the Showcase that shows the general pattern. In this case a CanvasItem contains an editable ListGrid intended for editing nested data structures, but it demonstrates the basic steps you'll need
          http://www.smartclient.com/smartgwt/...#nested_editor

          Regards
          Isomorphic Software

          Comment


            #6
            this is my implementation for Smartclient:
            http://wiki.smartclient.com/display/...+Item+controls
            Last edited by claudiobosticco; 16 Feb 2012, 02:57.

            Comment


              #7
              I am trying to do the same thing so that the time is not set by default. I have attempted to follow the examples in constructing a canvas item. For some reason I am getting JSExceptions for using null values. Can someone help me identify what I am doing wrong. I would like for the widget work such that the fields are not required. However, if you set a date you must set a time, and vice versa.
              Last edited by jpappalardo; 24 Sep 2014, 09:43.

              Comment


                #8
                Try this:

                Code:
                if(form.getValueAsString("dateOnly")!=null){
                  Date dateDate = (Date)form.getValue("dateOnly");
                  ...
                }

                Comment


                  #9
                  After going through a bit more thoroughly I have the following:



                  The Dynamic form that contains this canvas item is added to a values manager. I keep getting the following error when attempting to open the view that would expose this form.

                  15:19:04.028:MUP1:WARN:CanvasItem:isc_CanvasItem_0:Observer: [CanvasItem ID:isc_CanvasItem_0 name:schedTakeoffTime] is already observing method '$lf' on object '[DynamicForm ID:isc_DynamicForm_1]', ignoring
                  15:19:04.028:MUP1:WARN:CanvasItem:isc_CanvasItem_0:Observer: [CanvasItem ID:isc_CanvasItem_0 name:schedTakeoffTime] is already observing method 'setFocusItem' on object '[DynamicForm ID:isc_DynamicForm_1]', ignoring
                  Last edited by jpappalardo; 24 Sep 2014, 09:43.

                  Comment


                    #10
                    Just a quick update to note that this discussion has moved to another thread: http://forums.smartclient.com/showthread.php?t=21242

                    Comment

                    Working...
                    X